fix: harden backend stability and test production utilities
This commit is contained in:
31
backend/tests/archive-tests.js
Normal file
31
backend/tests/archive-tests.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const assert = require('assert');
|
||||
const { PassThrough } = require('stream');
|
||||
const { finished } = require('stream/promises');
|
||||
const { createZipArchive } = require('../utils/archive');
|
||||
|
||||
async function run() {
|
||||
const archive = await createZipArchive({ store: true });
|
||||
const output = new PassThrough();
|
||||
const chunks = [];
|
||||
output.on('data', (chunk) => chunks.push(chunk));
|
||||
archive.pipe(output);
|
||||
archive.append(Buffer.from('wanwanyun archive smoke test'), { name: 'smoke.txt' });
|
||||
|
||||
await archive.finalize();
|
||||
await finished(output);
|
||||
|
||||
const zip = Buffer.concat(chunks);
|
||||
assert.ok(zip.length > 30, 'ZIP output should not be empty');
|
||||
assert.strictEqual(zip.subarray(0, 2).toString('ascii'), 'PK');
|
||||
assert.ok(zip.includes(Buffer.from('smoke.txt')), 'ZIP should contain the requested entry');
|
||||
|
||||
console.log('通过: 1');
|
||||
console.log('失败: 0');
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error(error.stack || error.message);
|
||||
console.log('通过: 0');
|
||||
console.log('失败: 1');
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user