32 lines
1015 B
JavaScript
32 lines
1015 B
JavaScript
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);
|
|
});
|