run-test: pass --experimental-test-module-mocks through to node

Specs that replace a module need mock.module from node:test, which
Node only exposes behind this flag. The runner rejected unknown flags,
so there was no way to turn it on. It is now accepted and forwarded to
node like --import and --require.

The repo's own test run enables it, and a spec checks that a module
registered as a mock is what a later dynamic import receives.
This commit is contained in:
Satoshi Qazi Muhammed committed 2026-10-10 08:42:29 +04:00
1 parent 15747fde74
commit 2e3c47bbd7
4 files changed
+25 -1

No files matched your search

+1 -1
View File
@@ -30,7 +30,7 @@
"docs": "pezkuwi-dev-build-docs",
"lint": "pezkuwi-dev-run-lint",
"postinstall": "./packages/dev/scripts/pezkuwi-dev-yarn-only.mjs",
"test": "yarn build && pezkuwi-dev-run-test --dev-build --env browser"
"test": "yarn build && pezkuwi-dev-run-test --dev-build --experimental-test-module-mocks --env browser"
},
"devDependencies": {
"@pezkuwi/dev": "workspace:packages/dev",
+14
View File
@@ -0,0 +1,14 @@
// Copyright 2017-2026 @pezkuwi/dev-test authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { mock } from 'node:test';
describe('mock.module', () => {
it('replaces a module loaded after the mock is registered', async () => {
mock.module('node:os', { namedExports: { platform: () => 'mocked' } });
const { platform } = await import('node:os');
expect(platform()).toBe('mocked');
});
});
+5
View File
@@ -252,6 +252,11 @@ This script runs test files in the repository, filtering by file extensions and
- **`--logfile <file>`**:
Specifies a log file to capture test output.
- **`--experimental-test-module-mocks`**:
Passed to Node.js, enabling `mock.module` from `node:test`. Node only swaps a module that has not
been loaded yet, so a spec registers its mocks first and then loads the code under test with a
dynamic `import()`.
- **`--import <module>`**:
Imports the specified module.
@@ -58,6 +58,11 @@ for (let i = 0; i < args.length; i++) {
cmd.push(args[++i]);
break;
// node flags with no params
case '--experimental-test-module-mocks':
nodeFlags.push(args[i]);
break;
// node flags that could have additional params
case '--import':
case '--loader':