d0ef462921
验证:713 项单测、8 视口环境、代码及格式检查通过;未运行生产构建。
66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
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 });
|
|
}
|