Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Node.js writer for the OpenTelemetry thread-context record (OTEP-4947), discoverable via AsyncLocalStorage / AsyncContextFrame.",
"main": "index.js",
"scripts": {
"test": "node --experimental-async-context-frame --disable-warning=ExperimentalWarning --test test/test.js",
"test": "node test/run.js",
"test:docker": "./test/run-in-docker.sh",
"install": "node build.js"
},
Expand Down
16 changes: 16 additions & 0 deletions js/test/node-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

// Node flags needed to make AsyncContextFrame — the writer's discovery
// substrate — available on the running Node.
//
// Node 22/23 need the --experimental-async-context-frame opt-in. Node 24
// turned ACF on by default and *removed* the flag, so passing it there is a
// hard `node: bad option` failure rather than a no-op. Anything that spawns a
// Node process for these tests has to compute the list rather than hardcode
// it; that includes `npm test` itself (see run.js).
function acfFlags() {
const major = Number(process.versions.node.split('.')[0]);
return major >= 22 && major < 24 ? ['--experimental-async-context-frame'] : [];
}

module.exports = { acfFlags };
36 changes: 36 additions & 0 deletions js/test/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

// `npm test` entry point.
//
// The script used to pass --experimental-async-context-frame unconditionally,
// which works on Node 22/23 and fails outright from Node 24 on, where the flag
// was removed:
//
// node: bad option: --experimental-async-context-frame
//
// so `npm test` was broken on every current Node. Compute the flags instead.

const { spawnSync } = require('node:child_process');
const path = require('node:path');

const { acfFlags } = require('./node-flags');

const major = Number(process.versions.node.split('.')[0]);
const flags = [...acfFlags()];
// --disable-warning landed in Node 21.3; on older Node it would itself be a
// bad option. Nothing below 22 can run these tests anyway (test.js bails).
if (major >= 22) {
flags.push('--disable-warning=ExperimentalWarning');
}

const res = spawnSync(
process.execPath,
[...flags, '--test', path.join(__dirname, 'test.js')],
{ stdio: 'inherit' },
);

if (res.error) {
console.error(res.error);
process.exit(1);
}
process.exit(res.status === null ? 1 : res.status);