|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2026 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +// Note: can be converted to ts file once node 20 support is dropped. |
| 8 | +// Node 20 does not support --experimental-strip-types flag. |
| 9 | + |
| 10 | +import {spawn} from 'node:child_process'; |
| 11 | +import path from 'node:path'; |
| 12 | +import process from 'node:process'; |
| 13 | + |
| 14 | +const args = process.argv.slice(2); |
| 15 | +const userArgs = args.filter(arg => !arg.startsWith('-')); |
| 16 | +const flags = args.filter(arg => arg.startsWith('-')); |
| 17 | + |
| 18 | +const files = []; |
| 19 | + |
| 20 | +if (userArgs.length > 0) { |
| 21 | + for (const arg of userArgs) { |
| 22 | + // Map .ts files to build/ .js files |
| 23 | + let testPath = arg; |
| 24 | + if (testPath.endsWith('.ts')) { |
| 25 | + testPath = testPath.replace(/\.ts$/, '.js'); |
| 26 | + if (!testPath.startsWith('build/')) { |
| 27 | + testPath = path.join('build', testPath); |
| 28 | + } |
| 29 | + } |
| 30 | + files.push(testPath); |
| 31 | + } |
| 32 | +} else { |
| 33 | + const isNode20 = process.version.startsWith('v20.'); |
| 34 | + if (isNode20) { |
| 35 | + files.push('build/tests'); |
| 36 | + } else { |
| 37 | + files.push('build/tests/**/*.test.js'); |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +const nodeArgs = [ |
| 42 | + '--import', |
| 43 | + './build/tests/setup.js', |
| 44 | + '--no-warnings=ExperimentalWarning', |
| 45 | + '--test-reporter', |
| 46 | + 'spec', |
| 47 | + '--test-force-exit', |
| 48 | + '--test', |
| 49 | + ...flags, |
| 50 | + ...files, |
| 51 | +]; |
| 52 | + |
| 53 | +const child = spawn('node', nodeArgs, { |
| 54 | + stdio: 'inherit', |
| 55 | +}); |
| 56 | + |
| 57 | +child.on('close', code => { |
| 58 | + process.exit(code ?? 1); |
| 59 | +}); |
0 commit comments