]> git.kaiwu.me - njs.git/commitdiff
Tests: improve compatibility with Node.js
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 22 Sep 2026 03:16:38 +0000 (20:16 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 25 Sep 2026 23:00:29 +0000 (16:00 -0700)
Accept RangeError from Buffer.concat() revalidation.
Remove oversized Buffer.from() cases that make Node.js allocate 4 GiB.
Expect empty Buffer.fill() values to fail.
Use fs.rm() for recursive removal under Node.js.
Check non-enumerable fs.Stats date properties directly.
Use distinct readlink fixtures for concurrently run test cases.

Known failures for js_test --binary=node are limited to module
resolution in import and XML module tests for v25.2.1 on linux.

test/buffer.t.js
test/fs/methods.t.mjs
test/fs/rmdir.t.mjs

index f110f83ec6c9173f8e8fd05b96a09a32a453a386..8111ffa4064ac3b05c2d1aa93dee228b656187e9 100644 (file)
@@ -132,7 +132,7 @@ let concatRevalidate_tsuite = {
             Buffer.concat(list);
 
         } catch (e) {
-            if (e instanceof TypeError) {
+            if (e instanceof TypeError || e instanceof RangeError) {
                 return 'SUCCESS';
             }
 
@@ -340,8 +340,10 @@ let fill_tsuite = {
         { buf: Buffer.from('abc'), value: Buffer.from('def'), expected: 'def' },
         { buf: Buffer.from('abc'), value: Buffer.from('def'), detach_value: true,
           exception: 'TypeError: detached buffer' },
-        { buf: Buffer.from('abc'), value: Buffer.from(''), expected: '\0\0\0' },
-        { buf: Buffer.from('abc'), value_from_buf: [1, 1], expected: '\0\0\0' },
+        { buf: Buffer.from('abc'), value: Buffer.from(''),
+          exception: 'TypeError: value argument must not be empty' },
+        { buf: Buffer.from('abc'), value_from_buf: [1, 1],
+          exception: 'TypeError: value argument must not be empty' },
         { buf: Buffer.from('def'),
           value: Buffer.from(new Uint8Array([0x60, 0x61, 0x62, 0x63]).buffer, 1),
           expected: 'abc' },
@@ -409,8 +411,6 @@ let from_tsuite = {
         { args: [{length:3, 0:0x62, 1:0x75, 2:0x66}], expected: 'buf' },
         { args: [[-1, 1, 255, 22323, -Infinity, Infinity, NaN]], fmt: "hex", expected: 'ff01ff33000000' },
         { args: [{length:5, 0:'A'.charCodeAt(0), 2:'X', 3:NaN, 4:0xfd}], fmt: "hex", expected: '41000000fd' },
-        { args: [{length: 0x100000000}], exception: 'RangeError: invalid index' },
-        { args: [{length: 0x100000001}], exception: 'RangeError: invalid index' },
         { args: [[1, 2, 0.23, '5', 'A']], fmt: "hex", expected: '0102000500' },
         { args: [new Uint8Array([0xff, 0xde, 0xba])], fmt: "hex", expected: 'ffdeba' },
 
index 72e42cb9eaf14a21ec0c628e40b3c8a08a3679f7..7d7d8034c14dbc340c61ad56fc1602d9629f6ce5 100644 (file)
@@ -454,11 +454,11 @@ async function readlink_test(params) {
 }
 
 let readlink_tests = () => [
-    { args: [`${test_dir}/symlink`],
+    { args: ["@symlink"],
       check: (data) => data.endsWith("test/fs/ascii") },
-    { args: [`${test_dir}/symlink`, {encoding:'buffer'}],
+    { args: ["@symlink", {encoding:'buffer'}],
       check: (data) => data instanceof Buffer },
-    { args: [`${test_dir}/symlink`, {encoding:'hex'}],
+    { args: ["@symlink", {encoding:'hex'}],
       check: (data) => data.endsWith("746573742f66732f6173636969") },
 ];
 
@@ -569,10 +569,17 @@ let stat_tests = () => [
 
     { args: ["test/fs/ascii"],
       check: (st) => contains(Object.keys(st),
-                              [ "atime", "atimeMs", "birthtime", "birthtimeMs",
-                                "blksize", "blocks", "ctime", "ctimeMs", "dev",
-                                "gid", "ino", "mode", "mtime", "mtimeMs","nlink",
+                              [ "atimeMs", "birthtimeMs", "blksize", "blocks",
+                                "ctimeMs", "dev", "gid", "ino", "mode", "mtimeMs", "nlink",
                                 "rdev", "size", "uid" ]) },
+    { args: ["test/fs/ascii"],
+      check: (st) => ["atime", "birthtime", "ctime", "mtime"].every(p => {
+          if (!(st[p] instanceof Date)) {
+              throw Error(`${p} is not an instance of Date`);
+          }
+
+          return true;
+      }) },
 
     { args: ["test/fs/ascii"],
       check: (st) => Object.keys(st).every(p => {
index 480f54b532a6587ac10c476a1e86c7b5bfb1c7f8..19c0220cdc585e896c91d1ec46a773dae88c1dbd 100644 (file)
@@ -23,6 +23,10 @@ var setContent = (root, path) => {
 
 var isNode = () => process.argv[0].includes('node');
 
+var rmdirRecursive = (path) => isNode()
+    ? fs.rmSync(path, { recursive: true, force: true })
+    : fs.rmdirSync(path, { recursive: true });
+
 let stages = [];
 
 var testSync = () => new Promise((resolve, reject) => {
@@ -31,7 +35,7 @@ var testSync = () => new Promise((resolve, reject) => {
     } catch (e) {
     }
     try {
-        fs.rmdirSync(root + dname, { recursive: true });
+        rmdirRecursive(root + dname);
     } catch (e) {
     }
 
@@ -66,10 +70,10 @@ var testSync = () => new Promise((resolve, reject) => {
         }
 
         fs.mkdirSync(root + dname, { mode: 0 });
-        fs.rmdirSync(root + dname, { recursive: true });
+        fs.rmdirSync(root + dname);
 
         setContent(root + dname, path);
-        fs.rmdirSync(root + dname, { recursive: true });
+        rmdirRecursive(root + dname);
 
         try {
             fs.accessSync(root + dname);