- C1: 4 个 CLI 脚本守卫加 process.argv[1] 空值短路,避免动态 import 时 pathToFileURL(undefined) 崩溃 - I1: check-cocos-version CLI 在宿主 creator.version 为 null 时报错 exit 1,避免 CI 虚假 OK - M1: scaffold 测试收紧 UUID 正则 - 新增 cli-entry 测试覆盖动态 import 场景 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
20 lines
869 B
JavaScript
20 lines
869 B
JavaScript
import { test } from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { spawnSync } from 'node:child_process';
|
||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||
import { dirname, join } from 'node:path';
|
||
|
||
const scriptsDir = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||
const CLI = ['setup-links.mjs', 'new-game.mjs', 'check-cocos-version.mjs', 'bump-cocos.mjs'];
|
||
|
||
for (const name of CLI) {
|
||
test(`${name} 被动态 import 时不崩溃(argv[1] undefined)`, () => {
|
||
const url = pathToFileURL(join(scriptsDir, name)).href;
|
||
const r = spawnSync(process.execPath,
|
||
['--input-type=module', '-e', `import(${JSON.stringify(url)}).then(()=>process.exit(0))`],
|
||
{ encoding: 'utf8' });
|
||
assert.equal(r.status, 0, `stderr: ${r.stderr}`);
|
||
assert.ok(!/TypeError/.test(r.stderr), `不应出现 TypeError: ${r.stderr}`);
|
||
});
|
||
}
|