diff options
Diffstat (limited to 'cli/tests/unit_node/testdata')
11 files changed, 69 insertions, 0 deletions
diff --git a/cli/tests/unit_node/testdata/binary_stdio.js b/cli/tests/unit_node/testdata/binary_stdio.js new file mode 100644 index 000000000..aa370a933 --- /dev/null +++ b/cli/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/cli/tests/unit_node/testdata/child_process_unref.js b/cli/tests/unit_node/testdata/child_process_unref.js new file mode 100644 index 000000000..cc7815d97 --- /dev/null +++ b/cli/tests/unit_node/testdata/child_process_unref.js @@ -0,0 +1,9 @@ +import cp from "node:child_process"; +import * as path from "node:path"; + +const script = path.join( + path.dirname(path.fromFileUrl(import.meta.url)), + "infinite_loop.js", +); +const childProcess = cp.spawn(Deno.execPath(), ["run", script]); +childProcess.unref(); diff --git a/cli/tests/unit_node/testdata/exec_file_text_error.js b/cli/tests/unit_node/testdata/exec_file_text_error.js new file mode 100644 index 000000000..9697e6044 --- /dev/null +++ b/cli/tests/unit_node/testdata/exec_file_text_error.js @@ -0,0 +1,2 @@ +console.error("yikes!"); +Deno.exit(1); diff --git a/cli/tests/unit_node/testdata/exec_file_text_output.js b/cli/tests/unit_node/testdata/exec_file_text_output.js new file mode 100644 index 000000000..019c0f4bc --- /dev/null +++ b/cli/tests/unit_node/testdata/exec_file_text_output.js @@ -0,0 +1 @@ +console.log("Hello World!"); diff --git a/cli/tests/unit_node/testdata/infinite_loop.js b/cli/tests/unit_node/testdata/infinite_loop.js new file mode 100644 index 000000000..0e6540a7b --- /dev/null +++ b/cli/tests/unit_node/testdata/infinite_loop.js @@ -0,0 +1,3 @@ +while (true) { + await new Promise((resolve) => setTimeout(resolve, 1000)); +} diff --git a/cli/tests/unit_node/testdata/node_modules/foo/index.js b/cli/tests/unit_node/testdata/node_modules/foo/index.js new file mode 100644 index 000000000..24faba789 --- /dev/null +++ b/cli/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/cli/tests/unit_node/testdata/node_modules/foo/package.json b/cli/tests/unit_node/testdata/node_modules/foo/package.json new file mode 100644 index 000000000..bde99de92 --- /dev/null +++ b/cli/tests/unit_node/testdata/node_modules/foo/package.json @@ -0,0 +1,3 @@ +{ + "name": "foo" +} diff --git a/cli/tests/unit_node/testdata/process_exit.ts b/cli/tests/unit_node/testdata/process_exit.ts new file mode 100644 index 000000000..57351c087 --- /dev/null +++ b/cli/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/cli/tests/unit_node/testdata/process_exit2.ts b/cli/tests/unit_node/testdata/process_exit2.ts new file mode 100644 index 000000000..3731f745a --- /dev/null +++ b/cli/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/cli/tests/unit_node/testdata/process_stdin.ts b/cli/tests/unit_node/testdata/process_stdin.ts new file mode 100644 index 000000000..23562b090 --- /dev/null +++ b/cli/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/cli/tests/unit_node/testdata/process_stdin_dummy.txt b/cli/tests/unit_node/testdata/process_stdin_dummy.txt new file mode 100644 index 000000000..a907ec3f4 --- /dev/null +++ b/cli/tests/unit_node/testdata/process_stdin_dummy.txt @@ -0,0 +1,2 @@ +foo +bar
\ No newline at end of file |