diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-02-10 13:22:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-10 20:22:13 +0000 |
commit | f5e46c9bf2f50d66a953fa133161fc829cecff06 (patch) | |
tree | 8faf2f5831c1c7b11d842cd9908d141082c869a5 /tests/unit_node/testdata | |
parent | d2477f780630a812bfd65e3987b70c0d309385bb (diff) |
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
Diffstat (limited to 'tests/unit_node/testdata')
24 files changed, 223 insertions, 0 deletions
diff --git a/tests/unit_node/testdata/add_global_property.js b/tests/unit_node/testdata/add_global_property.js new file mode 100644 index 000000000..814d17d0d --- /dev/null +++ b/tests/unit_node/testdata/add_global_property.js @@ -0,0 +1 @@ +globalThis.foo = "Hello"; diff --git a/tests/unit_node/testdata/add_global_property_run_main.js b/tests/unit_node/testdata/add_global_property_run_main.js new file mode 100644 index 000000000..c9db1cea6 --- /dev/null +++ b/tests/unit_node/testdata/add_global_property_run_main.js @@ -0,0 +1 @@ +globalThis.calledViaRunMain = true; diff --git a/tests/unit_node/testdata/binary_stdio.js b/tests/unit_node/testdata/binary_stdio.js new file mode 100644 index 000000000..aa370a933 --- /dev/null +++ b/tests/unit_node/testdata/binary_stdio.js @@ -0,0 +1,11 @@ +const buffer = new Uint8Array(10); +const nread = await Deno.stdin.read(buffer); + +if (nread != 10) { + throw new Error("Too little data read"); +} + +const nwritten = await Deno.stdout.write(buffer); +if (nwritten != 10) { + throw new Error("Too little data written"); +} diff --git a/tests/unit_node/testdata/child_process_stdio.js b/tests/unit_node/testdata/child_process_stdio.js new file mode 100644 index 000000000..b13b09562 --- /dev/null +++ b/tests/unit_node/testdata/child_process_stdio.js @@ -0,0 +1,16 @@ +import childProcess from "node:child_process"; +import process from "node:process"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; + +const script = path.join( + path.dirname(fileURLToPath(import.meta.url)), + "node_modules", + "foo", + "index.js", +); + +const child = childProcess.spawn(process.execPath, [script], { + stdio: [process.stdin, process.stdout, process.stderr], +}); +child.on("close", () => console.log("close")); diff --git a/tests/unit_node/testdata/child_process_stdio_012.js b/tests/unit_node/testdata/child_process_stdio_012.js new file mode 100644 index 000000000..e3717f985 --- /dev/null +++ b/tests/unit_node/testdata/child_process_stdio_012.js @@ -0,0 +1,16 @@ +import childProcess from "node:child_process"; +import process from "node:process"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; + +const script = path.join( + path.dirname(fileURLToPath(import.meta.url)), + "node_modules", + "foo", + "index.js", +); + +const child = childProcess.spawn(process.execPath, [script], { + stdio: [0, 1, 2], +}); +child.on("close", () => console.log("close")); diff --git a/tests/unit_node/testdata/child_process_unref.js b/tests/unit_node/testdata/child_process_unref.js new file mode 100644 index 000000000..8201ac44d --- /dev/null +++ b/tests/unit_node/testdata/child_process_unref.js @@ -0,0 +1,10 @@ +import cp from "node:child_process"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; + +const script = path.join( + path.dirname(fileURLToPath(import.meta.url)), + "infinite_loop.js", +); +const childProcess = cp.spawn(Deno.execPath(), ["run", script]); +childProcess.unref(); diff --git a/tests/unit_node/testdata/exec_file_text_error.js b/tests/unit_node/testdata/exec_file_text_error.js new file mode 100644 index 000000000..9697e6044 --- /dev/null +++ b/tests/unit_node/testdata/exec_file_text_error.js @@ -0,0 +1,2 @@ +console.error("yikes!"); +Deno.exit(1); diff --git a/tests/unit_node/testdata/exec_file_text_output.js b/tests/unit_node/testdata/exec_file_text_output.js new file mode 100644 index 000000000..019c0f4bc --- /dev/null +++ b/tests/unit_node/testdata/exec_file_text_output.js @@ -0,0 +1 @@ +console.log("Hello World!"); diff --git a/tests/unit_node/testdata/infinite_loop.js b/tests/unit_node/testdata/infinite_loop.js new file mode 100644 index 000000000..0e6540a7b --- /dev/null +++ b/tests/unit_node/testdata/infinite_loop.js @@ -0,0 +1,3 @@ +while (true) { + await new Promise((resolve) => setTimeout(resolve, 1000)); +} diff --git a/tests/unit_node/testdata/lorem_ipsum.txt b/tests/unit_node/testdata/lorem_ipsum.txt new file mode 100644 index 000000000..08e00ed29 --- /dev/null +++ b/tests/unit_node/testdata/lorem_ipsum.txt @@ -0,0 +1 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\ No newline at end of file diff --git a/tests/unit_node/testdata/node_modules/foo/index.js b/tests/unit_node/testdata/node_modules/foo/index.js new file mode 100644 index 000000000..24faba789 --- /dev/null +++ b/tests/unit_node/testdata/node_modules/foo/index.js @@ -0,0 +1,4 @@ +console.log("foo"); +console.log(typeof require === "function"); +console.log(typeof module === "object"); +console.log(typeof exports === "object"); diff --git a/tests/unit_node/testdata/node_modules/foo/package.json b/tests/unit_node/testdata/node_modules/foo/package.json new file mode 100644 index 000000000..bde99de92 --- /dev/null +++ b/tests/unit_node/testdata/node_modules/foo/package.json @@ -0,0 +1,3 @@ +{ + "name": "foo" +} diff --git a/tests/unit_node/testdata/process_exit.ts b/tests/unit_node/testdata/process_exit.ts new file mode 100644 index 000000000..57351c087 --- /dev/null +++ b/tests/unit_node/testdata/process_exit.ts @@ -0,0 +1,19 @@ +import process from "node:process"; + +//deno-lint-ignore no-undef +process.on("exit", () => { + console.log(1); +}); + +function unexpected() { + console.log(null); +} +//deno-lint-ignore no-undef +process.on("exit", unexpected); +//deno-lint-ignore no-undef +process.removeListener("exit", unexpected); + +//deno-lint-ignore no-undef +process.on("exit", () => { + console.log(2); +}); diff --git a/tests/unit_node/testdata/process_exit2.ts b/tests/unit_node/testdata/process_exit2.ts new file mode 100644 index 000000000..3731f745a --- /dev/null +++ b/tests/unit_node/testdata/process_exit2.ts @@ -0,0 +1,4 @@ +import process from "node:process"; + +process.on("exit", () => console.log("exit")); +process.exit(); diff --git a/tests/unit_node/testdata/process_really_exit.ts b/tests/unit_node/testdata/process_really_exit.ts new file mode 100644 index 000000000..16f30b33d --- /dev/null +++ b/tests/unit_node/testdata/process_really_exit.ts @@ -0,0 +1,10 @@ +import process from "node:process"; + +//deno-lint-ignore no-undef +// @ts-ignore - Node typings don't even have this because it's +// been deprecated for 4 years. But it's used in `signal-exit`, +// which in turn is used in `node-tap`. +process.reallyExit = function () { + console.info("really exited"); +}; +process.exit(); diff --git a/tests/unit_node/testdata/process_stdin.ts b/tests/unit_node/testdata/process_stdin.ts new file mode 100644 index 000000000..23562b090 --- /dev/null +++ b/tests/unit_node/testdata/process_stdin.ts @@ -0,0 +1,11 @@ +import process from "node:process"; + +console.log(process.stdin.readableHighWaterMark); + +process.stdin.setEncoding("utf8"); +process.stdin.on("readable", () => { + console.log(process.stdin.read()); +}); +process.stdin.on("end", () => { + console.log("end"); +}); diff --git a/tests/unit_node/testdata/process_stdin_dummy.txt b/tests/unit_node/testdata/process_stdin_dummy.txt new file mode 100644 index 000000000..a907ec3f4 --- /dev/null +++ b/tests/unit_node/testdata/process_stdin_dummy.txt @@ -0,0 +1,2 @@ +foo +bar
\ No newline at end of file diff --git a/tests/unit_node/testdata/rsa_private.pem b/tests/unit_node/testdata/rsa_private.pem new file mode 100644 index 000000000..cd274ae6d --- /dev/null +++ b/tests/unit_node/testdata/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u/wtJ2SPCKiKDbJB +re0CKPyRfGqzvA3njXwMxXazU4kGs+2Fg+xu/iKbaIjxXrclBLhkxhBtySrwAFhx +xOk6fFcPLSsCgYEAqS/Mdr5CMRGGMH0bKhPUWEtAixUGZhJaunX5wY71Xoc/Gh4c +nO+b7BNJ/+5L8WZog0vr6PgiLhrqBaCYm2wjpyoG2o2wDHm+NAlzN/wp3G2EFhrS +xdOux+S1c0kpRcyoiAO2n29rNDa+jOzwBBcU8ACEPdLOCQl0IEFFJO33tl8CgYBY +DOIqnEsovsucvh3MNzHwkg8i7CdPGHSmUIN0J9/ItpPxYn2VdtccVOM6+3xZ8+uU +M/9iXGZ+TDkFsZk4/VUsaNmfYOQf1oyLA2ZsNcU90bQbeHNCi/H/19qOJFXgNaCE +sd5P3DMl9lptFGIjRVBHjvbfTQBUR5fi+BusMGfrTQKBgQCTtzMEJP2sef883AJr +XuGVPLzwLi9eTBvPzc5r5pfkvh7mDDmWFxHZm5kctvavqgy32uUPsQgMi1Kz67bU +s5dY9MCVrN2elhTLD8LOiAz8836o3AxFefm5cUWGaU/aZWDYR0QtNqFdyHyRaodo +JJfnfK+oK1Eq7+PvpXfVN9BkYw== +-----END PRIVATE KEY----- diff --git a/tests/unit_node/testdata/rsa_private_pkcs1.pem b/tests/unit_node/testdata/rsa_private_pkcs1.pem new file mode 100644 index 000000000..215e5cc51 --- /dev/null +++ b/tests/unit_node/testdata/rsa_private_pkcs1.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEAt9xYiIonscC3vz/A2ceR7KhZZlDu/5bye53nCVTcKnWd2seY +6UAdKersX6njr83Dd5OVe1BW/wJvp5EjWTAGYbFswlNmeD44edEGM939B6Lq+/8i +BkrTi8mGN4YCytivE24YI0D4XZMPfkLSpab2y/Hy4DjQKBq1ThZ0UBnK+9IhX37J +u/ZoGYSlTIGIhzyaiYBh7wrZBoPczIEu6et/kN2VnnbRUtkYTF97ggcv5h+hDpUQ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kw5BbGZOP1VLGjZn2DkH9aMiwNm +bDXFPdG0G3hzQovx/9fajiRV4DWghLHeT9wzJfZabRRiI0VQR472300AVEeX4vgb +rDBn600CgYEAk7czBCT9rHn/PNwCa17hlTy88C4vXkwbz83Oa+aX5L4e5gw5lhcR +2ZuZHLb2r6oMt9rlD7EIDItSs+u21LOXWPTAlazdnpYUyw/CzogM/PN+qNwMRXn5 +uXFFhmlP2mVg2EdELTahXch8kWqHaCSX53yvqCtRKu/j76V31TfQZGM= +-----END RSA PRIVATE KEY----- diff --git a/tests/unit_node/testdata/rsa_public.pem b/tests/unit_node/testdata/rsa_public.pem new file mode 100644 index 000000000..8c30cfa52 --- /dev/null +++ b/tests/unit_node/testdata/rsa_public.pem @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt9xYiIonscC3vz/A2ceR +7KhZZlDu/5bye53nCVTcKnWd2seY6UAdKersX6njr83Dd5OVe1BW/wJvp5EjWTAG +YbFswlNmeD44edEGM939B6Lq+/8iBkrTi8mGN4YCytivE24YI0D4XZMPfkLSpab2 +y/Hy4DjQKBq1ThZ0UBnK+9IhX37Ju/ZoGYSlTIGIhzyaiYBh7wrZBoPczIEu6et/ +kN2VnnbRUtkYTF97ggcv5h+hDpUQjQW0ZgOMcTc8n+RkGpIt0/iM/bTjI3Tz/gsF +di6hHcpZgbopPL630296iByyigQCPJVzdusFrQN5DeC+zT/nGypQkZanLb4ZspSx +9QIDAQAB +-----END PUBLIC KEY----- diff --git a/tests/unit_node/testdata/worker_module/index.js b/tests/unit_node/testdata/worker_module/index.js new file mode 100644 index 000000000..a3e976b65 --- /dev/null +++ b/tests/unit_node/testdata/worker_module/index.js @@ -0,0 +1,3 @@ +import { myFunction } from "./other_file.js"; + +myFunction().then(() => {}); diff --git a/tests/unit_node/testdata/worker_module/other_file.js b/tests/unit_node/testdata/worker_module/other_file.js new file mode 100644 index 000000000..41789dfe8 --- /dev/null +++ b/tests/unit_node/testdata/worker_module/other_file.js @@ -0,0 +1,3 @@ +export async function myFunction() { + await new Promise((resolve) => setTimeout(resolve, 100)); +} diff --git a/tests/unit_node/testdata/worker_module/package.json b/tests/unit_node/testdata/worker_module/package.json new file mode 100644 index 000000000..486d2f82b --- /dev/null +++ b/tests/unit_node/testdata/worker_module/package.json @@ -0,0 +1,4 @@ +{ + "name": "foo", + "type": "module" +} diff --git a/tests/unit_node/testdata/worker_threads.mjs b/tests/unit_node/testdata/worker_threads.mjs new file mode 100644 index 000000000..03dc462f0 --- /dev/null +++ b/tests/unit_node/testdata/worker_threads.mjs @@ -0,0 +1,34 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { + getEnvironmentData, + isMainThread, + parentPort, + threadId, + workerData, +} from "node:worker_threads"; +import { once } from "node:events"; + +async function message(expectedMessage) { + const [message] = await once(parentPort, "message"); + if (message !== expectedMessage) { + console.log(`Expected the message "${expectedMessage}", but got`, message); + // fail test + parentPort.close(); + } +} + +await message("Hello, how are you my thread?"); + +parentPort.postMessage("I'm fine!"); + +await new Promise((resolve) => setTimeout(resolve, 100)); + +parentPort.postMessage({ + isMainThread, + threadId, + workerData: Array.isArray(workerData) && + workerData[workerData.length - 1] instanceof MessagePort + ? workerData.slice(0, -1) + : workerData, + envData: [getEnvironmentData("test"), getEnvironmentData(1)], +}); |