chore(tooling): 对齐协作规范与浏览器验收工具
验证:713 项单测、8 视口环境、代码及格式检查通过;未运行生产构建。
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
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 test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { createServer } from 'node:net';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { verifyBuild } from '../../scripts/verify-build.mjs';
|
||||
|
||||
test('static build validation rejects missing entry resources', async () => {
|
||||
const directory = await mkdtemp(path.join(tmpdir(), 'monkey-pw-preview-'));
|
||||
try {
|
||||
await assert.rejects(verifyBuild(directory), /ENOENT/);
|
||||
await writeFile(
|
||||
path.join(directory, 'index.html'),
|
||||
'<script src="/assets/app.js"></script>',
|
||||
);
|
||||
await assert.rejects(verifyBuild(directory), /ENOENT/);
|
||||
await mkdir(path.join(directory, 'assets'));
|
||||
await writeFile(path.join(directory, 'assets/app.js'), 'export {}');
|
||||
assert.equal((await verifyBuild(directory)).assets, 1);
|
||||
await writeFile(path.join(directory, 'logo.svg'), '<svg/>');
|
||||
await writeFile(
|
||||
path.join(directory, 'index.html'),
|
||||
'<link rel="icon" href="__WL_BRAND_FAVICON__"><script src="/assets/app.js"></script><script>const example = \'<img src="/not-a-build-resource.png">\'</script>',
|
||||
);
|
||||
assert.equal((await verifyBuild(directory)).assets, 2);
|
||||
await writeFile(
|
||||
path.join(directory, 'index.html'),
|
||||
'<script src="../outside.js"></script>',
|
||||
);
|
||||
await assert.rejects(verifyBuild(directory), /escapes output/);
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('preview refuses an occupied port instead of silently choosing the next port', async () => {
|
||||
const directory = await mkdtemp(path.join(tmpdir(), 'monkey-pw-preview-'));
|
||||
const blocker = createServer();
|
||||
try {
|
||||
await writeFile(
|
||||
path.join(directory, 'index.html'),
|
||||
'<script src="/app.js"></script>',
|
||||
);
|
||||
await writeFile(path.join(directory, 'app.js'), 'export {}');
|
||||
await new Promise((resolve) => blocker.listen(0, '127.0.0.1', resolve));
|
||||
const port = blocker.address().port;
|
||||
const result = await new Promise((resolve, reject) => {
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[
|
||||
fileURLToPath(
|
||||
new URL('../../scripts/preview-dist.mjs', import.meta.url),
|
||||
),
|
||||
'--port',
|
||||
String(port),
|
||||
],
|
||||
{
|
||||
cwd: fileURLToPath(new URL('../../', import.meta.url)),
|
||||
env: { ...process.env, PW_DIST_DIR: directory },
|
||||
windowsHide: true,
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
timeout: 20000,
|
||||
},
|
||||
);
|
||||
let output = '';
|
||||
child.stdout.on('data', (chunk) => {
|
||||
output += chunk;
|
||||
});
|
||||
child.stderr.on('data', (chunk) => {
|
||||
output += chunk;
|
||||
});
|
||||
child.on('error', reject);
|
||||
child.on('close', (code) => resolve({ code, output }));
|
||||
});
|
||||
assert.notEqual(result.code, 0);
|
||||
assert.match(result.output, /already in use/);
|
||||
} finally {
|
||||
await new Promise((resolve) => blocker.close(resolve));
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user