Repository navigation
Expand file tree
/
Copy pathindex.test.ts
More file actions
75 lines (63 loc) · 2.64 KB
/
Copy pathindex.test.ts
File metadata and controls
75 lines (63 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'node:path';
import * as fs from 'node:fs';
import { NoOpTerminalProvider } from '@rushstack/terminal/lib/NoOpTerminalProvider';
import { Terminal } from '@rushstack/terminal/lib/Terminal';
import { pack } from '../pack';
import { unpack } from '../unpack';
import { getDemoDataDirectoryDisposable } from './testUtils';
import type { ZipSyncOptionCompression } from '../zipSyncUtils';
describe('zipSync tests', () => {
it(`basic pack test`, () => {
const compressionOptions = ['store', 'deflate', 'zstd', 'auto'] satisfies ZipSyncOptionCompression[];
compressionOptions.forEach((compression) => {
if (compression === 'zstd') {
const [major, minor] = process.versions.node.split('.').map((x) => parseInt(x, 10));
if (major < 22 || (major === 22 && minor < 15)) {
// eslint-disable-next-line no-console
console.warn(`Skipping zstd test on Node ${process.versions.node}`);
return;
}
}
using demoDataDisposable = getDemoDataDirectoryDisposable(5);
const { targetDirectories, baseDir, metadata } = demoDataDisposable;
const terminal = new Terminal(new NoOpTerminalProvider());
const archivePath: string = path.join(baseDir, 'archive.zip');
const packResult = pack({
terminal: terminal,
compression,
baseDir,
targetDirectories,
archivePath
});
expect(packResult).toMatchObject({ filesPacked: 21, metadata });
using unpackDemoDataDisposable = getDemoDataDirectoryDisposable(2);
const { baseDir: unpackBaseDir } = unpackDemoDataDisposable;
const unpackResult = unpack({
terminal: terminal,
archivePath,
baseDir: unpackBaseDir,
targetDirectories
});
expect(unpackResult).toMatchObject({
filesDeleted: 0,
filesExtracted: 12,
filesSkipped: 8,
foldersDeleted: 0,
metadata
});
// Verify files were extracted
for (const targetDirectory of targetDirectories) {
const sourceDir: string = path.join(baseDir, targetDirectory);
for (let i: number = 0; i < 5; ++i) {
const sourceFile: string = path.join(sourceDir, 'subdir', `file-${i}.txt`);
const destFile: string = path.join(unpackBaseDir, targetDirectory, 'subdir', `file-${i}.txt`);
expect(fs.readFileSync(destFile, { encoding: 'utf-8' })).toEqual(
fs.readFileSync(sourceFile, { encoding: 'utf-8' })
);
}
}
});
});
});