summaryrefslogtreecommitdiff
path: root/tests/specs/node
diff options
context:
space:
mode:
authorhaturau <135221985+haturatu@users.noreply.github.com>2024-11-20 01:20:47 +0900
committerGitHub <noreply@github.com>2024-11-20 01:20:47 +0900
commit85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch)
treeface0aecaac53e93ce2f23b53c48859bcf1a36ec /tests/specs/node
parent67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff)
parent186b52731c6bb326c4d32905c5e732d082e83465 (diff)
Merge branch 'denoland:main' into main
Diffstat (limited to 'tests/specs/node')
-rw-r--r--tests/specs/node/child_process_extra_pipes/main.out2
-rw-r--r--tests/specs/node/child_process_extra_pipes/main.ts20
-rw-r--r--tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs25
-rw-r--r--tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out2
-rw-r--r--tests/specs/node/next_tick_uncaught_exception/__test__.jsonc4
-rw-r--r--tests/specs/node/next_tick_uncaught_exception/main.out2
-rw-r--r--tests/specs/node/next_tick_uncaught_exception/main.ts13
-rw-r--r--tests/specs/node/require_export_from_parent_with_no_filename/__test__.jsonc13
-rw-r--r--tests/specs/node/require_export_from_parent_with_no_filename/main.cjs16
-rw-r--r--tests/specs/node/require_export_from_parent_with_no_filename/package.json5
10 files changed, 93 insertions, 9 deletions
diff --git a/tests/specs/node/child_process_extra_pipes/main.out b/tests/specs/node/child_process_extra_pipes/main.out
index 694126b92..436afd2f7 100644
--- a/tests/specs/node/child_process_extra_pipes/main.out
+++ b/tests/specs/node/child_process_extra_pipes/main.out
@@ -1,5 +1,5 @@
-data: hello world
[UNORDERED_START]
child closed
+got: hello world
pipe closed
[UNORDERED_END]
diff --git a/tests/specs/node/child_process_extra_pipes/main.ts b/tests/specs/node/child_process_extra_pipes/main.ts
index a3683fe9e..2837cdc53 100644
--- a/tests/specs/node/child_process_extra_pipes/main.ts
+++ b/tests/specs/node/child_process_extra_pipes/main.ts
@@ -1,5 +1,4 @@
import child_process from "node:child_process";
-import { Buffer } from "node:buffer";
import console from "node:console";
const child = child_process.spawn("./test-pipe/target/debug/test-pipe", [], {
@@ -8,19 +7,32 @@ const child = child_process.spawn("./test-pipe/target/debug/test-pipe", [], {
const extra = child.stdio[4];
-const p = Promise.withResolvers();
+if (!extra) {
+ throw new Error("no extra pipe");
+}
+
+const p = Promise.withResolvers<void>();
+
+let got = "";
child.on("close", () => {
console.log("child closed");
- p.resolve();
+ console.log("got:", got);
+ if (got === "hello world") {
+ p.resolve();
+ } else {
+ p.reject(new Error(`wanted "hello world", got "${got}"`));
+ }
});
extra.on("data", (d) => {
- console.log("data:", d.toString().trim());
+ got += d.toString();
});
extra.on("close", () => {
console.log("pipe closed");
});
+extra.write("start");
+
await p.promise;
diff --git a/tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs b/tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs
index 192f82731..acc034830 100644
--- a/tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs
+++ b/tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs
@@ -1,12 +1,31 @@
+use std::fs::File;
use std::io::prelude::*;
use std::os::fd::FromRawFd;
-use std::os::unix::net::UnixStream;
fn main() {
#[cfg(unix)]
{
- let mut stream = unsafe { UnixStream::from_raw_fd(4) };
+ let mut pipe = unsafe { File::from_raw_fd(4) };
- stream.write_all(b"hello world\n").unwrap();
+ let mut read = 0;
+ let mut buf = [0u8; 1024];
+ loop {
+ if read > 4 {
+ assert_eq!(&buf[..5], b"start");
+ break;
+ }
+ match pipe.read(&mut buf) {
+ Ok(n) => {
+ read += n;
+ }
+ Ok(0) => {
+ return;
+ }
+ Err(e) => {
+ eprintln!("GOT ERROR: {e:?}");
+ }
+ }
+ }
+ pipe.write_all(b"hello world").unwrap();
}
}
diff --git a/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out
index 321d995b8..c50f064d7 100644
--- a/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out
+++ b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out
@@ -1,4 +1,4 @@
-Download http://localhost:4260/@denotest/cjs-reexport-same-specifier-in-sub-folder
+Download http://localhost:4260/@denotest%2fcjs-reexport-same-specifier-in-sub-folder
Download http://localhost:4260/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0.tgz
[Module: null prototype] {
default: { main: [Getter], sub: [Getter] },
diff --git a/tests/specs/node/next_tick_uncaught_exception/__test__.jsonc b/tests/specs/node/next_tick_uncaught_exception/__test__.jsonc
new file mode 100644
index 000000000..5517e693d
--- /dev/null
+++ b/tests/specs/node/next_tick_uncaught_exception/__test__.jsonc
@@ -0,0 +1,4 @@
+{
+ "args": "run main.ts",
+ "output": "main.out"
+}
diff --git a/tests/specs/node/next_tick_uncaught_exception/main.out b/tests/specs/node/next_tick_uncaught_exception/main.out
new file mode 100644
index 000000000..45b756515
--- /dev/null
+++ b/tests/specs/node/next_tick_uncaught_exception/main.out
@@ -0,0 +1,2 @@
+caught Error: thrown from next tick
+ at file:///[WILDCARD]/specs/node/next_tick_uncaught_exception/main.ts:4:15
diff --git a/tests/specs/node/next_tick_uncaught_exception/main.ts b/tests/specs/node/next_tick_uncaught_exception/main.ts
new file mode 100644
index 000000000..2679d3d54
--- /dev/null
+++ b/tests/specs/node/next_tick_uncaught_exception/main.ts
@@ -0,0 +1,13 @@
+import process from "node:process";
+import { strictEqual } from "node:assert";
+
+const error = new Error("thrown from next tick");
+
+process.on("uncaughtException", (caught) => {
+ strictEqual(caught, error);
+ console.log("caught", caught);
+});
+
+process.nextTick(() => {
+ throw error;
+});
diff --git a/tests/specs/node/require_export_from_parent_with_no_filename/__test__.jsonc b/tests/specs/node/require_export_from_parent_with_no_filename/__test__.jsonc
new file mode 100644
index 000000000..a3de08e46
--- /dev/null
+++ b/tests/specs/node/require_export_from_parent_with_no_filename/__test__.jsonc
@@ -0,0 +1,13 @@
+{
+ "tempDir": true,
+ "steps": [
+ {
+ "args": "install",
+ "output": "[WILDCARD]"
+ },
+ {
+ "args": "run -A main.cjs",
+ "output": "3\n"
+ }
+ ]
+}
diff --git a/tests/specs/node/require_export_from_parent_with_no_filename/main.cjs b/tests/specs/node/require_export_from_parent_with_no_filename/main.cjs
new file mode 100644
index 000000000..3335ae1bf
--- /dev/null
+++ b/tests/specs/node/require_export_from_parent_with_no_filename/main.cjs
@@ -0,0 +1,16 @@
+const path = require("node:path");
+const Module = require("node:module");
+function requireFromString(code, filename) {
+ const paths = Module._nodeModulePaths((0, path.dirname)(filename));
+ const m = new Module(filename, module.parent);
+ m.paths = paths;
+ m._compile(code, filename);
+ return m.exports;
+}
+
+const code = `
+const add = require("@denotest/cjs-multiple-exports/add");
+
+console.log(add(1, 2));
+`;
+requireFromString(code, "fake.js");
diff --git a/tests/specs/node/require_export_from_parent_with_no_filename/package.json b/tests/specs/node/require_export_from_parent_with_no_filename/package.json
new file mode 100644
index 000000000..9cd643895
--- /dev/null
+++ b/tests/specs/node/require_export_from_parent_with_no_filename/package.json
@@ -0,0 +1,5 @@
+{
+ "dependencies": {
+ "@denotest/cjs-multiple-exports": "1.0.0"
+ }
+}