27 lines
1.6 KiB
JavaScript
27 lines
1.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { randomBytes } from 'node:crypto';
|
|
import { fixture } from './helpers.mjs';
|
|
import { copyReleaseTree } from '../scripts/release-copy.mjs';
|
|
|
|
test('fresh parallel release copies preserve all binary and Unicode bytes and empty directories', t => {
|
|
const f = fixture(t), source = path.join(f.root, 'source'), target = path.join(f.root, 'copied');
|
|
fs.mkdirSync(path.join(source, '中文', 'empty'), { recursive: true });
|
|
const files = { 'original.bin': randomBytes(8193), '中文/原件.txt': Buffer.from('\ufeff原始失败\r\n原始成功\r\n') };
|
|
for (const [relative, bytes] of Object.entries(files)) fs.writeFileSync(path.join(source, relative), bytes);
|
|
copyReleaseTree(source, target);
|
|
for (const [relative, bytes] of Object.entries(files)) assert.deepEqual(fs.readFileSync(path.join(target, relative)), bytes);
|
|
assert.deepEqual(fs.readdirSync(path.join(target, '中文', 'empty')), []);
|
|
fs.writeFileSync(path.join(source, 'original.bin'), 'changed'); copyReleaseTree(source, target);
|
|
assert.equal(fs.readFileSync(path.join(target, 'original.bin'), 'utf8'), 'changed');
|
|
});
|
|
|
|
test('Windows parallel release copy rejects junctions before creating a candidate', { skip: process.platform !== 'win32' }, t => {
|
|
const f = fixture(t), source = path.join(f.root, 'source'), target = path.join(f.root, 'copied');
|
|
fs.mkdirSync(source); fs.symlinkSync(f.projectRoot, path.join(source, 'external'), 'junction');
|
|
assert.throws(() => copyReleaseTree(source, target), /regular files|links/);
|
|
assert.equal(fs.existsSync(target), false);
|
|
});
|