Repository navigation
Expand file tree
/
Copy pathworkerAsync.test.ts
More file actions
55 lines (46 loc) · 1.89 KB
/
Copy pathworkerAsync.test.ts
File metadata and controls
55 lines (46 loc) · 1.89 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
// 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 { unpackWorkerAsync } from '../unpackWorkerAsync';
import { packWorkerAsync } from '../packWorkerAsync';
import { getDemoDataDirectoryDisposable } from './testUtils';
describe('zipSyncWorkerAsync tests', () => {
it('basic pack test', async () => {
using demoDataDisposable = getDemoDataDirectoryDisposable(5);
const { targetDirectories, baseDir, metadata } = demoDataDisposable;
const archivePath: string = path.join(baseDir, 'archive.zip');
const { zipSyncReturn: packResult } = await packWorkerAsync({
compression: 'deflate',
baseDir,
targetDirectories,
archivePath
});
expect(packResult).toMatchObject({ filesPacked: 21, metadata });
using unpackDemoDataDisposable = getDemoDataDirectoryDisposable(2);
const { baseDir: unpackBaseDir } = unpackDemoDataDisposable;
const { zipSyncReturn: unpackResult } = await unpackWorkerAsync({
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' })
);
}
}
});
});