8a48765a46
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import { mkdtemp, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { spawn } from 'node:child_process';
|
|
import { verifyBuild } from './verify-build.mjs';
|
|
|
|
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
const directory = await mkdtemp(path.join(tmpdir(), 'monkey-pw-build-'));
|
|
const env = {
|
|
...process.env,
|
|
PW_TARGET: 'local-dist',
|
|
PW_BASE_URL: 'http://127.0.0.1:4176/',
|
|
PW_REQUIRE_ALL: '1',
|
|
PW_DIST_DIR: directory,
|
|
};
|
|
function run(script, args) {
|
|
return new Promise((resolve, reject) => {
|
|
const child = spawn(process.execPath, [script, ...args], {
|
|
cwd: root,
|
|
stdio: 'inherit',
|
|
env,
|
|
});
|
|
child.on('error', reject);
|
|
child.on('exit', (code) =>
|
|
code === 0
|
|
? resolve()
|
|
: reject(new Error(`${path.basename(script)} failed (${code})`)),
|
|
);
|
|
});
|
|
}
|
|
try {
|
|
await run(path.join(root, 'node_modules/vite/bin/vite.js'), [
|
|
'build',
|
|
'--outDir',
|
|
directory,
|
|
'--emptyOutDir',
|
|
]);
|
|
await verifyBuild(directory);
|
|
await run(path.join(root, 'node_modules/@playwright/test/cli.js'), [
|
|
'test',
|
|
...process.argv.slice(2),
|
|
]);
|
|
} finally {
|
|
await rm(directory, { recursive: true, force: true });
|
|
}
|