import { test } from 'node:test'; import assert from 'node:assert/strict'; import { join } from 'node:path'; import { readFileSync, writeFileSync } from 'node:fs'; import { makeTempMonorepo, makeGameProject, cleanup } from './helpers.mjs'; import { bumpVersion } from '../bump-cocos.mjs'; test('bumpVersion 改写各工程 creator.version 并报告 from/to', () => { const mono = makeTempMonorepo(); try { const a = makeGameProject(mono.games, 'a', '3.8.8'); const changed = bumpVersion([mono.host, a], '3.8.9'); assert.equal(changed.length, 2); assert.equal(changed[1].from, '3.8.8'); assert.equal(changed[1].to, '3.8.9'); const pkgA = JSON.parse(readFileSync(join(a, 'package.json'), 'utf8')); assert.equal(pkgA.creator.version, '3.8.9'); const pkgHost = JSON.parse(readFileSync(join(mono.host, 'package.json'), 'utf8')); assert.equal(pkgHost.creator.version, '3.8.9'); } finally { cleanup(mono.root); } }); test('bumpVersion 对缺 creator 字段的工程补建后写入', () => { const mono = makeTempMonorepo(); try { const a = makeGameProject(mono.games, 'a', '3.8.8'); writeFileSync(join(a, 'package.json'), JSON.stringify({ name: 'a' })); bumpVersion([a], '3.8.9'); const pkgA = JSON.parse(readFileSync(join(a, 'package.json'), 'utf8')); assert.equal(pkgA.creator.version, '3.8.9'); } finally { cleanup(mono.root); } });