From: Dmitry Volyntsev Date: Tue, 22 Sep 2026 03:16:38 +0000 (-0700) Subject: Tests: improve compatibility with Node.js X-Git-Tag: 1.0.2~23 X-Git-Url: https://git.kaiwu.me/%7B@url%7D?a=commitdiff_plain;h=c3789e2a79379621c06d4af300c9296b2378cd4c;p=njs.git Tests: improve compatibility with Node.js 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. --- diff --git a/test/buffer.t.js b/test/buffer.t.js index f110f83e..8111ffa4 100644 --- a/test/buffer.t.js +++ b/test/buffer.t.js @@ -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' }, diff --git a/test/fs/methods.t.mjs b/test/fs/methods.t.mjs index 72e42cb9..7d7d8034 100644 --- a/test/fs/methods.t.mjs +++ b/test/fs/methods.t.mjs @@ -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 => { diff --git a/test/fs/rmdir.t.mjs b/test/fs/rmdir.t.mjs index 480f54b5..19c0220c 100644 --- a/test/fs/rmdir.t.mjs +++ b/test/fs/rmdir.t.mjs @@ -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);