test: skip failing tests when compiled without amaro

When compiled without amaro, this conflicts with
--experimental-strip-types defaulting to true. To avoid that,
we need to skip relevant failing tests.

Fixes: https://github.com/nodejs/node/issues/60640
PR-URL: https://github.com/nodejs/node/pull/60815
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Yuki Okita 2025-11-29 00:37:42 +09:00 committed by GitHub
parent 1b3a64deb4
commit d09c3ffb7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 71 additions and 27 deletions

View File

@ -1092,7 +1092,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"Type-stripping for TypeScript files.",
&EnvironmentOptions::strip_types,
kAllowedInEnvvar,
true);
HAVE_AMARO);
AddAlias("--experimental-strip-types", "--strip-types");
AddOption("--experimental-transform-types",
"enable transformation of TypeScript-only"

View File

@ -259,7 +259,7 @@ class EnvironmentOptions : public Options {
std::vector<std::string> preload_esm_modules;
bool strip_types = true;
bool strip_types = HAVE_AMARO;
bool experimental_transform_types = false;
std::vector<std::string> user_argv;

View File

@ -21,6 +21,8 @@ function wrapScriptInUrlWorker(script) {
`;
}
const onlyWithAmaro = { skip: !process.config.variables.node_use_amaro };
describe('import.meta.main in evaluated scripts', () => {
const importMetaMainScript = `
import assert from 'node:assert/strict';
@ -85,7 +87,7 @@ const { isMain: importedModuleIsMain } = await import(
assert.strictEqual(importedModuleIsMain, false, 'import.meta.main should evaluate false in imported module');
`;
it('should evaluate true in evaluated script', async () => {
it('should evaluate true in evaluated script', onlyWithAmaro, async () => {
const result = await spawnPromisified(
process.execPath,
['--input-type=module-typescript', '--disable-warning=ExperimentalWarning', '--eval', importMetaMainTSScript],
@ -98,7 +100,7 @@ assert.strictEqual(importedModuleIsMain, false, 'import.meta.main should evaluat
});
});
it('should evaluate true in worker instantiated with module source by evaluated script', async () => {
it('should evaluate true in worker instantiated with module source by evaluated script', onlyWithAmaro, async () => {
const result = await spawnPromisified(
process.execPath,
['--input-type=module-typescript',
@ -114,7 +116,7 @@ assert.strictEqual(importedModuleIsMain, false, 'import.meta.main should evaluat
});
});
it('should evaluate true in worker instantiated with `data:` URL by evaluated script', async () => {
it('should evaluate true in worker instantiated with `data:` URL by evaluated script', onlyWithAmaro, async () => {
const result = await spawnPromisified(
process.execPath,
['--input-type=module',

View File

@ -23,6 +23,8 @@ async function assertSpawnedProcess(args, options = {}, expected = {}) {
// Common expectation for experimental feature warning in stderr
const experimentalFeatureWarning = { stderr: /--entry-url is an experimental feature/ };
const onlyWithAmaro = { skip: !process.config.variables.node_use_amaro };
describe('--entry-url', { concurrency: true }, () => {
it('should reject loading a path that contains %', async () => {
await assertSpawnedProcess(
@ -76,7 +78,7 @@ describe('--entry-url', { concurrency: true }, () => {
);
});
it('should support loading TypeScript URLs', { skip: !process.config.variables.node_use_amaro }, async () => {
it('should support loading TypeScript URLs', onlyWithAmaro, async () => {
const typescriptUrls = [
'typescript/cts/test-require-ts-file.cts',
'typescript/mts/test-import-ts-file.mts',

View File

@ -198,6 +198,10 @@ try {
subdirPackageType,
expectedResolvedFormat,
mainSuffix = '' ] = testVariant;
const skip = mainImportScript.endsWith('.ts') && !process.config.variables.node_use_amaro;
if (skip) {
return;
}
const mDir = rel(`node_modules/${moduleName}`);
const subDir = rel(`node_modules/${moduleName}/subdir`);

View File

@ -63,6 +63,11 @@ for (const [, envVar, config] of nodeOptionsCC.matchAll(addOptionRE)) {
hasTrueAsDefaultValue = true;
}
// Exception for HAVE_AMARO conditional default (defaults to true when Amaro is available)
if (config.includes('HAVE_AMARO')) {
hasTrueAsDefaultValue = true;
}
if (
envVar.startsWith('[') ||
deprecated.includes(envVar) ||

View File

@ -2,7 +2,10 @@
// This tests NODE_COMPILE_CACHE works for CommonJS with types.
require('../common');
const common = require('../common');
if (!process.config.variables.node_use_amaro) {
common.skip('Requires Amaro');
}
const { spawnSyncAndAssert } = require('../common/child_process');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');

View File

@ -2,7 +2,10 @@
// This tests NODE_COMPILE_CACHE works for ESM with types.
require('../common');
const common = require('../common');
if (!process.config.variables.node_use_amaro) {
common.skip('Requires Amaro');
}
const { spawnSyncAndAssert } = require('../common/child_process');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');

View File

@ -3,7 +3,10 @@
// This tests NODE_COMPILE_CACHE can handle cache invalidation
// between strip-only TypeScript and transformed TypeScript.
require('../common');
const common = require('../common');
if (!process.config.variables.node_use_amaro) {
common.skip('Requires Amaro');
}
const { spawnSyncAndAssert } = require('../common/child_process');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');

View File

@ -3,7 +3,10 @@
// This tests NODE_COMPILE_CACHE can be used for type stripping and ignores
// --enable-source-maps as there's no difference in the code generated.
require('../common');
const common = require('../common');
if (!process.config.variables.node_use_amaro) {
common.skip('Requires Amaro');
}
const { spawnSyncAndAssert } = require('../common/child_process');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');

View File

@ -2,7 +2,10 @@
// This tests NODE_COMPILE_CACHE works with --experimental-transform-types.
require('../common');
const common = require('../common');
if (!process.config.variables.node_use_amaro) {
common.skip('Requires Amaro');
}
const { spawnSyncAndAssert } = require('../common/child_process');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');

View File

@ -13,6 +13,8 @@ const { test, it, describe } = require('node:test');
const { chmodSync, writeFileSync, constants } = require('node:fs');
const { join } = require('node:path');
const onlyWithAmaro = { skip: !process.config.variables.node_use_amaro };
test('should handle non existing json', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-config-file',
@ -49,7 +51,7 @@ test('should handle empty object json', async () => {
assert.strictEqual(result.code, 0);
});
test('should parse boolean flag', async () => {
test('should parse boolean flag', onlyWithAmaro, async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-config-file',
fixtures.path('rc/transform-types.json'),
@ -83,8 +85,7 @@ test('should throw an error when a flag is declared twice', async () => {
assert.strictEqual(result.code, 9);
});
test('should override env-file', async () => {
test('should override env-file', onlyWithAmaro, async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-config-file',
@ -97,7 +98,7 @@ test('should override env-file', async () => {
assert.strictEqual(result.code, 0);
});
test('should not override NODE_OPTIONS', async () => {
test('should not override NODE_OPTIONS', onlyWithAmaro, async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-config-file',
@ -114,7 +115,7 @@ test('should not override NODE_OPTIONS', async () => {
assert.strictEqual(result.code, 1);
});
test('should not override CLI flags', async () => {
test('should not override CLI flags', onlyWithAmaro, async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--no-experimental-transform-types',

View File

@ -1,4 +1,7 @@
import '../common/index.mjs';
import * as common from '../common/index.mjs';
if (!process.config.variables.node_use_amaro) {
common.skip('Requires Amaro');
}
import * as fixtures from '../common/fixtures.mjs';
import * as snapshot from '../common/assertSnapshot.js';
import { basename } from 'node:path';

View File

@ -35,7 +35,8 @@ describe('sourcemaps output', { concurrency: !process.env.TEST_PARALLEL }, () =>
{ name: 'source-map/output/source_map_throw_set_immediate.js' },
];
for (const { name, transform } of tests) {
it(name, async () => {
const skip = name.endsWith('.ts') && !process.config.variables.node_use_amaro;
it(name, { skip }, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
});
}

View File

@ -10,6 +10,8 @@ import { join } from 'node:path';
const testFixtures = fixtures.path('test-runner');
const onlyWithAmaro = { skip: !process.config.variables.node_use_amaro };
async function runTest(
{
isolation,
@ -256,7 +258,7 @@ async function runTest(
'Teardown should not run after setup fails');
});
it('should run TypeScript globalSetup and globalTeardown functions', async () => {
it('should run TypeScript globalSetup and globalTeardown functions', onlyWithAmaro, async () => {
const setupFlagPath = tmpdir.resolve('setup-executed-ts.tmp');
const teardownFlagPath = tmpdir.resolve('teardown-executed-ts.tmp');

View File

@ -8,6 +8,8 @@ import path from 'node:path';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
const onlyWithAmaro = { skip: !process.config.variables.node_use_amaro };
const testFixtures = fixtures.path('test-runner', 'global-setup-teardown');
const runnerFixture = fixtures.path('test-runner', 'test-runner-global-hooks.mjs');
@ -162,7 +164,7 @@ describe('require(\'node:test\').run with global hooks', { concurrency: false },
assert.strictEqual(content, 'Setup part, Teardown part');
});
it('should run TypeScript globalSetup and globalTeardown functions', async () => {
it('should run TypeScript globalSetup and globalTeardown functions', onlyWithAmaro, async () => {
const setupFlagPath = tmpdir.resolve('setup-executed-ts.tmp');
const teardownFlagPath = tmpdir.resolve('teardown-executed-ts.tmp');

View File

@ -1,7 +1,9 @@
'use strict';
const common = require('../common');
if (!process.config.variables.node_use_amaro) {
common.skip('Requires Amaro');
}
const fixtures = require('../common/fixtures');
const file = fixtures.path('get-call-sites.js');

View File

@ -19,18 +19,20 @@ const cjsHelloWorld = `
const disableTypeScriptWarningFlag = '--disable-warning=ExperimentalWarning';
test('Worker eval module typescript without input-type', async () => {
const onlyWithAmaro = { skip: !process.config.variables.node_use_amaro };
test('Worker eval module typescript without input-type', onlyWithAmaro, async () => {
const w = new Worker(esmHelloWorld, { eval: true, execArgv: [disableTypeScriptWarningFlag] });
assert.deepStrictEqual(await once(w, 'message'), ['Hello, World!']);
});
test('Worker eval module typescript with --input-type=module-typescript', async () => {
test('Worker eval module typescript with --input-type=module-typescript', onlyWithAmaro, async () => {
const w = new Worker(esmHelloWorld, { eval: true, execArgv: ['--input-type=module-typescript',
disableTypeScriptWarningFlag] });
assert.deepStrictEqual(await once(w, 'message'), ['Hello, World!']);
});
test('Worker eval module typescript with --input-type=commonjs-typescript', async () => {
test('Worker eval module typescript with --input-type=commonjs-typescript', onlyWithAmaro, async () => {
const w = new Worker(esmHelloWorld, { eval: true, execArgv: ['--input-type=commonjs-typescript',
disableTypeScriptWarningFlag] });
@ -47,18 +49,18 @@ test('Worker eval module typescript with --input-type=module', async () => {
assert.match(err.message, /Missing initializer in const declaration/);
});
test('Worker eval commonjs typescript without input-type', async () => {
test('Worker eval commonjs typescript without input-type', onlyWithAmaro, async () => {
const w = new Worker(cjsHelloWorld, { eval: true, execArgv: [disableTypeScriptWarningFlag] });
assert.deepStrictEqual(await once(w, 'message'), ['Hello, World!']);
});
test('Worker eval commonjs typescript with --input-type=commonjs-typescript', async () => {
test('Worker eval commonjs typescript with --input-type=commonjs-typescript', onlyWithAmaro, async () => {
const w = new Worker(cjsHelloWorld, { eval: true, execArgv: ['--input-type=commonjs-typescript',
disableTypeScriptWarningFlag] });
assert.deepStrictEqual(await once(w, 'message'), ['Hello, World!']);
});
test('Worker eval commonjs typescript with --input-type=module-typescript', async () => {
test('Worker eval commonjs typescript with --input-type=module-typescript', onlyWithAmaro, async () => {
const w = new Worker(cjsHelloWorld, { eval: true, execArgv: ['--input-type=module-typescript',
disableTypeScriptWarningFlag] });
const [err] = await once(w, 'error');

View File

@ -1,6 +1,9 @@
// Test that the output of test-runner/output/typescript-coverage.mts matches
// test-runner/output/typescript-coverage.snapshot
import * as common from '../common/index.mjs';
if (!process.config.variables.node_use_amaro) {
common.skip('Requires Amaro');
}
import * as fixtures from '../common/fixtures.mjs';
import { spawnAndAssert, defaultTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js';