qwen-code/scripts/tests/clean-package-build-artifacts.test.js
易良 6d966d2917
test(core): stabilize file history eviction test (#6637)
* test(core): stabilize file history eviction test

* ci: clean package build artifacts before fast-path check

* ci: preserve web build outputs during fast-path check
2026-07-10 06:39:52 +00:00

68 lines
2 KiB
JavaScript

/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, expect, it } from 'vitest';
import {
existsSync,
mkdirSync,
mkdtempSync,
rmSync,
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { cleanPackageBuildArtifacts } from '../clean-package-build-artifacts.js';
describe('clean package build artifacts', () => {
it('removes CLI package outputs without deleting dependencies or web package outputs', () => {
const tempDir = mkdtempSync(join(tmpdir(), 'clean-build-artifacts-'));
try {
writeFileSync(
join(tempDir, 'package.json'),
JSON.stringify({ workspaces: ['packages/*'] }),
);
mkdirSync(join(tempDir, 'packages', 'core', 'dist'), {
recursive: true,
});
mkdirSync(join(tempDir, 'packages', 'web-shell', 'dist'), {
recursive: true,
});
mkdirSync(join(tempDir, 'packages', 'core', 'node_modules', 'dep'), {
recursive: true,
});
writeFileSync(join(tempDir, 'packages', 'core', 'package.json'), '{}');
writeFileSync(
join(tempDir, 'packages', 'web-shell', 'package.json'),
'{}',
);
writeFileSync(join(tempDir, 'packages', 'core', 'dist', 'index.js'), '');
writeFileSync(
join(tempDir, 'packages', 'web-shell', 'dist', 'index.js'),
'',
);
writeFileSync(
join(tempDir, 'packages', 'core', 'tsconfig.tsbuildinfo'),
'',
);
cleanPackageBuildArtifacts({ root: tempDir });
expect(existsSync(join(tempDir, 'packages', 'core', 'dist'))).toBe(false);
expect(
existsSync(join(tempDir, 'packages', 'web-shell', 'dist', 'index.js')),
).toBe(true);
expect(
existsSync(join(tempDir, 'packages', 'core', 'tsconfig.tsbuildinfo')),
).toBe(false);
expect(
existsSync(join(tempDir, 'packages', 'core', 'node_modules', 'dep')),
).toBe(true);
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
});