Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { join } from 'node:path';
|
|
import { writeFileSync, mkdirSync } from 'node:fs';
|
|
import { makeTempMonorepo, makeGameProject, cleanup } from './helpers.mjs';
|
|
import { readCreatorVersion, listGameProjects } from '../lib/paths.mjs';
|
|
|
|
test('readCreatorVersion 读取 package.json 的 creator.version', () => {
|
|
const mono = makeTempMonorepo();
|
|
try {
|
|
assert.equal(readCreatorVersion(mono.host), '3.8.8');
|
|
} finally {
|
|
cleanup(mono.root);
|
|
}
|
|
});
|
|
|
|
test('readCreatorVersion 缺字段返回 null', () => {
|
|
const mono = makeTempMonorepo();
|
|
try {
|
|
const dir = makeGameProject(mono.games, 'nover');
|
|
// 覆写成无 creator 字段
|
|
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'nover' }));
|
|
assert.equal(readCreatorVersion(dir), null);
|
|
} finally {
|
|
cleanup(mono.root);
|
|
}
|
|
});
|
|
|
|
test('listGameProjects 只列出含 package.json 的子目录', () => {
|
|
const mono = makeTempMonorepo();
|
|
try {
|
|
makeGameProject(mono.games, 'doudizhu');
|
|
makeGameProject(mono.games, 'niuniu');
|
|
mkdirSync(join(mono.games, 'not-a-project')); // 无 package.json,应被忽略
|
|
const found = listGameProjects(mono.games).map((p) => p.split(/[\\/]/).pop()).sort();
|
|
assert.deepEqual(found, ['doudizhu', 'niuniu']);
|
|
} finally {
|
|
cleanup(mono.root);
|
|
}
|
|
});
|
|
|
|
test('listGameProjects 对不存在的目录返回空数组', () => {
|
|
assert.deepEqual(listGameProjects('/no/such/dir'), []);
|
|
});
|