Follow-up to https://github.com/xtermjs/xterm.js/issues/5896 / PR #5966. Converting addons to ../../../src/common relative imports broke unit tests: esbuild emits addon code under addons/*/out-esbuild/ without mirroring the shared tree, so Node could not load TypeScript sources at runtime (Cannot find module '../../../src/common/Lifecycle'). Core src/, test/, and headless continue to use relative imports with no common/* path mappings. Addons keep the prior model until build layout can share out-esbuild the same way as the main package. Changes: - Restore common/* and browser/* paths in addon src/test/benchmark tsconfigs - Revert addon imports to common/ and browser/ path-mapped specifiers - Restore NODE_PATH=out-esbuild in bin/test_unit.js for Mocha resolution - Restore webpack resolve.alias on addons that bundle against out/ Fixes CI test-unit failures on remove-path-mappings-5896. Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
/**
|
|
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
|
* @license MIT
|
|
*/
|
|
|
|
const cp = require('child_process');
|
|
const path = require('path');
|
|
|
|
const COVERAGE_LINES_THRESHOLD = 40;
|
|
|
|
// Add `out-esbuild` to NODE_PATH so addon path-mapped imports (common/*, browser/*) resolve.
|
|
const env = { ...process.env };
|
|
env.NODE_PATH = path.resolve(__dirname, '../out-esbuild');
|
|
|
|
let testFiles = ['**/out-esbuild/**/*.test.js'];
|
|
|
|
let flagArgs = [];
|
|
|
|
if (process.argv.length > 2) {
|
|
const args = process.argv.slice(2);
|
|
flagArgs = args.filter(e => e.startsWith('--'));
|
|
// ability to inject particular test files via
|
|
// npm run test [testFileA testFileB ...]
|
|
files = args.filter(e => !e.startsWith('--'));
|
|
if (files.length) {
|
|
testFiles = files;
|
|
}
|
|
}
|
|
|
|
const checkCoverage = flagArgs.indexOf('--coverage') >= 0;
|
|
if (checkCoverage) {
|
|
flagArgs.splice(flagArgs.indexOf('--coverage'), 1);
|
|
const executable = npmBinScript('nyc');
|
|
const args = [
|
|
'--check-coverage',
|
|
`--lines=${COVERAGE_LINES_THRESHOLD}`,
|
|
'--exclude=out-esbuild/vs/**',
|
|
npmBinScript('mocha'),
|
|
...testFiles,
|
|
...flagArgs
|
|
];
|
|
console.info('executable', executable);
|
|
console.info('args', args);
|
|
const run = cp.spawnSync(
|
|
executable,
|
|
args,
|
|
{
|
|
cwd: path.resolve(__dirname, '..'),
|
|
env,
|
|
shell: true,
|
|
stdio: 'inherit'
|
|
}
|
|
);
|
|
process.exit(run.status);
|
|
}
|
|
|
|
const run = cp.spawnSync(
|
|
npmBinScript('mocha'),
|
|
[...testFiles, ...flagArgs],
|
|
{
|
|
cwd: path.resolve(__dirname, '..'),
|
|
env,
|
|
shell: true,
|
|
stdio: 'inherit'
|
|
}
|
|
);
|
|
|
|
function npmBinScript(script) {
|
|
return path.resolve(__dirname, `../node_modules/.bin/` + (process.platform === 'win32' ? `${script}.cmd` : script));
|
|
}
|
|
|
|
if (run.error) {
|
|
console.error(run.error);
|
|
}
|
|
process.exit(run.status ?? -1);
|