Skip to content

Commit c89949a

Browse files
committed
test: move amaro checks after common import
Move the amaro availability check immediately after importing common module in test files, as requested in PR feedback. Changes: - Place amaro check after common import but before other imports - Update test-node-output-sourcemaps.mjs to dynamically skip .ts tests based on file extension - Add individual skip conditions for TypeScript-specific tests - Fix linting errors (missing semicolon, line length issues) Refs: nodejs#60815
1 parent 0911552 commit c89949a

21 files changed

+230
-255
lines changed

src/node_options.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,12 +1092,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
10921092
"Type-stripping for TypeScript files.",
10931093
&EnvironmentOptions::strip_types,
10941094
kAllowedInEnvvar,
1095-
#if HAVE_AMARO
1096-
true
1097-
#else
1098-
false
1099-
#endif // HAVE_AMARO
1100-
);
1095+
HAVE_AMARO);
11011096
AddAlias("--experimental-strip-types", "--strip-types");
11021097
AddOption("--experimental-transform-types",
11031098
"enable transformation of TypeScript-only"

test/es-module/test-esm-detect-ambiguous.mjs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import * as common from '../common/index.mjs';
1+
import { spawnPromisified } from '../common/index.mjs';
22
import * as fixtures from '../common/fixtures.mjs';
33
import { spawn } from 'node:child_process';
44
import { describe, it } from 'node:test';
55
import assert from 'node:assert';
66

7-
if (!process.config.variables.node_use_amaro) {
8-
common.skip('Requires Amaro');
9-
}
10-
const { spawnPromisified } = common;
11-
127
describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL }, () => {
138
describe('string input', { concurrency: !process.env.TEST_PARALLEL }, () => {
149
it('permits ESM syntax in --eval input without requiring --input-type=module', async () => {
@@ -268,17 +263,19 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL },
268263
assert.strictEqual(signal, null);
269264
});
270265

271-
it('still throws on `await` in an ordinary sync function', async () => {
272-
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
273-
'--eval',
274-
'function fn() { await Promise.resolve(); } fn();',
275-
]);
266+
it('still throws on `await` in an ordinary sync function',
267+
{ skip: !process.config.variables.node_use_amaro },
268+
async () => {
269+
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
270+
'--eval',
271+
'function fn() { await Promise.resolve(); } fn();',
272+
]);
276273

277-
assert.match(stderr, /SyntaxError: await is only valid in async function/);
278-
assert.strictEqual(stdout, '');
279-
assert.strictEqual(code, 1);
280-
assert.strictEqual(signal, null);
281-
});
274+
assert.match(stderr, /SyntaxError: await is only valid in async function/);
275+
assert.strictEqual(stdout, '');
276+
assert.strictEqual(code, 1);
277+
assert.strictEqual(signal, null);
278+
});
282279

283280
it('throws on undefined `require` when top-level `await` triggers ESM parsing', async () => {
284281
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
@@ -319,17 +316,19 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL },
319316
assert.strictEqual(signal, null);
320317
});
321318

322-
it('still throws on double `const` declaration not at the top level', async () => {
323-
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
324-
'--eval',
325-
'function fn() { const require = 1; const require = 2; } fn();',
326-
]);
327-
328-
assert.match(stderr, /SyntaxError: Identifier 'require' has already been declared/);
329-
assert.strictEqual(stdout, '');
330-
assert.strictEqual(code, 1);
331-
assert.strictEqual(signal, null);
332-
});
319+
it('still throws on double `const` declaration not at the top level',
320+
{ skip: !process.config.variables.node_use_amaro },
321+
async () => {
322+
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
323+
'--eval',
324+
'function fn() { const require = 1; const require = 2; } fn();',
325+
]);
326+
327+
assert.match(stderr, /SyntaxError: Identifier 'require' has already been declared/);
328+
assert.strictEqual(stdout, '');
329+
assert.strictEqual(code, 1);
330+
assert.strictEqual(signal, null);
331+
});
333332
});
334333

