Skip to content

Commit cfbd54b

Browse files
committed
fix: suppress experimental warning for node 23
1 parent c29b2fe commit cfbd54b

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

.github/workflows/smoke-tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Run Smoke Tests"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
schedule:
9+
- cron: "0 0 * * *"
10+
11+
jobs:
12+
smoke-tests:
13+
strategy:
14+
matrix:
15+
runner: [ubuntu-latest, macos-latest, windows-latest]
16+
node: [20.x, 22.x, 23.x]
17+
runs-on: ${{ matrix.runner }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node }}
23+
- run: npm ci
24+
- run: npm run test-smoke

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"test-evergreen-expansions": "bash .evergreen/compilation-context-expansions.test.sh",
2727
"replace-package": "node scripts/replace-package.js",
2828
"test-nodedriver": "bash .evergreen/test-node-driver.sh",
29+
"pretest-smoke": "npm run compile-cli",
30+
"test-smoke": "npm run test-smoke -w @mongosh/cli-repl",
2931
"compile": "npm run compile --workspaces --if-present",
3032
"compile-cli": "lerna run compile --scope @mongosh/cli-repl --include-dependencies",
3133
"prestart-cli": "npm run compile-cli",
@@ -167,4 +169,4 @@
167169
"overrides": {
168170
"cookie": "^0.7.2"
169171
}
170-
}
172+
}

packages/cli-repl/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",
2727
"test-ci-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test-ci",
2828
"test-apistrict-ci": "cross-env MONGOSH_TEST_FORCE_API_STRICT=1 npm run test-ci",
29+
"test-smoke": "node bin/mongosh.js --smokeTests",
2930
"eslint": "eslint",
3031
"lint": "npm run eslint . && npm run prettier -- --check .",
3132
"check": "npm run lint && npm run depcheck",

packages/cli-repl/src/run.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if ((v8 as any)?.startupSnapshot?.isBuildingSnapshot?.()) {
6969
// eslint-disable-next-line complexity
7070
async function main() {
7171
markTime(TimingCategories.Main, 'entered main');
72+
suppressExperimentalWarnings();
7273
if (process.env.MONGOSH_RUN_NODE_SCRIPT) {
7374
// For uncompiled mongosh: node /path/to/this/file script ... -> node script ...
7475
// FOr compiled mongosh: mongosh mongosh script ... -> mongosh script ...
@@ -311,3 +312,32 @@ async function ask(prompt: string): Promise<string> {
311312
process.stdin.unpipe(stdinCopy);
312313
}
313314
}
315+
316+
/**
317+
* Helper to suppress experimental warnings emitted by node if necessary.
318+
*
319+
* In Node.js 23 require()ing ESM modules will work, but emit an experimental warning like
320+
* CommonJS module ABC is loading ES Module XYZ using require(). This is causing problems for
321+
* the way we import fetch - see relevant comments here:
322+
* https://github.com/mongodb-js/devtools-shared/blob/29ceeb5f51d29883d4a69c83e68ad37b0965d49e/packages/devtools-proxy-support/src/fetch.ts#L12-L17
323+
*/
324+
function suppressExperimentalWarnings() {
325+
const nodeMajorVersion = process.versions.node.split('.').map(Number)[0];
326+
if (nodeMajorVersion >= 23) {
327+
const originalEmit = process.emitWarning;
328+
process.emitWarning = (warning, ...args: any[]): void => {
329+
if (args[0] === 'ExperimentalWarning') {
330+
return;
331+
}
332+
333+
if (
334+
typeof args[0] === 'object' &&
335+
args[0].type === 'ExperimentalWarning'
336+
) {
337+
return;
338+
}
339+
340+
originalEmit(warning, ...args);
341+
};
342+
}
343+
}

packages/cli-repl/src/smoke-tests.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ async function runSmokeTest({
397397
// eslint-disable-next-line
398398
const { spawn } = require('child_process') as typeof import('child_process');
399399
const proc = spawn(executable, [...args], {
400-
stdio: ['pipe', 'pipe', includeStderr ? 'pipe' : 'inherit'],
400+
stdio: 'pipe',
401401
});
402402
let stdout = '';
403403
let stderr = '';
@@ -420,13 +420,14 @@ async function runSmokeTest({
420420
input,
421421
output,
422422
stdout,
423-
stderr,
423+
stderr: includeStderr ? stderr : '',
424424
executable,
425425
actualExitCode,
426426
args: args.map((arg) => redactURICredentials(arg)),
427427
};
428428
try {
429429
assert.match(includeStderr ? `${stdout}\n${stderr}` : stdout, output);
430+
assert.doesNotMatch(stderr, /ExperimentalWarning/);
430431
if (exitCode !== undefined) {
431432
assert.strictEqual(actualExitCode, exitCode);
432433
}

0 commit comments

Comments
 (0)