From 5f77aebdfb3ea4d60cda79045d29afb244d6bcb1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 25 Oct 2025 23:05:02 +0200 Subject: [PATCH] test: ensure assertions are reachable in `test/es-module` PR-URL: https://github.com/nodejs/node/pull/60501 Reviewed-By: Chemi Atlow --- test/es-module/test-esm-assert-strict.mjs | 2 + .../test-esm-assertionless-json-import.js | 38 ++-- test/es-module/test-esm-cjs-named-error.mjs | 18 +- test/es-module/test-esm-custom-exports.mjs | 4 +- test/es-module/test-esm-default-type.mjs | 4 +- test/es-module/test-esm-detect-ambiguous.mjs | 196 +++++++++--------- .../test-esm-dynamic-import-attribute.js | 18 +- .../test-esm-dynamic-import-attribute.mjs | 18 +- .../test-esm-experimental-warnings.mjs | 16 +- test/es-module/test-esm-exports.mjs | 40 ++-- .../test-esm-extensionless-esm-and-wasm.mjs | 42 ++-- .../test-esm-import-attributes-1.mjs | 4 +- .../test-esm-import-attributes-2.mjs | 8 +- .../test-esm-import-attributes-3.mjs | 8 +- .../test-esm-import-attributes-errors.js | 28 +-- .../test-esm-import-attributes-errors.mjs | 24 +-- .../test-esm-import-meta-resolve.mjs | 2 +- test/es-module/test-esm-imports.mjs | 26 +-- test/es-module/test-esm-json-cache.mjs | 14 +- test/es-module/test-esm-loader-hooks.mjs | 2 +- test/es-module/test-esm-loader-modulemap.js | 57 ++--- .../test-esm-loader-resolve-type.mjs | 4 +- test/es-module/test-esm-loader-thenable.mjs | 18 +- .../test-esm-loader-with-syntax-error.mjs | 8 +- ...est-esm-module-not-found-commonjs-hint.mjs | 6 +- test/es-module/test-esm-non-js.mjs | 8 +- test/es-module/test-esm-nowarn-exports.mjs | 8 +- test/es-module/test-esm-preserve-symlinks.js | 4 +- .../test-esm-recursive-cjs-dependencies.mjs | 4 +- test/es-module/test-esm-repl.js | 6 +- test/es-module/test-esm-symlink-main.js | 4 +- test/es-module/test-esm-symlink.js | 4 +- test/es-module/test-esm-syntax-error.mjs | 6 +- ...tax-errors-not-recognized-as-tla-error.mjs | 18 +- test/es-module/test-typescript-commonjs.mjs | 78 +++---- test/es-module/test-typescript-eval.mjs | 160 +++++++------- test/es-module/test-typescript-module.mjs | 62 +++--- test/es-module/test-typescript-transform.mjs | 66 +++--- test/es-module/test-typescript.mjs | 192 ++++++++--------- test/es-module/test-wasm-web-api.js | 20 +- test/eslint.config_partial.mjs | 1 + 41 files changed, 626 insertions(+), 620 deletions(-) diff --git a/test/es-module/test-esm-assert-strict.mjs b/test/es-module/test-esm-assert-strict.mjs index f753c218a50e4a..d12c2ec3a99b76 100644 --- a/test/es-module/test-esm-assert-strict.mjs +++ b/test/es-module/test-esm-assert-strict.mjs @@ -1,5 +1,7 @@ import '../common/index.mjs'; +// eslint-disable-next-line node-core/must-call-assert import assert, { strict } from 'assert'; +// eslint-disable-next-line node-core/must-call-assert import assertStrict from 'assert/strict'; assert.strictEqual(strict, assertStrict); diff --git a/test/es-module/test-esm-assertionless-json-import.js b/test/es-module/test-esm-assertionless-json-import.js index bd8acdae995a76..f5dc5ff810576c 100644 --- a/test/es-module/test-esm-assertionless-json-import.js +++ b/test/es-module/test-esm-assertionless-json-import.js @@ -1,7 +1,7 @@ // Flags: --experimental-loader ./test/fixtures/es-module-loaders/assertionless-json-import.mjs 'use strict'; const common = require('../common'); -const { strictEqual } = require('assert'); +const assert = require('assert'); async function test() { { @@ -13,10 +13,10 @@ async function test() { ), ]); - strictEqual(secret0.default.ofLife, 42); - strictEqual(secret1.default.ofLife, 42); - strictEqual(secret0.default, secret1.default); - strictEqual(secret0, secret1); + assert.strictEqual(secret0.default.ofLife, 42); + assert.strictEqual(secret1.default.ofLife, 42); + assert.strictEqual(secret0.default, secret1.default); + assert.strictEqual(secret0, secret1); } { @@ -28,10 +28,10 @@ async function test() { ), ]); - strictEqual(secret0.default.ofLife, 42); - strictEqual(secret1.default.ofLife, 42); - strictEqual(secret0.default, secret1.default); - strictEqual(secret0, secret1); + assert.strictEqual(secret0.default.ofLife, 42); + assert.strictEqual(secret1.default.ofLife, 42); + assert.strictEqual(secret0.default, secret1.default); + assert.strictEqual(secret0, secret1); } { @@ -43,10 +43,10 @@ async function test() { ), ]); - strictEqual(secret0.default.ofLife, 42); - strictEqual(secret1.default.ofLife, 42); - strictEqual(secret0.default, secret1.default); - strictEqual(secret0, secret1); + assert.strictEqual(secret0.default.ofLife, 42); + assert.strictEqual(secret1.default.ofLife, 42); + assert.strictEqual(secret0.default, secret1.default); + assert.strictEqual(secret0, secret1); } { @@ -58,10 +58,10 @@ async function test() { ), ]); - strictEqual(secret0.default.ofLife, 42); - strictEqual(secret1.default.ofLife, 42); - strictEqual(secret0.default, secret1.default); - strictEqual(secret0, secret1); + assert.strictEqual(secret0.default.ofLife, 42); + assert.strictEqual(secret1.default.ofLife, 42); + assert.strictEqual(secret0.default, secret1.default); + assert.strictEqual(secret0, secret1); } { @@ -73,8 +73,8 @@ async function test() { ), ]); - strictEqual(secret0.default.ofLife, 42); - strictEqual(secret1.default.ofLife, 42); + assert.strictEqual(secret0.default.ofLife, 42); + assert.strictEqual(secret1.default.ofLife, 42); } } diff --git a/test/es-module/test-esm-cjs-named-error.mjs b/test/es-module/test-esm-cjs-named-error.mjs index 548f82b591da3b..6ece31ed3adc8a 100644 --- a/test/es-module/test-esm-cjs-named-error.mjs +++ b/test/es-module/test-esm-cjs-named-error.mjs @@ -1,5 +1,5 @@ import '../common/index.mjs'; -import { rejects } from 'assert'; +import assert from 'assert'; const fixtureBase = '../fixtures/es-modules/package-cjs-named-error'; @@ -23,55 +23,55 @@ const expectedPackageHack = const expectedBare = errTemplate('deep-fail', 'comeOn', '{ comeOn }'); -await rejects(async () => { +await assert.rejects(async () => { await import(`${fixtureBase}/single-quote.mjs`); }, { name: 'SyntaxError', message: expectedRelative }, 'should support relative specifiers with single quotes'); -await rejects(async () => { +await assert.rejects(async () => { await import(`${fixtureBase}/double-quote.mjs`); }, { name: 'SyntaxError', message: expectedRelative }, 'should support relative specifiers with double quotes'); -await rejects(async () => { +await assert.rejects(async () => { await import(`${fixtureBase}/renamed-import.mjs`); }, { name: 'SyntaxError', message: expectedRenamed }, 'should correctly format named imports with renames'); -await rejects(async () => { +await assert.rejects(async () => { await import(`${fixtureBase}/multi-line.mjs`); }, { name: 'SyntaxError', message: expectedWithoutExample, }, 'should correctly format named imports across multiple lines'); -await rejects(async () => { +await assert.rejects(async () => { await import(`${fixtureBase}/json-hack.mjs`); }, { name: 'SyntaxError', message: expectedPackageHack }, 'should respect recursive package.json for module type'); -await rejects(async () => { +await assert.rejects(async () => { await import(`${fixtureBase}/bare-import-single.mjs`); }, { name: 'SyntaxError', message: expectedBare }, 'should support bare specifiers with single quotes'); -await rejects(async () => { +await assert.rejects(async () => { await import(`${fixtureBase}/bare-import-double.mjs`); }, { name: 'SyntaxError', message: expectedBare }, 'should support bare specifiers with double quotes'); -await rejects(async () => { +await assert.rejects(async () => { await import(`${fixtureBase}/escaped-single-quote.mjs`); }, /import pkg from '\.\/oh'no\.cjs'/, 'should support relative specifiers with escaped single quote'); diff --git a/test/es-module/test-esm-custom-exports.mjs b/test/es-module/test-esm-custom-exports.mjs index e6023387cf8afc..398416a21d6032 100644 --- a/test/es-module/test-esm-custom-exports.mjs +++ b/test/es-module/test-esm-custom-exports.mjs @@ -1,10 +1,10 @@ // Flags: --conditions=custom-condition -C another import { mustCall } from '../common/index.mjs'; -import { strictEqual } from 'assert'; +import assert from 'assert'; import { requireFixture, importFixture } from '../fixtures/pkgexports.mjs'; [requireFixture, importFixture].forEach((loadFixture) => { loadFixture('pkgexports/condition') .then(mustCall((actual) => { - strictEqual(actual.default, 'from custom condition'); + assert.strictEqual(actual.default, 'from custom condition'); })); }); diff --git a/test/es-module/test-esm-default-type.mjs b/test/es-module/test-esm-default-type.mjs index 4b758df9166986..c00c58f75256c0 100644 --- a/test/es-module/test-esm-default-type.mjs +++ b/test/es-module/test-esm-default-type.mjs @@ -1,7 +1,7 @@ import '../common/index.mjs'; -import { strictEqual } from 'assert'; +import assert from 'assert'; import asdf from '../fixtures/es-modules/package-type-module/nested-default-type/module.js'; -strictEqual(asdf, 'asdf'); +assert.strictEqual(asdf, 'asdf'); diff --git a/test/es-module/test-esm-detect-ambiguous.mjs b/test/es-module/test-esm-detect-ambiguous.mjs index a583da981fed5c..234e27a947a13f 100644 --- a/test/es-module/test-esm-detect-ambiguous.mjs +++ b/test/es-module/test-esm-detect-ambiguous.mjs @@ -2,7 +2,7 @@ import { spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import { spawn } from 'node:child_process'; import { describe, it } from 'node:test'; -import { strictEqual, match } from 'node:assert'; +import assert from 'node:assert'; describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, () => { describe('string input', { concurrency: !process.env.TEST_PARALLEL }, () => { @@ -12,10 +12,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'import { version } from "node:process"; console.log(version);', ]); - strictEqual(stderr, ''); - strictEqual(stdout, `${process.version}\n`); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, `${process.version}\n`); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); // ESM is unsupported for --print via --input-type=module @@ -24,7 +24,7 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, const child = spawn(process.execPath, []); child.stdin.end('console.log(typeof import.meta.resolve)'); - match((await child.stdout.toArray()).toString(), /^function\r?\n$/); + assert.match((await child.stdout.toArray()).toString(), /^function\r?\n$/); }); it('should be overridden by --input-type', async () => { @@ -34,10 +34,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'import.meta.url', ]); - match(stderr, /SyntaxError: Cannot use 'import\.meta' outside a module/); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /SyntaxError: Cannot use 'import\.meta' outside a module/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); it('should not switch to module if code is parsable as script', async () => { @@ -46,10 +46,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'let __filename,__dirname,require,module,exports;this.a', ]); - strictEqual(stderr, ''); - strictEqual(stdout, ''); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('does not trigger detection via source code `eval()`', async () => { @@ -58,10 +58,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'eval("import \'nonexistent\';");', ]); - match(stderr, /SyntaxError: Cannot use import statement outside a module/); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /SyntaxError: Cannot use import statement outside a module/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); }); @@ -98,10 +98,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, entryPath, ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); } }); @@ -139,10 +139,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, entryPath, ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); } @@ -161,10 +161,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, fixtures.path('es-modules/package-without-type/noext-esm'), ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'null\nexecuted\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'null\nexecuted\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); }); @@ -189,10 +189,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, entryPath, ]); - match(stderr, /SyntaxError: Unexpected token 'export'/); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /SyntaxError: Unexpected token 'export'/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); } }); @@ -217,10 +217,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, entryPath, ]); - match(stderr, /ReferenceError: module is not defined in ES module scope/); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /ReferenceError: module is not defined in ES module scope/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); } }); @@ -233,10 +233,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'await Promise.resolve(); console.log("executed");', ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('reports unfinished top-level `await`', async () => { @@ -245,10 +245,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, fixtures.path('es-modules/tla/unresolved.js'), ]); - strictEqual(stderr, ''); - strictEqual(stdout, ''); - strictEqual(code, 13); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 13); + assert.strictEqual(signal, null); }); it('permits top-level `await` above import/export syntax', async () => { @@ -257,10 +257,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'await Promise.resolve(); import "node:os"; console.log("executed");', ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('still throws on `await` in an ordinary sync function', async () => { @@ -269,10 +269,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'function fn() { await Promise.resolve(); } fn();', ]); - match(stderr, /SyntaxError: await is only valid in async function/); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /SyntaxError: await is only valid in async function/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); it('throws on undefined `require` when top-level `await` triggers ESM parsing', async () => { @@ -281,13 +281,13 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'const fs = require("node:fs"); await Promise.resolve();', ]); - match( + assert.match( stderr, /ReferenceError: Cannot determine intended module format because both require\(\) and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, replace require\(\) with import\./ ); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); it('permits declaration of CommonJS module variables', async () => { @@ -296,10 +296,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, fixtures.path('es-modules/package-without-type/commonjs-wrapper-variables.js'), ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'exports require module __filename __dirname\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'exports require module __filename __dirname\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('permits declaration of CommonJS module variables above import/export', async () => { @@ -308,10 +308,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'const module = 3; import "node:os"; console.log("executed");', ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('still throws on double `const` declaration not at the top level', async () => { @@ -320,10 +320,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, 'function fn() { const require = 1; const require = 2; } fn();', ]); - match(stderr, /SyntaxError: Identifier 'require' has already been declared/); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /SyntaxError: Identifier 'require' has already been declared/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); }); @@ -347,10 +347,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, entryPath, ]); - match(stderr, /MODULE_TYPELESS_PACKAGE_JSON/); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.match(stderr, /MODULE_TYPELESS_PACKAGE_JSON/); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); } @@ -359,10 +359,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, fixtures.path('es-modules/loose.js'), ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); @@ -371,11 +371,11 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, fixtures.path('es-modules/package-without-type/detected-as-esm.js'), ]); - match(stderr, /MODULE_TYPELESS_PACKAGE_JSON/); - strictEqual(stderr.match(/MODULE_TYPELESS_PACKAGE_JSON/g).length, 1); - strictEqual(stdout, 'executed\nexecuted\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.match(stderr, /MODULE_TYPELESS_PACKAGE_JSON/); + assert.strictEqual(stderr.match(/MODULE_TYPELESS_PACKAGE_JSON/g).length, 1); + assert.strictEqual(stdout, 'executed\nexecuted\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('can be disabled via --no-experimental-detect-module', async () => { @@ -384,10 +384,10 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, fixtures.path('es-modules/package-without-type/module.js'), ]); - match(stderr, /SyntaxError: Unexpected token 'export'/); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /SyntaxError: Unexpected token 'export'/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); }); }); @@ -406,10 +406,10 @@ describe('Wrapping a `require` of an ES module while using `--abort-on-uncaught- cwd: fixtures.path('es-modules'), }); - strictEqual(stderr, ''); - strictEqual(stdout, ''); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); }); @@ -420,10 +420,10 @@ describe('when working with Worker threads', () => { 'new worker_threads.Worker("let __filename,__dirname,require,module,exports;this.a",{eval:true})', ]); - strictEqual(stderr, ''); - strictEqual(stdout, ''); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); }); @@ -438,12 +438,12 @@ describe('cjs & esm ambiguous syntax case', () => { ] ); - match( + assert.match( stderr, /ReferenceError: Cannot determine intended module format because both require\(\) and top-level await are present\. If the code is intended to be CommonJS, wrap await in an async function\. If the code is intended to be an ES module, replace require\(\) with import\./ ); - strictEqual(code, 1); - strictEqual(signal, null); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); }); diff --git a/test/es-module/test-esm-dynamic-import-attribute.js b/test/es-module/test-esm-dynamic-import-attribute.js index 4558cd27ca4237..bc6186f7433409 100644 --- a/test/es-module/test-esm-dynamic-import-attribute.js +++ b/test/es-module/test-esm-dynamic-import-attribute.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../common'); -const { strictEqual } = require('assert'); +const assert = require('assert'); async function test() { { @@ -9,8 +9,8 @@ async function test() { import('../fixtures/empty.js'), ]); - strictEqual(results[0].status, 'rejected'); - strictEqual(results[1].status, 'fulfilled'); + assert.strictEqual(results[0].status, 'rejected'); + assert.strictEqual(results[1].status, 'fulfilled'); } { @@ -19,8 +19,8 @@ async function test() { import('../fixtures/empty.js', { with: { type: 'json' } }), ]); - strictEqual(results[0].status, 'fulfilled'); - strictEqual(results[1].status, 'rejected'); + assert.strictEqual(results[0].status, 'fulfilled'); + assert.strictEqual(results[1].status, 'rejected'); } { @@ -29,8 +29,8 @@ async function test() { import('../fixtures/empty.json'), ]); - strictEqual(results[0].status, 'fulfilled'); - strictEqual(results[1].status, 'rejected'); + assert.strictEqual(results[0].status, 'fulfilled'); + assert.strictEqual(results[1].status, 'rejected'); } { @@ -39,8 +39,8 @@ async function test() { import('../fixtures/empty.json', { with: { type: 'json' } }), ]); - strictEqual(results[0].status, 'rejected'); - strictEqual(results[1].status, 'fulfilled'); + assert.strictEqual(results[0].status, 'rejected'); + assert.strictEqual(results[1].status, 'fulfilled'); } } diff --git a/test/es-module/test-esm-dynamic-import-attribute.mjs b/test/es-module/test-esm-dynamic-import-attribute.mjs index b3d2cb20c36e34..c4dead192593a7 100644 --- a/test/es-module/test-esm-dynamic-import-attribute.mjs +++ b/test/es-module/test-esm-dynamic-import-attribute.mjs @@ -1,5 +1,5 @@ import '../common/index.mjs'; -import { strictEqual } from 'assert'; +import assert from 'assert'; { const results = await Promise.allSettled([ @@ -7,8 +7,8 @@ import { strictEqual } from 'assert'; import('../fixtures/empty.js'), ]); - strictEqual(results[0].status, 'rejected'); - strictEqual(results[1].status, 'fulfilled'); + assert.strictEqual(results[0].status, 'rejected'); + assert.strictEqual(results[1].status, 'fulfilled'); } { @@ -17,8 +17,8 @@ import { strictEqual } from 'assert'; import('../fixtures/empty.js', { with: { type: 'json' } }), ]); - strictEqual(results[0].status, 'fulfilled'); - strictEqual(results[1].status, 'rejected'); + assert.strictEqual(results[0].status, 'fulfilled'); + assert.strictEqual(results[1].status, 'rejected'); } { @@ -27,8 +27,8 @@ import { strictEqual } from 'assert'; import('../fixtures/empty.json'), ]); - strictEqual(results[0].status, 'fulfilled'); - strictEqual(results[1].status, 'rejected'); + assert.strictEqual(results[0].status, 'fulfilled'); + assert.strictEqual(results[1].status, 'rejected'); } { @@ -37,6 +37,6 @@ import { strictEqual } from 'assert'; import('../fixtures/empty.json', { with: { type: 'json' } }), ]); - strictEqual(results[0].status, 'rejected'); - strictEqual(results[1].status, 'fulfilled'); + assert.strictEqual(results[0].status, 'rejected'); + assert.strictEqual(results[1].status, 'fulfilled'); } diff --git a/test/es-module/test-esm-experimental-warnings.mjs b/test/es-module/test-esm-experimental-warnings.mjs index 902583c6db77fa..904b39258e80d1 100644 --- a/test/es-module/test-esm-experimental-warnings.mjs +++ b/test/es-module/test-esm-experimental-warnings.mjs @@ -1,6 +1,6 @@ import { spawnPromisified } from '../common/index.mjs'; import { fileURL } from '../common/fixtures.mjs'; -import { doesNotMatch, match, strictEqual } from 'node:assert'; +import assert from 'node:assert'; import { execPath } from 'node:process'; import { describe, it } from 'node:test'; @@ -13,13 +13,13 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TE `import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`, ]); - doesNotMatch( + assert.doesNotMatch( stderr, /ExperimentalWarning/, new Error('No experimental warning(s) should be emitted when no experimental feature is enabled') ); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); describe('experimental warnings for enabled experimental feature', () => { @@ -40,10 +40,10 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TE `import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`, ]); - match(stderr, /ExperimentalWarning/); - match(stderr, experiment); - strictEqual(code, 0); - strictEqual(signal, null); + assert.match(stderr, /ExperimentalWarning/); + assert.match(stderr, experiment); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); } }); diff --git a/test/es-module/test-esm-exports.mjs b/test/es-module/test-esm-exports.mjs index 21ed3d383e64e9..bc065898c075a1 100644 --- a/test/es-module/test-esm-exports.mjs +++ b/test/es-module/test-esm-exports.mjs @@ -1,5 +1,5 @@ import { mustCall } from '../common/index.mjs'; -import { ok, deepStrictEqual, strictEqual } from 'assert'; +import assert from 'assert'; import { sep } from 'path'; import { requireFixture, importFixture } from '../fixtures/pkgexports.mjs'; @@ -69,7 +69,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; loadFixture(validSpecifier) .then(mustCall((actual) => { - deepStrictEqual({ ...actual }, expected); + assert.deepStrictEqual({ ...actual }, expected); })); } @@ -128,7 +128,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; for (const [specifier, subpath] of undefinedExports) { loadFixture(specifier).catch(mustCall((err) => { - strictEqual(err.code, 'ERR_PACKAGE_PATH_NOT_EXPORTED'); + assert.strictEqual(err.code, 'ERR_PACKAGE_PATH_NOT_EXPORTED'); assertStartsWith(err.message, 'Package subpath '); assertIncludes(err.message, subpath); })); @@ -136,7 +136,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; for (const [specifier, subpath] of invalidExports) { loadFixture(specifier).catch(mustCall((err) => { - strictEqual(err.code, 'ERR_INVALID_PACKAGE_TARGET'); + assert.strictEqual(err.code, 'ERR_INVALID_PACKAGE_TARGET'); assertStartsWith(err.message, 'Invalid "exports"'); assertIncludes(err.message, subpath); if (!subpath.startsWith('./')) { @@ -147,7 +147,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; for (const [specifier, subpath] of invalidSpecifiers) { loadFixture(specifier).catch(mustCall((err) => { - strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER'); + assert.strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER'); assertStartsWith(err.message, 'Invalid module '); assertIncludes(err.message, 'is not a valid match in pattern'); assertIncludes(err.message, subpath); @@ -158,7 +158,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; // of falling back to main if (isRequire) { loadFixture('pkgexports-main').catch(mustCall((err) => { - strictEqual(err.code, 'ERR_PACKAGE_PATH_NOT_EXPORTED'); + assert.strictEqual(err.code, 'ERR_PACKAGE_PATH_NOT_EXPORTED'); assertStartsWith(err.message, 'No "exports" main '); })); } @@ -175,17 +175,17 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; ]); if (!isRequire) { - const onDirectoryImport = (err) => { - strictEqual(err.code, 'ERR_UNSUPPORTED_DIR_IMPORT'); - assertStartsWith(err.message, 'Directory import'); + const onDirectoryImport = { + code: 'ERR_UNSUPPORTED_DIR_IMPORT', + message: /^Directory import/, }; - loadFixture('pkgexports/subpath/dir1').catch(mustCall(onDirectoryImport)); - loadFixture('pkgexports/subpath/dir2').catch(mustCall(onDirectoryImport)); + assert.rejects(loadFixture('pkgexports/subpath/dir1'), onDirectoryImport).then(mustCall()); + assert.rejects(loadFixture('pkgexports/subpath/dir2'), onDirectoryImport).then(mustCall()); } for (const [specifier, request] of notFoundExports) { loadFixture(specifier).catch(mustCall((err) => { - strictEqual(err.code, (isRequire ? '' : 'ERR_') + 'MODULE_NOT_FOUND'); + assert.strictEqual(err.code, (isRequire ? '' : 'ERR_') + 'MODULE_NOT_FOUND'); assertIncludes(err.message, request); assertStartsWith(err.message, 'Cannot find module'); })); @@ -193,20 +193,20 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; // The use of %2F and %5C escapes in paths fails loading loadFixture('pkgexports/sub/..%2F..%2Fbar.js').catch(mustCall((err) => { - strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER'); + assert.strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER'); })); loadFixture('pkgexports/sub/..%5C..%5Cbar.js').catch(mustCall((err) => { - strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER'); + assert.strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER'); })); // Package export with numeric index properties must throw a validation error loadFixture('pkgexports-numeric').catch(mustCall((err) => { - strictEqual(err.code, 'ERR_INVALID_PACKAGE_CONFIG'); + assert.strictEqual(err.code, 'ERR_INVALID_PACKAGE_CONFIG'); })); // Sugar conditional exports main mixed failure case loadFixture('pkgexports-sugar-fail').catch(mustCall((err) => { - strictEqual(err.code, 'ERR_INVALID_PACKAGE_CONFIG'); + assert.strictEqual(err.code, 'ERR_INVALID_PACKAGE_CONFIG'); assertStartsWith(err.message, 'Invalid package'); assertIncludes(err.message, '"exports" cannot contain some keys starting ' + 'with \'.\' and some not. The exports object must either be an object of ' + @@ -232,17 +232,17 @@ const { requireFromInside, importFromInside } = fromInside; loadFromInside(validSpecifier) .then(mustCall((actual) => { - deepStrictEqual({ ...actual }, expected); + assert.deepStrictEqual({ ...actual }, expected); })); } }); function assertStartsWith(actual, expected) { const start = actual.toString().slice(0, expected.length); - strictEqual(start, expected); + assert.strictEqual(start, expected); } function assertIncludes(actual, expected) { - ok(actual.toString().indexOf(expected) !== -1, - `${JSON.stringify(actual)} includes ${JSON.stringify(expected)}`); + assert.ok(actual.toString().indexOf(expected) !== -1, + `${JSON.stringify(actual)} includes ${JSON.stringify(expected)}`); } diff --git a/test/es-module/test-esm-extensionless-esm-and-wasm.mjs b/test/es-module/test-esm-extensionless-esm-and-wasm.mjs index 41fda57cfa4e30..5252111cc4feaf 100644 --- a/test/es-module/test-esm-extensionless-esm-and-wasm.mjs +++ b/test/es-module/test-esm-extensionless-esm-and-wasm.mjs @@ -2,7 +2,7 @@ import { spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import { describe, it } from 'node:test'; -import { match, strictEqual } from 'node:assert'; +import assert from 'node:assert'; describe('extensionless ES modules within a "type": "module" package scope', { concurrency: !process.env.TEST_PARALLEL, @@ -12,23 +12,23 @@ describe('extensionless ES modules within a "type": "module" package scope', { fixtures.path('es-modules/package-type-module/noext-esm'), ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('should be importable', async () => { const { default: defaultExport } = await import(fixtures.fileURL('es-modules/package-type-module/noext-esm')); - strictEqual(defaultExport, 'module'); + assert.strictEqual(defaultExport, 'module'); }); it('should be importable from a module scope under node_modules', async () => { const { default: defaultExport } = await import(fixtures.fileURL( 'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-esm')); - strictEqual(defaultExport, 'module'); + assert.strictEqual(defaultExport, 'module'); }); }); describe('extensionless Wasm modules within a "type": "module" package scope', { @@ -41,21 +41,21 @@ describe('extensionless Wasm modules within a "type": "module" package scope', { fixtures.path('es-modules/package-type-module/noext-wasm'), ]); - strictEqual(stderr, ''); - strictEqual(stdout, 'executed\n'); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('should be importable', async () => { const { add } = await import(fixtures.fileURL('es-modules/package-type-module/noext-wasm')); - strictEqual(add(1, 2), 3); + assert.strictEqual(add(1, 2), 3); }); it('should be importable from a module scope under node_modules', async () => { const { add } = await import(fixtures.fileURL( 'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-wasm')); - strictEqual(add(1, 2), 3); + assert.strictEqual(add(1, 2), 3); }); }); @@ -65,10 +65,10 @@ describe('extensionless ES modules within no package scope', { concurrency: !pro fixtures.path('es-modules/noext-esm'), ]); - strictEqual(stdout, 'executed\n'); - strictEqual(stderr, ''); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stdout, 'executed\n'); + assert.strictEqual(stderr, ''); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); it('should run on import', async () => { @@ -84,10 +84,10 @@ describe('extensionless Wasm within no package scope', { concurrency: !process.e fixtures.path('es-modules/noext-wasm'), ]); - match(stderr, /SyntaxError/); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /SyntaxError/); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); it('should run on import', async () => { diff --git a/test/es-module/test-esm-import-attributes-1.mjs b/test/es-module/test-esm-import-attributes-1.mjs index c699a27bb51a75..3a08fcc844b2a5 100644 --- a/test/es-module/test-esm-import-attributes-1.mjs +++ b/test/es-module/test-esm-import-attributes-1.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; -import { strictEqual } from 'assert'; +import assert from 'assert'; import secret from '../fixtures/experimental.json' with { type: 'json' }; -strictEqual(secret.ofLife, 42); +assert.strictEqual(secret.ofLife, 42); diff --git a/test/es-module/test-esm-import-attributes-2.mjs b/test/es-module/test-esm-import-attributes-2.mjs index 85d6020019af05..f81deebf8d0e82 100644 --- a/test/es-module/test-esm-import-attributes-2.mjs +++ b/test/es-module/test-esm-import-attributes-2.mjs @@ -1,11 +1,11 @@ import '../common/index.mjs'; -import { strictEqual } from 'assert'; +import assert from 'assert'; import secret0 from '../fixtures/experimental.json' with { type: 'json' }; const secret1 = await import('../fixtures/experimental.json', { with: { type: 'json' }, }); -strictEqual(secret0.ofLife, 42); -strictEqual(secret1.default.ofLife, 42); -strictEqual(secret1.default, secret0); +assert.strictEqual(secret0.ofLife, 42); +assert.strictEqual(secret1.default.ofLife, 42); +assert.strictEqual(secret1.default, secret0); diff --git a/test/es-module/test-esm-import-attributes-3.mjs b/test/es-module/test-esm-import-attributes-3.mjs index 8950ca5c595e12..884d20f491dc92 100644 --- a/test/es-module/test-esm-import-attributes-3.mjs +++ b/test/es-module/test-esm-import-attributes-3.mjs @@ -1,10 +1,10 @@ import '../common/index.mjs'; -import { strictEqual } from 'assert'; +import assert from 'assert'; import secret0 from '../fixtures/experimental.json' with { type: 'json' }; const secret1 = await import('../fixtures/experimental.json', { with: { type: 'json' } }); -strictEqual(secret0.ofLife, 42); -strictEqual(secret1.default.ofLife, 42); -strictEqual(secret1.default, secret0); +assert.strictEqual(secret0.ofLife, 42); +assert.strictEqual(secret1.default.ofLife, 42); +assert.strictEqual(secret1.default, secret0); diff --git a/test/es-module/test-esm-import-attributes-errors.js b/test/es-module/test-esm-import-attributes-errors.js index 9789484be986b3..c8ffd9320ad566 100644 --- a/test/es-module/test-esm-import-attributes-errors.js +++ b/test/es-module/test-esm-import-attributes-errors.js @@ -1,67 +1,67 @@ 'use strict'; const common = require('../common'); -const { rejects } = require('assert'); +const assert = require('assert'); -const jsModuleDataUrl = 'data:text/javascript,export{}'; +const jsModuleDataUrl = 'data:text/javascript,exportassert'; const jsonModuleDataUrl = 'data:application/json,""'; async function test() { - await rejects( + await assert.rejects( import('data:text/css,', { with: { type: 'css' } }), { code: 'ERR_UNKNOWN_MODULE_FORMAT' } ); - await rejects( + await assert.rejects( import('data:text/css,', { with: { unsupportedAttribute: 'value' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); - await rejects( + await assert.rejects( import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}with{type:"json"}`), { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } ); - await rejects( + await assert.rejects( import(jsModuleDataUrl, { with: { type: 'json' } }), { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } ); - await rejects( + await assert.rejects( import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); - await rejects( + await assert.rejects( import(jsModuleDataUrl, { with: { type: 'unsupported' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); - await rejects( + await assert.rejects( import(jsonModuleDataUrl), { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } ); - await rejects( + await assert.rejects( import(jsonModuleDataUrl, { with: {} }), { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } ); - await rejects( + await assert.rejects( import(jsonModuleDataUrl, { with: { foo: 'bar' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); - await rejects( + await assert.rejects( import(jsonModuleDataUrl, { with: { type: 'unsupported' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); - await rejects( + await assert.rejects( import(jsonModuleDataUrl, { assert: { type: 'json' } }), { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } ); - await rejects( + await assert.rejects( import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`), SyntaxError ); diff --git a/test/es-module/test-esm-import-attributes-errors.mjs b/test/es-module/test-esm-import-attributes-errors.mjs index 8095662b104135..1168c109fdc4d0 100644 --- a/test/es-module/test-esm-import-attributes-errors.mjs +++ b/test/es-module/test-esm-import-attributes-errors.mjs @@ -1,62 +1,62 @@ import '../common/index.mjs'; -import { rejects } from 'assert'; +import assert from 'assert'; const jsModuleDataUrl = 'data:text/javascript,export{}'; const jsonModuleDataUrl = 'data:application/json,""'; -await rejects( +await assert.rejects( // This rejects because of the unsupported MIME type, not because of the // unsupported assertion. import('data:text/css,', { with: { type: 'css' } }), { code: 'ERR_UNKNOWN_MODULE_FORMAT' } ); -await rejects( +await assert.rejects( import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}with{type:"json"}`), { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } ); -await rejects( +await assert.rejects( import(jsModuleDataUrl, { with: { type: 'json' } }), { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } ); -await rejects( +await assert.rejects( import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); -await rejects( +await assert.rejects( import(import.meta.url, { with: { type: 'unsupported' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); -await rejects( +await assert.rejects( import(jsonModuleDataUrl), { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } ); -await rejects( +await assert.rejects( import(jsonModuleDataUrl, { with: {} }), { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } ); -await rejects( +await assert.rejects( import(jsonModuleDataUrl, { with: { foo: 'bar' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); -await rejects( +await assert.rejects( import(jsonModuleDataUrl, { with: { type: 'unsupported' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } ); -await rejects( +await assert.rejects( import(jsonModuleDataUrl, { assert: { type: 'json' } }), { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } ); -await rejects( +await assert.rejects( import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`), SyntaxError ); diff --git a/test/es-module/test-esm-import-meta-resolve.mjs b/test/es-module/test-esm-import-meta-resolve.mjs index 504d8968995bf1..695527c3974202 100644 --- a/test/es-module/test-esm-import-meta-resolve.mjs +++ b/test/es-module/test-esm-import-meta-resolve.mjs @@ -26,7 +26,7 @@ assert.strictEqual( assert.strictEqual( import.meta.resolve('../fixtures/', new URL(import.meta.url)), fixtures); -[[], {}, Symbol(), 0, 1, 1n, 1.1, () => {}, true, false].map((arg) => +[[], {}, Symbol(), 0, 1, 1n, 1.1, () => {}, true, false].forEach((arg) => assert.throws(() => import.meta.resolve('../fixtures/', arg), { code: 'ERR_INVALID_ARG_TYPE', }) diff --git a/test/es-module/test-esm-imports.mjs b/test/es-module/test-esm-imports.mjs index d005355e4ab5af..7d2f7a63773514 100644 --- a/test/es-module/test-esm-imports.mjs +++ b/test/es-module/test-esm-imports.mjs @@ -1,5 +1,5 @@ import { mustCall } from '../common/index.mjs'; -import { ok, deepStrictEqual, strictEqual } from 'assert'; +import assert from 'assert'; import importer from '../fixtures/es-modules/pkgimports/importer.js'; import { requireFixture } from '../fixtures/pkgexports.mjs'; @@ -36,7 +36,7 @@ const { requireImport, importImport } = importer; loadFixture(validSpecifier) .then(mustCall((actual) => { - deepStrictEqual({ ...actual }, expected); + assert.deepStrictEqual({ ...actual }, expected); })); } @@ -49,7 +49,7 @@ const { requireImport, importImport } = importer; for (const [specifier, subpath] of invalidImportTargets) { loadFixture(specifier).catch(mustCall((err) => { - strictEqual(err.code, 'ERR_INVALID_PACKAGE_TARGET'); + assert.strictEqual(err.code, 'ERR_INVALID_PACKAGE_TARGET'); assertStartsWith(err.message, 'Invalid "imports"'); assertIncludes(err.message, subpath); assertNotIncludes(err.message, 'targets must start with'); @@ -73,7 +73,7 @@ const { requireImport, importImport } = importer; for (const [specifier, expected] of invalidImportSpecifiers) { loadFixture(specifier).catch(mustCall((err) => { - strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER'); + assert.strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER'); assertStartsWith(err.message, 'Invalid module'); assertIncludes(err.message, expected); })); @@ -98,7 +98,7 @@ const { requireImport, importImport } = importer; for (const specifier of undefinedImports) { loadFixture(specifier).catch(mustCall((err) => { - strictEqual(err.code, 'ERR_PACKAGE_IMPORT_NOT_DEFINED'); + assert.strictEqual(err.code, 'ERR_PACKAGE_IMPORT_NOT_DEFINED'); assertStartsWith(err.message, 'Package import '); assertIncludes(err.message, specifier); })); @@ -115,28 +115,28 @@ const { requireImport, importImport } = importer; ]); for (const specifier of nonDefinedImports) { loadFixture(specifier).catch(mustCall((err) => { - strictEqual(err.code, - isRequire ? 'MODULE_NOT_FOUND' : 'ERR_MODULE_NOT_FOUND'); + assert.strictEqual(err.code, + isRequire ? 'MODULE_NOT_FOUND' : 'ERR_MODULE_NOT_FOUND'); })); } }); // CJS resolver must still support #package packages in node_modules requireFixture('#cjs').then(mustCall((actual) => { - strictEqual(actual.default, 'cjs backcompat'); + assert.strictEqual(actual.default, 'cjs backcompat'); })); function assertStartsWith(actual, expected) { const start = actual.toString().slice(0, expected.length); - strictEqual(start, expected); + assert.strictEqual(start, expected); } function assertIncludes(actual, expected) { - ok(actual.toString().indexOf(expected) !== -1, - `${JSON.stringify(actual)} includes ${JSON.stringify(expected)}`); + assert.ok(actual.toString().indexOf(expected) !== -1, + `${JSON.stringify(actual)} includes ${JSON.stringify(expected)}`); } function assertNotIncludes(actual, expected) { - ok(actual.toString().indexOf(expected) === -1, - `${JSON.stringify(actual)} doesn't include ${JSON.stringify(expected)}`); + assert.ok(actual.toString().indexOf(expected) === -1, + `${JSON.stringify(actual)} doesn't include ${JSON.stringify(expected)}`); } diff --git a/test/es-module/test-esm-json-cache.mjs b/test/es-module/test-esm-json-cache.mjs index f8d24fd394a4a2..9b61137db65531 100644 --- a/test/es-module/test-esm-json-cache.mjs +++ b/test/es-module/test-esm-json-cache.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; -import { strictEqual, deepStrictEqual } from 'assert'; +import assert from 'assert'; import { createRequire } from 'module'; @@ -15,10 +15,10 @@ const modCjs = require('../fixtures/es-modules/json-cache/mod.cjs'); const anotherCjs = require('../fixtures/es-modules/json-cache/another.cjs'); const testCjs = require('../fixtures/es-modules/json-cache/test.json'); -strictEqual(mod.one, 1); -strictEqual(another.one, 'zalgo'); -strictEqual(test.one, 'it comes'); +assert.strictEqual(mod.one, 1); +assert.strictEqual(another.one, 'zalgo'); +assert.strictEqual(test.one, 'it comes'); -deepStrictEqual(mod, modCjs); -deepStrictEqual(another, anotherCjs); -deepStrictEqual(test, testCjs); +assert.deepStrictEqual(mod, modCjs); +assert.deepStrictEqual(another, anotherCjs); +assert.deepStrictEqual(test, testCjs); diff --git a/test/es-module/test-esm-loader-hooks.mjs b/test/es-module/test-esm-loader-hooks.mjs index f2726c8c154300..3ff5954c06ef54 100644 --- a/test/es-module/test-esm-loader-hooks.mjs +++ b/test/es-module/test-esm-loader-hooks.mjs @@ -776,7 +776,7 @@ describe('Loader hooks', { concurrency: !process.env.TEST_PARALLEL }, () => { assert.strictEqual(signal, null); }); - describe('should use hooks', async () => { + it('should use hooks', async () => { const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ '--no-experimental-require-module', '--import', diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index b582f4b2aa903b..c725f093fa3bda 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -3,7 +3,7 @@ require('../common'); -const { strictEqual, throws } = require('assert'); +const assert = require('assert'); const { createModuleLoader } = require('internal/modules/esm/loader'); const { LoadCache, ResolveCache } = require('internal/modules/esm/module_map'); const { ModuleJob } = require('internal/modules/esm/module_job'); @@ -30,21 +30,21 @@ const jsonModuleJob = new ModuleJob(loader, jsonModuleDataUrl, moduleMap.set(jsModuleDataUrl, undefined, jsModuleJob); moduleMap.set(jsonModuleDataUrl, 'json', jsonModuleJob); - strictEqual(moduleMap.get(jsModuleDataUrl), jsModuleJob); - strictEqual(moduleMap.get(jsonModuleDataUrl, 'json'), jsonModuleJob); + assert.strictEqual(moduleMap.get(jsModuleDataUrl), jsModuleJob); + assert.strictEqual(moduleMap.get(jsonModuleDataUrl, 'json'), jsonModuleJob); - strictEqual(moduleMap.has(jsModuleDataUrl), true); - strictEqual(moduleMap.has(jsModuleDataUrl, 'javascript'), true); - strictEqual(moduleMap.has(jsonModuleDataUrl, 'json'), true); + assert.strictEqual(moduleMap.has(jsModuleDataUrl), true); + assert.strictEqual(moduleMap.has(jsModuleDataUrl, 'javascript'), true); + assert.strictEqual(moduleMap.has(jsonModuleDataUrl, 'json'), true); - strictEqual(moduleMap.has('unknown'), false); + assert.strictEqual(moduleMap.has('unknown'), false); // The types must match - strictEqual(moduleMap.has(jsModuleDataUrl, 'json'), false); - strictEqual(moduleMap.has(jsonModuleDataUrl, 'javascript'), false); - strictEqual(moduleMap.has(jsonModuleDataUrl), false); - strictEqual(moduleMap.has(jsModuleDataUrl, 'unknown'), false); - strictEqual(moduleMap.has(jsonModuleDataUrl, 'unknown'), false); + assert.strictEqual(moduleMap.has(jsModuleDataUrl, 'json'), false); + assert.strictEqual(moduleMap.has(jsonModuleDataUrl, 'javascript'), false); + assert.strictEqual(moduleMap.has(jsonModuleDataUrl), false); + assert.strictEqual(moduleMap.has(jsModuleDataUrl, 'unknown'), false); + assert.strictEqual(moduleMap.has(jsonModuleDataUrl, 'unknown'), false); } // LoadCache.get, LoadCache.has and LoadCache.set should only accept string @@ -59,9 +59,9 @@ const jsonModuleJob = new ModuleJob(loader, jsonModuleDataUrl, }; [{}, [], true, 1].forEach((value) => { - throws(() => moduleMap.get(value), errorObj); - throws(() => moduleMap.has(value), errorObj); - throws(() => moduleMap.set(value, undefined, jsModuleJob), errorObj); + assert.throws(() => moduleMap.get(value), errorObj); + assert.throws(() => moduleMap.has(value), errorObj); + assert.throws(() => moduleMap.set(value, undefined, jsModuleJob), errorObj); }); } @@ -77,9 +77,9 @@ const jsonModuleJob = new ModuleJob(loader, jsonModuleDataUrl, }; [{}, [], true, 1].forEach((value) => { - throws(() => moduleMap.get(jsModuleDataUrl, value), errorObj); - throws(() => moduleMap.has(jsModuleDataUrl, value), errorObj); - throws(() => moduleMap.set(jsModuleDataUrl, value, jsModuleJob), errorObj); + assert.throws(() => moduleMap.get(jsModuleDataUrl, value), errorObj); + assert.throws(() => moduleMap.has(jsModuleDataUrl, value), errorObj); + assert.throws(() => moduleMap.set(jsModuleDataUrl, value, jsModuleJob), errorObj); }); } @@ -88,7 +88,7 @@ const jsonModuleJob = new ModuleJob(loader, jsonModuleDataUrl, const moduleMap = new LoadCache(); [{}, [], true, 1].forEach((value) => { - throws(() => moduleMap.set('', undefined, value), { + assert.throws(() => moduleMap.set('', undefined, value), { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', message: /^The "job" argument must be an instance of ModuleJob/ @@ -99,17 +99,20 @@ const jsonModuleJob = new ModuleJob(loader, jsonModuleDataUrl, { const resolveMap = new ResolveCache(); - strictEqual(resolveMap.serializeKey('./file', { __proto__: null }), './file::'); - strictEqual(resolveMap.serializeKey('./file', { __proto__: null, type: 'json' }), './file::"type""json"'); - strictEqual(resolveMap.serializeKey('./file::"type""json"', { __proto__: null }), './file::"type""json"::'); - strictEqual(resolveMap.serializeKey('./file', { __proto__: null, c: 'd', a: 'b' }), './file::"a""b","c""d"'); - strictEqual(resolveMap.serializeKey('./s', { __proto__: null, c: 'd', a: 'b', b: 'c' }), './s::"a""b","b""c","c""d"'); + assert.strictEqual(resolveMap.serializeKey('./file', { __proto__: null }), './file::'); + assert.strictEqual(resolveMap.serializeKey('./file', { __proto__: null, type: 'json' }), './file::"type""json"'); + assert.strictEqual(resolveMap.serializeKey('./file::"type""json"', { __proto__: null }), './file::"type""json"::'); + assert.strictEqual(resolveMap.serializeKey('./file', { __proto__: null, c: 'd', a: 'b' }), './file::"a""b","c""d"'); + assert.strictEqual( + resolveMap.serializeKey('./s', { __proto__: null, c: 'd', a: 'b', b: 'c' }), + './s::"a""b","b""c","c""d"', + ); resolveMap.set('key1', 'parent1', 1); resolveMap.set('key2', 'parent1', 2); resolveMap.set('key2', 'parent2', 3); - strictEqual(resolveMap.get('key1', 'parent1'), 1); - strictEqual(resolveMap.get('key2', 'parent1'), 2); - strictEqual(resolveMap.get('key2', 'parent2'), 3); + assert.strictEqual(resolveMap.get('key1', 'parent1'), 1); + assert.strictEqual(resolveMap.get('key2', 'parent1'), 2); + assert.strictEqual(resolveMap.get('key2', 'parent2'), 3); } diff --git a/test/es-module/test-esm-loader-resolve-type.mjs b/test/es-module/test-esm-loader-resolve-type.mjs index 94f409490227af..7dcc65a10c09cf 100644 --- a/test/es-module/test-esm-loader-resolve-type.mjs +++ b/test/es-module/test-esm-loader-resolve-type.mjs @@ -1,7 +1,7 @@ import { spawnPromisified } from '../common/index.mjs'; import * as tmpdir from '../common/tmpdir.js'; import * as fixtures from '../common/fixtures.mjs'; -import { deepStrictEqual } from 'node:assert'; +import assert from 'node:assert'; import { mkdir, rm, cp } from 'node:fs/promises'; import { execPath } from 'node:process'; @@ -33,7 +33,7 @@ try { { cwd: base }, ); - deepStrictEqual(output, { + assert.deepStrictEqual(output, { code: 0, signal: null, stderr: '', diff --git a/test/es-module/test-esm-loader-thenable.mjs b/test/es-module/test-esm-loader-thenable.mjs index 1f394e8607acc5..8cb3f50650cb2e 100644 --- a/test/es-module/test-esm-loader-thenable.mjs +++ b/test/es-module/test-esm-loader-thenable.mjs @@ -1,6 +1,6 @@ import { spawnPromisified } from '../common/index.mjs'; import { fileURL, path } from '../common/fixtures.mjs'; -import { match, ok, notStrictEqual, strictEqual } from 'assert'; +import assert from 'assert'; import { execPath } from 'node:process'; import { describe, it } from 'node:test'; @@ -13,8 +13,8 @@ describe('ESM: thenable loader hooks', { concurrency: !process.env.TEST_PARALLEL path('es-modules', 'test-esm-ok.mjs'), ]); - strictEqual(code, 0); - ok(!stderr.includes('must not call')); + assert.strictEqual(code, 0); + assert.ok(!stderr.includes('must not call')); }); it('should crash the node process rejection with an error', async () => { @@ -24,9 +24,9 @@ describe('ESM: thenable loader hooks', { concurrency: !process.env.TEST_PARALLEL path('es-modules', 'test-esm-ok.mjs'), ]); - notStrictEqual(code, 0); - match(stderr, /\sError: must crash the process\r?\n/); - ok(!stderr.includes('must not call')); + assert.notStrictEqual(code, 0); + assert.match(stderr, /\sError: must crash the process\r?\n/); + assert.ok(!stderr.includes('must not call')); }); it('should just reject without an error (but NOT crash the node process)', async () => { @@ -36,8 +36,8 @@ describe('ESM: thenable loader hooks', { concurrency: !process.env.TEST_PARALLEL path('es-modules', 'test-esm-ok.mjs'), ]); - notStrictEqual(code, 0); - match(stderr, /\sundefined\r?\n/); - ok(!stderr.includes('must not call')); + assert.notStrictEqual(code, 0); + assert.match(stderr, /\sundefined\r?\n/); + assert.ok(!stderr.includes('must not call')); }); }); diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index a2461677730a63..48071a3dc1e80d 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -1,6 +1,6 @@ import { spawnPromisified } from '../common/index.mjs'; import { fileURL, path } from '../common/fixtures.mjs'; -import { match, ok, notStrictEqual } from 'node:assert'; +import assert from 'node:assert'; import { execPath } from 'node:process'; import { describe, it } from 'node:test'; @@ -13,8 +13,8 @@ describe('ESM: loader with syntax error', { concurrency: !process.env.TEST_PARAL path('print-error-message.js'), ]); - match(stderr, /SyntaxError/); - ok(!stderr.includes('Bad command or file name')); - notStrictEqual(code, 0); + assert.match(stderr, /SyntaxError/); + assert.ok(!stderr.includes('Bad command or file name')); + assert.notStrictEqual(code, 0); }); }); diff --git a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs index 7f2bb38bfc1adf..fcd7ec62bc8c09 100644 --- a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs +++ b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs @@ -1,6 +1,6 @@ import { spawnPromisified } from '../common/index.mjs'; import { fixturesDir, fileURL as fixtureSubDir } from '../common/fixtures.mjs'; -import { match, notStrictEqual } from 'node:assert'; +import assert from 'node:assert'; import { execPath } from 'node:process'; import { describe, it } from 'node:test'; @@ -49,7 +49,7 @@ describe('ESM: module not found hint', { concurrency: !process.env.TEST_PARALLEL input, ], { cwd }); - match(stderr, expected); - notStrictEqual(code, 0); + assert.match(stderr, expected); + assert.notStrictEqual(code, 0); }); }); diff --git a/test/es-module/test-esm-non-js.mjs b/test/es-module/test-esm-non-js.mjs index 9ecb2a64397bda..f341bb082a6431 100644 --- a/test/es-module/test-esm-non-js.mjs +++ b/test/es-module/test-esm-non-js.mjs @@ -1,6 +1,6 @@ import { spawnPromisified } from '../common/index.mjs'; import { fileURL } from '../common/fixtures.mjs'; -import { match, strictEqual } from 'node:assert'; +import assert from 'node:assert'; import { execPath } from 'node:process'; import { describe, it } from 'node:test'; @@ -13,8 +13,8 @@ describe('ESM: non-js extensions fail', { concurrency: !process.env.TEST_PARALLE `import ${JSON.stringify(fileURL('es-modules', 'file.unknown'))}`, ]); - match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); }); }); diff --git a/test/es-module/test-esm-nowarn-exports.mjs b/test/es-module/test-esm-nowarn-exports.mjs index b141cc43db85e5..4ca4b2f344a2f5 100644 --- a/test/es-module/test-esm-nowarn-exports.mjs +++ b/test/es-module/test-esm-nowarn-exports.mjs @@ -1,6 +1,6 @@ import { spawnPromisified } from '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { strictEqual } from 'node:assert'; +import assert from 'node:assert'; import { execPath } from 'node:process'; import { describe, it } from 'node:test'; @@ -12,8 +12,8 @@ describe('ESM: experiemental warning for import.meta.resolve', { concurrency: !p path('es-modules/import-resolve-exports.mjs'), ]); - strictEqual(stderr, ''); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); }); }); diff --git a/test/es-module/test-esm-preserve-symlinks.js b/test/es-module/test-esm-preserve-symlinks.js index a91373b0c05b93..36f64956d55ee8 100644 --- a/test/es-module/test-esm-preserve-symlinks.js +++ b/test/es-module/test-esm-preserve-symlinks.js @@ -33,6 +33,6 @@ try { spawn(process.execPath, ['--preserve-symlinks', entry], - { stdio: 'inherit' }).on('exit', (code) => { + { stdio: 'inherit' }).on('exit', common.mustCall((code) => { assert.strictEqual(code, 0); -}); +})); diff --git a/test/es-module/test-esm-recursive-cjs-dependencies.mjs b/test/es-module/test-esm-recursive-cjs-dependencies.mjs index d75f0fae95df6c..61061a219047f0 100644 --- a/test/es-module/test-esm-recursive-cjs-dependencies.mjs +++ b/test/es-module/test-esm-recursive-cjs-dependencies.mjs @@ -1,7 +1,7 @@ import '../common/index.mjs'; -import { strictEqual } from 'node:assert'; +import assert from 'node:assert'; import '../fixtures/recursive-a.cjs'; -strictEqual(global.counter, 1); +assert.strictEqual(global.counter, 1); delete global.counter; diff --git a/test/es-module/test-esm-repl.js b/test/es-module/test-esm-repl.js index 872d2c1f6ef8f4..6587d19d02dd6f 100644 --- a/test/es-module/test-esm-repl.js +++ b/test/es-module/test-esm-repl.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const { spawn } = require('child_process'); @@ -13,6 +13,6 @@ import('fs').then( ).then(process.exit) `); -child.on('exit', (code) => { +child.on('exit', common.mustCall((code) => { assert.strictEqual(code, 0); -}); +})); diff --git a/test/es-module/test-esm-symlink-main.js b/test/es-module/test-esm-symlink-main.js index 2be495ad7dcfb5..930bfeb9aa401a 100644 --- a/test/es-module/test-esm-symlink-main.js +++ b/test/es-module/test-esm-symlink-main.js @@ -20,6 +20,6 @@ try { spawn(process.execPath, ['--preserve-symlinks', symlinkPath], - { stdio: 'inherit' }).on('exit', (code) => { + { stdio: 'inherit' }).on('exit', common.mustCall((code) => { assert.strictEqual(code, 0); -}); +})); diff --git a/test/es-module/test-esm-symlink.js b/test/es-module/test-esm-symlink.js index 139e6820ed5354..0ed2dac792a1bb 100644 --- a/test/es-module/test-esm-symlink.js +++ b/test/es-module/test-esm-symlink.js @@ -42,6 +42,6 @@ try { } spawn(process.execPath, [entry], - { stdio: 'inherit' }).on('exit', (code) => { + { stdio: 'inherit' }).on('exit', common.mustCall((code) => { assert.strictEqual(code, 0); -}); +})); diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs index 6a15207a544f52..7f697b0105ed18 100644 --- a/test/es-module/test-esm-syntax-error.mjs +++ b/test/es-module/test-esm-syntax-error.mjs @@ -1,6 +1,6 @@ import { spawnPromisified } from '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { match, notStrictEqual } from 'node:assert'; +import assert from 'node:assert'; import { execPath } from 'node:process'; import { describe, it } from 'node:test'; @@ -10,7 +10,7 @@ describe('ESM: importing a module with syntax error(s)', { concurrency: !process const { code, stderr } = await spawnPromisified(execPath, [ path('es-module-loaders', 'syntax-error.mjs'), ]); - match(stderr, /SyntaxError:/); - notStrictEqual(code, 0); + assert.match(stderr, /SyntaxError:/); + assert.notStrictEqual(code, 0); }); }); diff --git a/test/es-module/test-esm-tla-syntax-errors-not-recognized-as-tla-error.mjs b/test/es-module/test-esm-tla-syntax-errors-not-recognized-as-tla-error.mjs index f6d1ca962c94a3..ed6d3e44f8f14b 100644 --- a/test/es-module/test-esm-tla-syntax-errors-not-recognized-as-tla-error.mjs +++ b/test/es-module/test-esm-tla-syntax-errors-not-recognized-as-tla-error.mjs @@ -1,6 +1,6 @@ import { spawnPromisified } from '../common/index.mjs'; import { describe, it } from 'node:test'; -import { strictEqual, match } from 'node:assert'; +import assert from 'node:assert'; describe('unusual top-level await syntax errors', () => { const expressions = [ @@ -41,10 +41,10 @@ describe('unusual top-level await syntax errors', () => { `, ]); - strictEqual(stderr, ''); - strictEqual(stdout, ''); - strictEqual(code, 0); - strictEqual(signal, null); + assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); } } }); @@ -69,10 +69,10 @@ describe('unusual top-level await syntax errors', () => { ${wrapperExpression} `, ]); - match(stderr, error); - strictEqual(stdout, ''); - strictEqual(code, 1); - strictEqual(signal, null); + assert.match(stderr, error); + assert.strictEqual(stdout, ''); + assert.strictEqual(code, 1); + assert.strictEqual(signal, null); } }); }); diff --git a/test/es-module/test-typescript-commonjs.mjs b/test/es-module/test-typescript-commonjs.mjs index 548f440e59b5aa..bcbd275d59554e 100644 --- a/test/es-module/test-typescript-commonjs.mjs +++ b/test/es-module/test-typescript-commonjs.mjs @@ -1,6 +1,6 @@ import { skip, spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; -import assert, { match, strictEqual } from 'node:assert'; +import assert from 'node:assert'; import { test } from 'node:test'; if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); @@ -14,9 +14,9 @@ test('require a .ts file with explicit extension succeeds', async () => { cwd: fixtures.path('typescript/ts'), }); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'Hello, TypeScript!\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'Hello, TypeScript!\n'); + assert.strictEqual(result.code, 0); }); test('eval require a .ts file with implicit extension fails', async () => { @@ -28,9 +28,9 @@ test('eval require a .ts file with implicit extension fails', async () => { cwd: fixtures.path('typescript/ts'), }); - strictEqual(result.stdout, ''); - match(result.stderr, /Error: Cannot find module/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /Error: Cannot find module/); + assert.strictEqual(result.code, 1); }); test('eval require a .cts file with implicit extension fails', async () => { @@ -42,9 +42,9 @@ test('eval require a .cts file with implicit extension fails', async () => { cwd: fixtures.path('typescript/ts'), }); - strictEqual(result.stdout, ''); - match(result.stderr, /Error: Cannot find module/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /Error: Cannot find module/); + assert.strictEqual(result.code, 1); }); test('require a .ts file with implicit extension fails', async () => { @@ -53,9 +53,9 @@ test('require a .ts file with implicit extension fails', async () => { fixtures.path('typescript/cts/test-extensionless-require.ts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /Error: Cannot find module/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /Error: Cannot find module/); + assert.strictEqual(result.code, 1); }); test('expect failure of an .mts file with CommonJS syntax', async () => { @@ -96,9 +96,9 @@ test('execute a .cts file importing a .cts file', async () => { fixtures.path('typescript/cts/test-require-commonjs.cts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a .cts file importing a .ts file export', async () => { @@ -107,9 +107,9 @@ test('execute a .cts file importing a .ts file export', async () => { fixtures.path('typescript/cts/test-require-ts-file.cts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a .cts file importing a .mts file export', async () => { @@ -118,9 +118,9 @@ test('execute a .cts file importing a .mts file export', async () => { fixtures.path('typescript/cts/test-require-mts-module.cts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /Error \[ERR_REQUIRE_ESM\]: require\(\) of ES Module/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /Error \[ERR_REQUIRE_ESM\]: require\(\) of ES Module/); + assert.strictEqual(result.code, 1); }); test('execute a .cts file importing a .mts file export', async () => { @@ -129,8 +129,8 @@ test('execute a .cts file importing a .mts file export', async () => { fixtures.path('typescript/cts/test-require-mts-module.cts'), ]); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('expect failure of a .cts file in node_modules', async () => { @@ -138,9 +138,9 @@ test('expect failure of a .cts file in node_modules', async () => { fixtures.path('typescript/cts/test-cts-node_modules.cts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); + assert.strictEqual(result.code, 1); }); test('expect failure of a .ts file in node_modules', async () => { @@ -148,9 +148,9 @@ test('expect failure of a .ts file in node_modules', async () => { fixtures.path('typescript/cts/test-ts-node_modules.cts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); + assert.strictEqual(result.code, 1); }); test('expect failure of a .cts requiring esm without default type module', async () => { @@ -159,9 +159,9 @@ test('expect failure of a .cts requiring esm without default type module', async fixtures.path('typescript/cts/test-mts-node_modules.cts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_REQUIRE_ESM/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_REQUIRE_ESM/); + assert.strictEqual(result.code, 1); }); test('expect failure of a .cts file requiring esm in node_modules', async () => { @@ -170,9 +170,9 @@ test('expect failure of a .cts file requiring esm in node_modules', async () => fixtures.path('typescript/cts/test-mts-node_modules.cts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); + assert.strictEqual(result.code, 1); }); test('cts -> require mts -> import cts', async () => { @@ -180,7 +180,7 @@ test('cts -> require mts -> import cts', async () => { fixtures.path('typescript/cts/issue-59963/a.cts'), ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'Hello from c.cts\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'Hello from c.cts\n'); + assert.strictEqual(result.code, 0); }); diff --git a/test/es-module/test-typescript-eval.mjs b/test/es-module/test-typescript-eval.mjs index 72ad8dfaaf2f45..24a80e4d210700 100644 --- a/test/es-module/test-typescript-eval.mjs +++ b/test/es-module/test-typescript-eval.mjs @@ -1,5 +1,5 @@ import { skip, spawnPromisified } from '../common/index.mjs'; -import { doesNotMatch, match, strictEqual } from 'node:assert'; +import assert from 'node:assert'; import { test } from 'node:test'; if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); @@ -11,9 +11,9 @@ test('eval TypeScript ESM syntax', async () => { const text: string = 'Hello, TypeScript!' console.log(util.styleText('red', text));`]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('eval TypeScript ESM syntax with input-type module', async () => { @@ -24,9 +24,9 @@ test('eval TypeScript ESM syntax with input-type module', async () => { const text: string = 'Hello, TypeScript!' console.log(util.styleText('red', text));`]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('eval TypeScript CommonJS syntax', async () => { @@ -35,9 +35,9 @@ test('eval TypeScript CommonJS syntax', async () => { `const util = require('node:util'); const text: string = 'Hello, TypeScript!' console.log(util.styleText('red', text));`]); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.stderr, ''); - strictEqual(result.code, 0); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.code, 0); }); test('eval TypeScript CommonJS syntax with input-type commonjs-typescript', async () => { @@ -48,9 +48,9 @@ test('eval TypeScript CommonJS syntax with input-type commonjs-typescript', asyn const text: string = 'Hello, TypeScript!' console.log(util.styleText('red', text));`, '--no-warnings']); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.stderr, ''); - strictEqual(result.code, 0); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.code, 0); }); test('eval TypeScript CommonJS syntax by default', async () => { @@ -61,9 +61,9 @@ test('eval TypeScript CommonJS syntax by default', async () => { console.log(util.styleText('red', text));`, '--no-warnings']); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('TypeScript ESM syntax not specified', async () => { @@ -72,9 +72,9 @@ test('TypeScript ESM syntax not specified', async () => { `import util from 'node:util' const text: string = 'Hello, TypeScript!' console.log(text);`]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('expect fail eval TypeScript CommonJS syntax with input-type module-typescript', async () => { @@ -85,9 +85,9 @@ test('expect fail eval TypeScript CommonJS syntax with input-type module-typescr const text: string = 'Hello, TypeScript!' console.log(util.styleText('red', text));`]); - strictEqual(result.stdout, ''); - match(result.stderr, /require is not defined in ES module scope, you can use import instead/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /require is not defined in ES module scope, you can use import instead/); + assert.strictEqual(result.code, 1); }); test('expect fail eval TypeScript ESM syntax with input-type commonjs-typescript', async () => { @@ -97,19 +97,19 @@ test('expect fail eval TypeScript ESM syntax with input-type commonjs-typescript `import util from 'node:util' const text: string = 'Hello, TypeScript!' console.log(util.styleText('red', text));`]); - strictEqual(result.stdout, ''); - match(result.stderr, /Cannot use import statement outside a module/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /Cannot use import statement outside a module/); + assert.strictEqual(result.code, 1); }); test('check syntax error is thrown when passing unsupported syntax', async () => { const result = await spawnPromisified(process.execPath, [ '--eval', 'enum Foo { A, B, C }']); - strictEqual(result.stdout, ''); - match(result.stderr, /SyntaxError/); - doesNotMatch(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /SyntaxError/); + assert.doesNotMatch(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); test('check syntax error is thrown when passing unsupported syntax with --input-type=module-typescript', async () => { @@ -117,9 +117,9 @@ test('check syntax error is thrown when passing unsupported syntax with --input- '--input-type=module-typescript', '--eval', 'enum Foo { A, B, C }']); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); test('check syntax error is thrown when passing unsupported syntax with --input-type=commonjs-typescript', async () => { @@ -127,9 +127,9 @@ test('check syntax error is thrown when passing unsupported syntax with --input- '--input-type=commonjs-typescript', '--eval', 'enum Foo { A, B, C }']); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); test('should not parse TypeScript with --type-module=commonjs', async () => { @@ -138,10 +138,10 @@ test('should not parse TypeScript with --type-module=commonjs', async () => { '--eval', `enum Foo {}`]); - strictEqual(result.stdout, ''); - match(result.stderr, /SyntaxError/); - doesNotMatch(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /SyntaxError/); + assert.doesNotMatch(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); test('should not parse TypeScript with --type-module=module', async () => { @@ -150,10 +150,10 @@ test('should not parse TypeScript with --type-module=module', async () => { '--eval', `enum Foo {}`]); - strictEqual(result.stdout, ''); - match(result.stderr, /SyntaxError/); - doesNotMatch(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /SyntaxError/); + assert.doesNotMatch(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); test('check warning is emitted when eval TypeScript CommonJS syntax', async () => { @@ -162,18 +162,18 @@ test('check warning is emitted when eval TypeScript CommonJS syntax', async () = `const util = require('node:util'); const text: string = 'Hello, TypeScript!' console.log(util.styleText('red', text));`]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('code is throwing a non Error is rethrown', async () => { const result = await spawnPromisified(process.execPath, [ '--eval', `throw null;`]); - doesNotMatch(result.stderr, /node:internal\/process\/execution/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.doesNotMatch(result.stderr, /node:internal\/process\/execution/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('code is throwing an error with customized accessors', async () => { @@ -181,10 +181,10 @@ test('code is throwing an error with customized accessors', async () => { '--eval', `throw Object.defineProperty(new Error, "stack", { set() {throw this} });`]); - match(result.stderr, /Error/); - match(result.stderr, /at \[eval\]:1:29/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /Error/); + assert.match(result.stderr, /at \[eval\]:1:29/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('typescript code is throwing an error', async () => { @@ -192,9 +192,9 @@ test('typescript code is throwing an error', async () => { '--eval', `const foo: string = 'Hello, TypeScript!'; throw new Error(foo);`]); - match(result.stderr, /Hello, TypeScript!/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /Hello, TypeScript!/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('typescript ESM code is throwing a syntax error at runtime', async () => { @@ -205,9 +205,9 @@ test('typescript ESM code is throwing a syntax error at runtime', async () => { // If evaluated in JavaScript `foo(1)` is evaluated as `foo < Number > (1)` // result in false // If evaluated in TypeScript `foo(1)` is evaluated as `foo(1)` - match(result.stderr, /SyntaxError: false/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /SyntaxError: false/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('typescript CJS code is throwing a syntax error at runtime', async () => { @@ -218,9 +218,9 @@ test('typescript CJS code is throwing a syntax error at runtime', async () => { // If evaluated in JavaScript `foo(1)` is evaluated as `foo < Number > (1)` // result in false // If evaluated in TypeScript `foo(1)` is evaluated as `foo(1)` - match(result.stderr, /SyntaxError: false/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /SyntaxError: false/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('check syntax error is thrown when passing invalid syntax with --input-type=commonjs-typescript', async () => { @@ -228,9 +228,9 @@ test('check syntax error is thrown when passing invalid syntax with --input-type '--input-type=commonjs-typescript', '--eval', 'function foo(){ await Promise.resolve(1); }']); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); test('check syntax error is thrown when passing invalid syntax with --input-type=module-typescript', async () => { @@ -238,9 +238,9 @@ test('check syntax error is thrown when passing invalid syntax with --input-type '--input-type=module-typescript', '--eval', 'function foo(){ await Promise.resolve(1); }']); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); test('should not allow module keyword', async () => { @@ -248,9 +248,9 @@ test('should not allow module keyword', async () => { '--input-type=module-typescript', '--eval', 'module F { export type x = number }']); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); test('should not allow declare module keyword', async () => { @@ -258,9 +258,9 @@ test('should not allow declare module keyword', async () => { '--input-type=module-typescript', '--eval', 'declare module F { export type x = number }']); - strictEqual(result.stdout, ''); - match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.code, 1); }); // TODO (marco-ippolito) Remove the extra padding from the error message @@ -270,13 +270,13 @@ test('the error message should not contain extra padding', async () => { '--input-type=module-typescript', '--eval', 'declare module F { export type x = number }']); - strictEqual(result.stdout, ''); + assert.strictEqual(result.stdout, ''); // Windows uses \r\n as line endings const lines = result.stderr.replace(/\r\n/g, '\n').split('\n'); - strictEqual(lines[0], '[eval]:1'); - strictEqual(lines[1], 'declare module F { export type x = number }'); - strictEqual(lines[2], ' ^^^^^^^^'); - strictEqual(lines[4], 'SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]:' + + assert.strictEqual(lines[0], '[eval]:1'); + assert.strictEqual(lines[1], 'declare module F { export type x = number }'); + assert.strictEqual(lines[2], ' ^^^^^^^^'); + assert.strictEqual(lines[4], 'SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]:' + ' `module` keyword is not supported. Use `namespace` instead.'); - strictEqual(result.code, 1); + assert.strictEqual(result.code, 1); }); diff --git a/test/es-module/test-typescript-module.mjs b/test/es-module/test-typescript-module.mjs index eab2fc620fd18e..010f42d825510b 100644 --- a/test/es-module/test-typescript-module.mjs +++ b/test/es-module/test-typescript-module.mjs @@ -1,6 +1,6 @@ import { skip, spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; -import { match, strictEqual } from 'node:assert'; +import assert from 'node:assert'; import { test } from 'node:test'; if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); @@ -10,9 +10,9 @@ test('expect failure of a .mts file with CommonJS syntax', async () => { fixtures.path('typescript/mts/test-mts-but-commonjs-syntax.mts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /require is not defined in ES module scope, you can use import instead/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /require is not defined in ES module scope, you can use import instead/); + assert.strictEqual(result.code, 1); }); test('execute an .mts file importing an .mts file', async () => { @@ -20,9 +20,9 @@ test('execute an .mts file importing an .mts file', async () => { fixtures.path('typescript/mts/test-import-module.mts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute an .mts file importing a .ts file', async () => { @@ -31,9 +31,9 @@ test('execute an .mts file importing a .ts file', async () => { fixtures.path('typescript/mts/test-import-ts-file.mts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute an .mts file importing a .cts file', async () => { @@ -42,9 +42,9 @@ test('execute an .mts file importing a .cts file', async () => { fixtures.path('typescript/mts/test-import-commonjs.mts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute an .mts file from node_modules', async () => { @@ -52,9 +52,9 @@ test('execute an .mts file from node_modules', async () => { fixtures.path('typescript/mts/test-mts-node_modules.mts'), ]); - match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute a .cts file from node_modules', async () => { @@ -62,9 +62,9 @@ test('execute a .cts file from node_modules', async () => { fixtures.path('typescript/mts/test-cts-node_modules.mts'), ]); - match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute a .ts file from node_modules', async () => { @@ -72,9 +72,9 @@ test('execute a .ts file from node_modules', async () => { fixtures.path('typescript/mts/test-ts-node_modules.mts'), ]); - match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute an empty .ts file', async () => { @@ -83,9 +83,9 @@ test('execute an empty .ts file', async () => { fixtures.path('typescript/ts/test-empty-file.ts'), ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, ''); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 0); }); test('execute .ts file importing a module', async () => { @@ -94,9 +94,9 @@ test('execute .ts file importing a module', async () => { fixtures.path('typescript/ts/test-import-fs.ts'), ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'Hello, TypeScript!\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'Hello, TypeScript!\n'); + assert.strictEqual(result.code, 0); }); test('mts -> import cts -> require mts', async () => { @@ -105,7 +105,7 @@ test('mts -> import cts -> require mts', async () => { fixtures.path('typescript/mts/issue-59963/a.mts'), ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'Hello from c.mts\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'Hello from c.mts\n'); + assert.strictEqual(result.code, 0); }); diff --git a/test/es-module/test-typescript-transform.mjs b/test/es-module/test-typescript-transform.mjs index 1dcad6647b01ac..e8be43bbd4ccd5 100644 --- a/test/es-module/test-typescript-transform.mjs +++ b/test/es-module/test-typescript-transform.mjs @@ -1,6 +1,6 @@ import { skip, spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; -import { match, strictEqual } from 'node:assert'; +import assert from 'node:assert'; import { test } from 'node:test'; if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); @@ -12,9 +12,9 @@ test('execute a TypeScript file with transformation enabled', async () => { fixtures.path('typescript/ts/transformation/test-enum.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('reconstruct error of a TypeScript file with transformation enabled and sourcemaps', async () => { @@ -24,9 +24,9 @@ test('reconstruct error of a TypeScript file with transformation enabled and sou fixtures.path('typescript/ts/transformation/test-enum-stacktrace.ts'), ]); - match(result.stderr, /test-enum-stacktrace\.ts:4:7/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /test-enum-stacktrace\.ts:4:7/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('reconstruct error of a TypeScript file with transformation enabled without sourcemaps', async () => { @@ -36,9 +36,9 @@ test('reconstruct error of a TypeScript file with transformation enabled without '--no-warnings', fixtures.path('typescript/ts/transformation/test-enum-stacktrace.ts'), ]); - match(result.stderr, /test-enum-stacktrace\.ts:5:7/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /test-enum-stacktrace\.ts:5:7/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('should not elide unused imports', async () => { @@ -47,9 +47,9 @@ test('should not elide unused imports', async () => { '--no-warnings', fixtures.path('typescript/ts/transformation/test-unused-import.ts'), ]); - match(result.stderr, /ERR_UNSUPPORTED_DIR_IMPORT/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_UNSUPPORTED_DIR_IMPORT/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute a TypeScript file with namespace', async () => { @@ -59,9 +59,9 @@ test('execute a TypeScript file with namespace', async () => { fixtures.path('typescript/ts/transformation/test-namespace.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); // Decorators are currently ignored by transpilation @@ -73,9 +73,9 @@ test('execute a TypeScript file with decorator', async () => { fixtures.path('typescript/ts/transformation/test-decorator.ts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /Invalid or unexpected token/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /Invalid or unexpected token/); + assert.strictEqual(result.code, 1); }); test('execute a TypeScript file with legacy-module', async () => { @@ -85,10 +85,10 @@ test('execute a TypeScript file with legacy-module', async () => { fixtures.path('typescript/ts/transformation/test-legacy-module.ts'), ]); - match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); - match(result.stderr, /`module` keyword is not supported\. Use `namespace` instead/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/); + assert.match(result.stderr, /`module` keyword is not supported\. Use `namespace` instead/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute a TypeScript file with modern typescript syntax', async () => { @@ -98,9 +98,9 @@ test('execute a TypeScript file with modern typescript syntax', async () => { fixtures.path('typescript/ts/transformation/test-modern-typescript.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a transpiled JavaScript file', async () => { @@ -110,10 +110,10 @@ test('execute a transpiled JavaScript file', async () => { fixtures.path('typescript/ts/transformation/test-transformed-typescript.js'), ]); - match(result.stderr, /Stacktrace at line 28/); - match(result.stderr, /test-failing-arm64\.js:28:7/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /Stacktrace at line 28/); + assert.match(result.stderr, /test-failing-arm64\.js:28:7/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute TypeScript file with import = require', async () => { @@ -123,7 +123,7 @@ test('execute TypeScript file with import = require', async () => { fixtures.path('typescript/cts/test-import-require.cts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); diff --git a/test/es-module/test-typescript.mjs b/test/es-module/test-typescript.mjs index 52d096b0e0b6fe..df25f60defd35b 100644 --- a/test/es-module/test-typescript.mjs +++ b/test/es-module/test-typescript.mjs @@ -1,6 +1,6 @@ import { skip, spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; -import { match, strictEqual } from 'node:assert'; +import assert from 'node:assert'; import { test } from 'node:test'; test('expect process.features.typescript to be false when --no-experimental-strip-types ', async () => { @@ -10,9 +10,9 @@ test('expect process.features.typescript to be false when --no-experimental-stri fixtures.path('typescript/echo-process-features-typescript.cjs'), ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'false\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, 'false\n'); + assert.strictEqual(result.code, 0); }); test('expect process.features.typescript to be \'transform\' when --experimental-transform-types', async () => { @@ -22,9 +22,9 @@ test('expect process.features.typescript to be \'transform\' when --experimental fixtures.path('typescript/echo-process-features-typescript.cjs'), ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, process.config.variables.node_use_amaro ? 'transform\n' : 'false\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, process.config.variables.node_use_amaro ? 'transform\n' : 'false\n'); + assert.strictEqual(result.code, 0); }); @@ -35,9 +35,9 @@ test('execute a TypeScript file', async () => { fixtures.path('typescript/ts/test-typescript.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with imports', async () => { @@ -46,9 +46,9 @@ test('execute a TypeScript file with imports', async () => { fixtures.path('typescript/ts/test-import-foo.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with imports', async () => { @@ -58,9 +58,9 @@ test('execute a TypeScript file with imports', async () => { `require(${JSON.stringify(fixtures.path('typescript/ts/test-import-fs.ts'))})`, ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with node_modules', async () => { @@ -69,9 +69,9 @@ test('execute a TypeScript file with node_modules', async () => { fixtures.path('typescript/ts/test-typescript-node-modules.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('expect error when executing a TypeScript file with imports with no extensions', async () => { @@ -79,9 +79,9 @@ test('expect error when executing a TypeScript file with imports with no extensi fixtures.path('typescript/ts/test-import-no-extension.ts'), ]); - match(result.stderr, /Error \[ERR_MODULE_NOT_FOUND\]:/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /Error \[ERR_MODULE_NOT_FOUND\]:/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('expect error when executing a TypeScript file with enum', async () => { @@ -90,9 +90,9 @@ test('expect error when executing a TypeScript file with enum', async () => { ]); // This error should be thrown during transformation - match(result.stderr, /TypeScript enum is not supported in strip-only mode/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /TypeScript enum is not supported in strip-only mode/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('expect error when executing a TypeScript file with experimental decorators', async () => { @@ -100,9 +100,9 @@ test('expect error when executing a TypeScript file with experimental decorators fixtures.path('typescript/ts/test-experimental-decorators.ts'), ]); // This error should be thrown at runtime - match(result.stderr, /Invalid or unexpected token/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /Invalid or unexpected token/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('expect error when executing a TypeScript file with namespaces', async () => { @@ -110,9 +110,9 @@ test('expect error when executing a TypeScript file with namespaces', async () = fixtures.path('typescript/ts/test-namespaces.ts'), ]); // This error should be thrown during transformation - match(result.stderr, /TypeScript namespace declaration is not supported in strip-only mode/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /TypeScript namespace declaration is not supported in strip-only mode/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute a TypeScript file with type definition', async () => { @@ -121,9 +121,9 @@ test('execute a TypeScript file with type definition', async () => { fixtures.path('typescript/ts/test-import-types.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with type definition but no type keyword', async () => { @@ -131,9 +131,9 @@ test('execute a TypeScript file with type definition but no type keyword', async fixtures.path('typescript/ts/test-import-no-type-keyword.ts'), ]); - match(result.stderr, /does not provide an export named 'MyType'/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /does not provide an export named 'MyType'/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute a TypeScript file with CommonJS syntax', async () => { @@ -141,9 +141,9 @@ test('execute a TypeScript file with CommonJS syntax', async () => { '--no-warnings', fixtures.path('typescript/ts/test-commonjs-parsing.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with ES module syntax', async () => { @@ -152,9 +152,9 @@ test('execute a TypeScript file with ES module syntax', async () => { fixtures.path('typescript/ts/test-module-typescript.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('expect failure of a TypeScript file requiring ES module syntax', async () => { @@ -163,8 +163,8 @@ test('expect failure of a TypeScript file requiring ES module syntax', async () fixtures.path('typescript/ts/test-require-module.ts'), ]); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('expect stack trace of a TypeScript file to be correct', async () => { @@ -172,9 +172,9 @@ test('expect stack trace of a TypeScript file to be correct', async () => { fixtures.path('typescript/ts/test-whitespacing.ts'), ]); - strictEqual(result.stdout, ''); - match(result.stderr, /test-whitespacing\.ts:5:7/); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.match(result.stderr, /test-whitespacing\.ts:5:7/); + assert.strictEqual(result.code, 1); }); test('execute CommonJS TypeScript file from node_modules with require-module', async () => { @@ -182,9 +182,9 @@ test('execute CommonJS TypeScript file from node_modules with require-module', a fixtures.path('typescript/ts/test-import-ts-node-modules.ts'), ]); - match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute a TypeScript file with CommonJS syntax requiring .cts', async () => { @@ -193,9 +193,9 @@ test('execute a TypeScript file with CommonJS syntax requiring .cts', async () = fixtures.path('typescript/ts/test-require-cts.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with CommonJS syntax requiring .mts', async () => { @@ -203,8 +203,8 @@ test('execute a TypeScript file with CommonJS syntax requiring .mts', async () = fixtures.path('typescript/ts/test-require-mts.ts'), ]); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with CommonJS syntax requiring .mts using require-module', async () => { @@ -213,8 +213,8 @@ test('execute a TypeScript file with CommonJS syntax requiring .mts using requir fixtures.path('typescript/ts/test-require-mts.ts'), ]); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with CommonJS syntax requiring .cts using commonjs', async () => { @@ -223,9 +223,9 @@ test('execute a TypeScript file with CommonJS syntax requiring .cts using common fixtures.path('typescript/ts/test-require-cts.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript file with CommonJS syntax requiring .mts with require-module', @@ -235,9 +235,9 @@ test('execute a TypeScript file with CommonJS syntax requiring .mts with require fixtures.path('typescript/ts/test-require-cts.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a JavaScript file importing a cjs TypeScript file', async () => { @@ -245,9 +245,9 @@ test('execute a JavaScript file importing a cjs TypeScript file', async () => { '--no-warnings', fixtures.path('typescript/ts/issue-54457.mjs'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript test mocking module', async () => { @@ -257,14 +257,14 @@ test('execute a TypeScript test mocking module', async () => { '--no-warnings', fixtures.path('typescript/ts/test-mock-module.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript-Module!/); - match(result.stdout, /Hello, TypeScript-CommonJS!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript-Module!/); + assert.match(result.stdout, /Hello, TypeScript-CommonJS!/); + assert.strictEqual(result.code, 0); }); test('expect process.features.typescript to be strip', async () => { - strictEqual(process.features.typescript, 'strip'); + assert.strictEqual(process.features.typescript, 'strip'); }); test('execute a TypeScript file with union types', async () => { @@ -273,15 +273,15 @@ test('execute a TypeScript file with union types', async () => { fixtures.path('typescript/ts/test-union-types.ts'), ]); - strictEqual(result.stderr, ''); - strictEqual(result.stdout, - '{' + - " name: 'Hello, TypeScript!' }\n" + - '{ role: \'admin\', permission: \'all\' }\n' + - '{\n foo: \'Testing Partial Type\',\n bar: 42,\n' + - ' zoo: true,\n metadata: undefined\n' + - '}\n'); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.strictEqual(result.stdout, + '{' + + " name: 'Hello, TypeScript!' }\n" + + '{ role: \'admin\', permission: \'all\' }\n' + + '{\n foo: \'Testing Partial Type\',\n bar: 42,\n' + + ' zoo: true,\n metadata: undefined\n' + + '}\n'); + assert.strictEqual(result.code, 0); }); test('expect error when executing a TypeScript file with generics', async () => { @@ -290,12 +290,12 @@ test('expect error when executing a TypeScript file with generics', async () => ]); // This error should be thrown during transformation - match( + assert.match( result.stderr, /TypeScript parameter property is not supported in strip-only mode/ ); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('execute a TypeScript loader and a .ts file', async () => { @@ -305,9 +305,9 @@ test('execute a TypeScript loader and a .ts file', async () => { fixtures.fileURL('typescript/ts/test-loader.ts'), fixtures.path('typescript/ts/test-typescript.ts'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute a TypeScript loader and a .js file', async () => { @@ -317,9 +317,9 @@ test('execute a TypeScript loader and a .js file', async () => { fixtures.fileURL('typescript/ts/test-loader.ts'), fixtures.path('typescript/ts/test-simple.js'), ]); - strictEqual(result.stderr, ''); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.strictEqual(result.stderr, ''); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); test('execute invalid TypeScript syntax', async () => { @@ -327,9 +327,9 @@ test('execute invalid TypeScript syntax', async () => { fixtures.path('typescript/ts/test-invalid-syntax.ts'), ]); - match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/); - strictEqual(result.stdout, ''); - strictEqual(result.code, 1); + assert.match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/); + assert.strictEqual(result.stdout, ''); + assert.strictEqual(result.code, 1); }); test('check transform types warning', async () => { @@ -338,7 +338,7 @@ test('check transform types warning', async () => { fixtures.path('typescript/ts/test-typescript.ts'), ]); - match(result.stderr, /Transform Types is an experimental feature and might change at any time/); - match(result.stdout, /Hello, TypeScript!/); - strictEqual(result.code, 0); + assert.match(result.stderr, /Transform Types is an experimental feature and might change at any time/); + assert.match(result.stdout, /Hello, TypeScript!/); + assert.strictEqual(result.code, 0); }); diff --git a/test/es-module/test-wasm-web-api.js b/test/es-module/test-wasm-web-api.js index 879748e4403b07..a6943254d88d83 100644 --- a/test/es-module/test-wasm-web-api.js +++ b/test/es-module/test-wasm-web-api.js @@ -45,17 +45,17 @@ function testCompileStreaming(makeResponsePromise, checkResult) { } function testCompileStreamingSuccess(makeResponsePromise) { - return testCompileStreaming(makeResponsePromise, async (modPromise) => { + return testCompileStreaming(makeResponsePromise, common.mustCall(async (modPromise) => { const mod = await modPromise; assert.strictEqual(mod.constructor, WebAssembly.Module); - }); + }, 2)); } function testCompileStreamingRejection(makeResponsePromise, rejection) { - return testCompileStreaming(makeResponsePromise, (modPromise) => { + return testCompileStreaming(makeResponsePromise, common.mustCall((modPromise) => { assert.strictEqual(modPromise.constructor, Promise); return assert.rejects(modPromise, rejection); - }); + }, 2)); } function testCompileStreamingSuccessUsingFetch(responseCallback) { @@ -70,13 +70,13 @@ function testCompileStreamingRejectionUsingFetch(responseCallback, rejection) { (async () => { // A non-Response should cause a TypeError. for (const invalid of [undefined, null, 0, true, 'foo', {}, [], Symbol()]) { - await withPromiseAndResolved(() => Promise.resolve(invalid), (arg) => { + await withPromiseAndResolved(() => Promise.resolve(invalid), common.mustCall((arg) => { return assert.rejects(() => WebAssembly.compileStreaming(arg), { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE', message: /^The "source" argument .*$/ }); - }); + }, 2)); } // When given a Promise, any rejection should be propagated as-is. @@ -120,7 +120,7 @@ function testCompileStreamingRejectionUsingFetch(responseCallback, rejection) { // the same WebAssembly file as in the previous test but insert useless custom // sections into the WebAssembly module to increase the file size without // changing the relevant contents. - await testCompileStreamingSuccessUsingFetch((res) => { + await testCompileStreamingSuccessUsingFetch(common.mustCall((res) => { res.setHeader('Content-Type', 'application/wasm'); // Send the WebAssembly magic and version first. @@ -150,7 +150,7 @@ function testCompileStreamingRejectionUsingFetch(responseCallback, rejection) { res.end(simpleWasmBytes.slice(8)); } })(0); - }); + }, 2)); // A valid WebAssembly file with an empty parameter in the (otherwise valid) // MIME type. @@ -233,7 +233,7 @@ function testCompileStreamingRejectionUsingFetch(responseCallback, rejection) { // which only contains an 'unreachable' instruction. res.setHeader('Content-Type', 'application/wasm'); res.end(fixtures.readSync('crash.wasm')); - }), async (modPromise) => { + }), common.mustCall(async (modPromise) => { // Call the WebAssembly function and check that the error stack contains the // correct "WebAssembly location" as per the specification. const mod = await modPromise; @@ -245,5 +245,5 @@ function testCompileStreamingRejectionUsingFetch(responseCallback, rejection) { /^\s*at http:\/\/127\.0\.0\.1:\d+\/foo\.wasm:wasm-function\[0\]:0x22$/); return true; }); - }); + }, 2)); })().then(common.mustCall()); diff --git a/test/eslint.config_partial.mjs b/test/eslint.config_partial.mjs index c53c0d4d24405e..e3f13fca4cf240 100644 --- a/test/eslint.config_partial.mjs +++ b/test/eslint.config_partial.mjs @@ -165,6 +165,7 @@ export default [ 'client-proxy', 'doctool', 'embedding', + 'es-module', 'fixtures', 'fuzzers', 'internet',