From d09c3ffb7ca85606d491e51ff15b11416a4f85a6 Mon Sep 17 00:00:00 2001 From: Yuki Okita Date: Sat, 29 Nov 2025 00:37:42 +0900 Subject: [PATCH] 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 Reviewed-By: Antoine du Hamel --- src/node_options.cc | 2 +- src/node_options.h | 2 +- test/es-module/test-esm-import-meta-main-eval.mjs | 8 +++++--- test/es-module/test-esm-loader-entry-url.mjs | 4 +++- test/es-module/test-esm-resolve-type.mjs | 4 ++++ test/parallel/test-cli-node-options-docs.js | 5 +++++ .../test-compile-cache-typescript-commonjs.js | 5 ++++- test/parallel/test-compile-cache-typescript-esm.js | 5 ++++- .../test-compile-cache-typescript-strip-miss.js | 5 ++++- ...st-compile-cache-typescript-strip-sourcemaps.js | 5 ++++- .../test-compile-cache-typescript-transform.js | 5 ++++- test/parallel/test-config-file.js | 11 ++++++----- test/parallel/test-node-output-eval.mjs | 5 ++++- test/parallel/test-node-output-sourcemaps.mjs | 3 ++- .../parallel/test-runner-global-setup-teardown.mjs | 4 +++- test/parallel/test-runner-run-global-hooks.mjs | 4 +++- test/parallel/test-util-getcallsites.js | 4 +++- test/parallel/test-worker-eval-typescript.js | 14 ++++++++------ .../test-output-typescript-coverage.mjs | 3 +++ 19 files changed, 71 insertions(+), 27 deletions(-) diff --git a/src/node_options.cc b/src/node_options.cc index baa3936075c..07a466e299d 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -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" diff --git a/src/node_options.h b/src/node_options.h index dd782b460ae..2d30c115dcb 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -259,7 +259,7 @@ class EnvironmentOptions : public Options { std::vector preload_esm_modules; - bool strip_types = true; + bool strip_types = HAVE_AMARO; bool experimental_transform_types = false; std::vector user_argv; diff --git a/test/es-module/test-esm-import-meta-main-eval.mjs b/test/es-module/test-esm-import-meta-main-eval.mjs index cf4642eac89..978cd88fc56 100644 --- a/test/es-module/test-esm-import-meta-main-eval.mjs +++ b/test/es-module/test-esm-import-meta-main-eval.mjs @@ -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', diff --git a/test/es-module/test-esm-loader-entry-url.mjs b/test/es-module/test-esm-loader-entry-url.mjs index f6be7bcf7ee..ae9396567fa 100644 --- a/test/es-module/test-esm-loader-entry-url.mjs +++ b/test/es-module/test-esm-loader-entry-url.mjs @@ -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', diff --git a/test/es-module/test-esm-resolve-type.mjs b/test/es-module/test-esm-resolve-type.mjs index 9d97413379a..fbd75d98a8d 100644 --- a/test/es-module/test-esm-resolve-type.mjs +++ b/test/es-module/test-esm-resolve-type.mjs @@ -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`); diff --git a/test/parallel/test-cli-node-options-docs.js b/test/parallel/test-cli-node-options-docs.js index f3034ef64bc..1be5ede13ce 100644 --- a/test/parallel/test-cli-node-options-docs.js +++ b/test/parallel/test-cli-node-options-docs.js @@ -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) || diff --git a/test/parallel/test-compile-cache-typescript-commonjs.js b/test/parallel/test-compile-cache-typescript-commonjs.js index b6c4581ed47..60e86c3c0f9 100644 --- a/test/parallel/test-compile-cache-typescript-commonjs.js +++ b/test/parallel/test-compile-cache-typescript-commonjs.js @@ -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'); diff --git a/test/parallel/test-compile-cache-typescript-esm.js b/test/parallel/test-compile-cache-typescript-esm.js index cec7b814da6..98473dbb2a5 100644 --- a/test/parallel/test-compile-cache-typescript-esm.js +++ b/test/parallel/test-compile-cache-typescript-esm.js @@ -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'); diff --git a/test/parallel/test-compile-cache-typescript-strip-miss.js b/test/parallel/test-compile-cache-typescript-strip-miss.js index 5d37a377f00..e3accd6f534 100644 --- a/test/parallel/test-compile-cache-typescript-strip-miss.js +++ b/test/parallel/test-compile-cache-typescript-strip-miss.js @@ -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'); diff --git a/test/parallel/test-compile-cache-typescript-strip-sourcemaps.js b/test/parallel/test-compile-cache-typescript-strip-sourcemaps.js index da5e350496f..a6c95e432b7 100644 --- a/test/parallel/test-compile-cache-typescript-strip-sourcemaps.js +++ b/test/parallel/test-compile-cache-typescript-strip-sourcemaps.js @@ -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'); diff --git a/test/parallel/test-compile-cache-typescript-transform.js b/test/parallel/test-compile-cache-typescript-transform.js index 41eb67b203b..8432d189a50 100644 --- a/test/parallel/test-compile-cache-typescript-transform.js +++ b/test/parallel/test-compile-cache-typescript-transform.js @@ -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'); diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index 438a138f6ba..9ffc2a90bee 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -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', diff --git a/test/parallel/test-node-output-eval.mjs b/test/parallel/test-node-output-eval.mjs index 8a3cc595742..56a880c8adf 100644 --- a/test/parallel/test-node-output-eval.mjs +++ b/test/parallel/test-node-output-eval.mjs @@ -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'; diff --git a/test/parallel/test-node-output-sourcemaps.mjs b/test/parallel/test-node-output-sourcemaps.mjs index 2d0e784e206..e883ff2c57a 100644 --- a/test/parallel/test-node-output-sourcemaps.mjs +++ b/test/parallel/test-node-output-sourcemaps.mjs @@ -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); }); } diff --git a/test/parallel/test-runner-global-setup-teardown.mjs b/test/parallel/test-runner-global-setup-teardown.mjs index 9498efbc73f..56b5ca6b112 100644 --- a/test/parallel/test-runner-global-setup-teardown.mjs +++ b/test/parallel/test-runner-global-setup-teardown.mjs @@ -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'); diff --git a/test/parallel/test-runner-run-global-hooks.mjs b/test/parallel/test-runner-run-global-hooks.mjs index d63f98af9d5..c047d61c7ca 100644 --- a/test/parallel/test-runner-run-global-hooks.mjs +++ b/test/parallel/test-runner-run-global-hooks.mjs @@ -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'); diff --git a/test/parallel/test-util-getcallsites.js b/test/parallel/test-util-getcallsites.js index 1219e097378..7cab4f6cac6 100644 --- a/test/parallel/test-util-getcallsites.js +++ b/test/parallel/test-util-getcallsites.js @@ -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'); diff --git a/test/parallel/test-worker-eval-typescript.js b/test/parallel/test-worker-eval-typescript.js index 6998bc031a3..5f1eac1eb9d 100644 --- a/test/parallel/test-worker-eval-typescript.js +++ b/test/parallel/test-worker-eval-typescript.js @@ -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'); diff --git a/test/test-runner/test-output-typescript-coverage.mjs b/test/test-runner/test-output-typescript-coverage.mjs index 41aa97d194c..50892f230cc 100644 --- a/test/test-runner/test-output-typescript-coverage.mjs +++ b/test/test-runner/test-output-typescript-coverage.mjs @@ -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';