335334
describe('warn about typeless packages for .js files with ESM syntax', { concurrency: true }, () => {

test/es-module/test-esm-import-meta-main-eval.mjs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import * as common from '../common/index.mjs';
1+
import { spawnPromisified } from '../common/index.mjs';
22
import * as fixtures from '../common/fixtures.js';
33
import assert from 'node:assert/strict';
44
import { describe, it } from 'node:test';
55

6-
if (!process.config.variables.node_use_amaro) {
7-
common.skip('Requires Amaro');
8-
}
9-
const { spawnPromisified } = common;
10-
116
function wrapScriptInEvalWorker(script) {
127
return `
138
import { Worker } from 'node:worker_threads';
@@ -38,7 +33,7 @@ const { isMain: importedModuleIsMain } = await import(
3833
assert.strictEqual(importedModuleIsMain, false, 'import.meta.main should evaluate false in imported module');
3934
`;
4035

41-
it('should evaluate true in evaluated script', async () => {
36+
it('should evaluate true in evaluated script', { skip: !process.config.variables.node_use_amaro }, async () => {
4237
const result = await spawnPromisified(
4338
process.execPath,
4439
['--input-type=module', '--eval', importMetaMainScript],
@@ -103,35 +98,39 @@ assert.strictEqual(importedModuleIsMain, false, 'import.meta.main should evaluat
10398
});
10499
});
105100

106-
it('should evaluate true in worker instantiated with module source by evaluated script', async () => {
107-
const result = await spawnPromisified(
108-
process.execPath,
109-
['--input-type=module-typescript',
110-
'--disable-warning=ExperimentalWarning',
111-
'--eval',
112-
wrapScriptInEvalWorker(importMetaMainTSScript)],
113-
);
114-
assert.deepStrictEqual(result, {
115-
stderr: '',
116-
stdout: '',
117-
code: 0,
118-
signal: null,
119-
});
120-
});
121-
122-
it('should evaluate true in worker instantiated with `data:` URL by evaluated script', async () => {
123-
const result = await spawnPromisified(
124-
process.execPath,
125-
['--input-type=module',
126-
'--input-type=module-typescript',
127-
'--disable-warning=ExperimentalWarning',
128-
'--eval', wrapScriptInUrlWorker(importMetaMainTSScript)],
129-
);
130-
assert.deepStrictEqual(result, {
131-
stderr: '',
132-
stdout: '',
133-
code: 0,
134-
signal: null,
135-
});
136-
});
101+
it('should evaluate true in worker instantiated with module source by evaluated script',
102+
{ skip: !process.config.variables.node_use_amaro },
103+
async () => {
104+
const result = await spawnPromisified(
105+
process.execPath,
106+
['--input-type=module-typescript',
107+
'--disable-warning=ExperimentalWarning',
108+
'--eval',
109+
wrapScriptInEvalWorker(importMetaMainTSScript)],
110+
);
111+
assert.deepStrictEqual(result, {
112+
stderr: '',
113+
stdout: '',
114+
code: 0,
115+
signal: null,
116+
});
117+
});
118+
119+
it('should evaluate true in worker instantiated with `data:` URL by evaluated script',
120+
{ skip: !process.config.variables.node_use_amaro },
121+
async () => {
122+
const result = await spawnPromisified(
123+
process.execPath,
124+
['--input-type=module',
125+
'--input-type=module-typescript',
126+
'--disable-warning=ExperimentalWarning',
127+
'--eval', wrapScriptInUrlWorker(importMetaMainTSScript)],
128+
);
129+
assert.deepStrictEqual(result, {
130+
stderr: '',
131+
stdout: '',
132+
code: 0,
133+
signal: null,
134+
});
135+
});
137136
});

test/es-module/test-esm-tla-syntax-errors-not-recognized-as-tla-error.mjs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import * as common from '../common/index.mjs';
1+
import { spawnPromisified } from '../common/index.mjs';
22
import { describe, it } from 'node:test';
33
import assert from 'node:assert';
44

5-
if (!process.config.variables.node_use_amaro) {
6-
common.skip('Requires Amaro');
7-
}
8-
const { spawnPromisified } = common;
9-
105
describe('unusual top-level await syntax errors', () => {
116
const expressions = [
127
// string
@@ -54,30 +49,32 @@ describe('unusual top-level await syntax errors', () => {
5449
}
5550
});
5651

57-
it('should throw the error for unrelated syntax errors', async () => {
58-
const expression = 'foo bar';
59-
const wrapperExpressions = [
60-
[`function callSyntaxError() {}; callSyntaxError(${expression});`, /missing \) after argument list/],
61-
[`if (${expression}) {}`, /Unexpected identifier/],
62-
[`{ key: ${expression} }`, /Unexpected identifier/],
63-
[`[${expression}]`, /Unexpected identifier/],
64-
[`(${expression})`, /Unexpected identifier/],
65-
[`const ${expression} = 1;`, /Missing initializer in const declaration/],
66-
[`console.log('PI: ' Math.PI);`, /missing \) after argument list/],
67-
[`callAwait(await "" "");`, /missing \) after argument list/],
68-
];
52+
it('should throw the error for unrelated syntax errors',
53+
{ skip: !process.config.variables.node_use_amaro },
54+
async () => {
55+
const expression = 'foo bar';
56+
const wrapperExpressions = [
57+
[`function callSyntaxError() {}; callSyntaxError(${expression});`, /missing \) after argument list/],
58+
[`if (${expression}) {}`, /Unexpected identifier/],
59+
[`{ key: ${expression} }`, /Unexpected identifier/],
60+
[`[${expression}]`, /Unexpected identifier/],
61+
[`(${expression})`, /Unexpected identifier/],
62+
[`const ${expression} = 1;`, /Missing initializer in const declaration/],
63+
[`console.log('PI: ' Math.PI);`, /missing \) after argument list/],
64+
[`callAwait(await "" "");`, /missing \) after argument list/],
65+
];
6966

70-
for (const [wrapperExpression, error] of wrapperExpressions) {
71-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
72-
'--eval',
73-
`
67+
for (const [wrapperExpression, error] of wrapperExpressions) {
68+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
69+
'--eval',
70+
`
7471
${wrapperExpression}
7572
`,
76-
]);
77-
assert.match(stderr, error);
78-
assert.strictEqual(stdout, '');
79-
assert.strictEqual(code, 1);
80-
assert.strictEqual(signal, null);
81-
}
82-
});
73+
]);
74+
assert.match(stderr, error);
75+
assert.strictEqual(stdout, '');
76+
assert.strictEqual(code, 1);
77+
assert.strictEqual(signal, null);
78+
}
79+
});
8380
});

test/parallel/test-compile-cache-typescript-commonjs.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
// This tests NODE_COMPILE_CACHE works for CommonJS with types.
44

55
const common = require('../common');
6+
if (!process.config.variables.node_use_amaro) {
7+
common.skip('Requires Amaro');
8+
}
69
const { spawnSyncAndAssert } = require('../common/child_process');
710
const assert = require('assert');
811
const tmpdir = require('../common/tmpdir');
912
const fixtures = require('../common/fixtures');
1013

11-
if (!process.config.variables.node_use_amaro) {
12-
common.skip('Requires Amaro');
13-
}
14-
1514
// Check cache for .ts files that would be run as CommonJS.
1615
{
1716
tmpdir.refresh();

test/parallel/test-compile-cache-typescript-esm.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
// This tests NODE_COMPILE_CACHE works for ESM with types.
44

55
const common = require('../common');
6+
if (!process.config.variables.node_use_amaro) {
7+
common.skip('Requires Amaro');
8+
}
69
const { spawnSyncAndAssert } = require('../common/child_process');
710
const assert = require('assert');
811
const tmpdir = require('../common/tmpdir');
912
const fixtures = require('../common/fixtures');
1013

11-
if (!process.config.variables.node_use_amaro) {
12-
common.skip('Requires Amaro');
13-
}
14-
1514
// Check cache for .ts files that would be run as ESM.
1615
{
1716
tmpdir.refresh();

test/parallel/test-compile-cache-typescript-strip-miss.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
// between strip-only TypeScript and transformed TypeScript.
55

66
const common = require('../common');
7+
if (!process.config.variables.node_use_amaro) {
8+
common.skip('Requires Amaro');
9+
}
710
const { spawnSyncAndAssert } = require('../common/child_process');
811
const assert = require('assert');
912
const tmpdir = require('../common/tmpdir');
1013
const fixtures = require('../common/fixtures');
1114

12-
if (!process.config.variables.node_use_amaro) {
13-
common.skip('Requires Amaro');
14-
}
15-
1615
tmpdir.refresh();
1716
const dir = tmpdir.resolve('.compile_cache_dir');
1817
const script = fixtures.path('typescript', 'ts', 'test-typescript.ts');

test/parallel/test-compile-cache-typescript-strip-sourcemaps.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
// --enable-source-maps as there's no difference in the code generated.
55

66
const common = require('../common');
7+
if (!process.config.variables.node_use_amaro) {
8+
common.skip('Requires Amaro');
9+
}
710
const { spawnSyncAndAssert } = require('../common/child_process');
811
const assert = require('assert');
912
const tmpdir = require('../common/tmpdir');
1013
const fixtures = require('../common/fixtures');
1114

12-
if (!process.config.variables.node_use_amaro) {
13-
common.skip('Requires Amaro');
14-
}
15-
1615
tmpdir.refresh();
1716
const dir = tmpdir.resolve('.compile_cache_dir');
1817
const script = fixtures.path('typescript', 'ts', 'test-typescript.ts');

test/parallel/test-compile-cache-typescript-transform.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
// This tests NODE_COMPILE_CACHE works with --experimental-transform-types.
44

55
const common = require('../common');
6+
if (!process.config.variables.node_use_amaro) {
7+
common.skip('Requires Amaro');
8+
}
69
const { spawnSyncAndAssert } = require('../common/child_process');
710
const assert = require('assert');
811
const tmpdir = require('../common/tmpdir');
912
const fixtures = require('../common/fixtures');
1013

11-
if (!process.config.variables.node_use_amaro) {
12-
common.skip('Requires Amaro');
13-
}
14-
1514

1615
tmpdir.refresh();
1716
const dir = tmpdir.resolve('.compile_cache_dir');

0 commit comments

Comments
 (0)