-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbundles.ts
More file actions
62 lines (49 loc) · 1.85 KB
/
Copy pathbundles.ts
File metadata and controls
62 lines (49 loc) · 1.85 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
import { mkdir } from 'fs/promises';
import { glob } from 'glob';
import { tmpdir } from 'os';
import { resolve, join, basename, format } from 'path';
import { cp } from '../src/file.ts';
export const validTestBundleNames = ['sample-vat', 'sample-vat-esp'];
export const invalidTestBundleNames = ['bad-vat.fails'];
const testRoot = new URL('.', import.meta.url).pathname;
const makeTestBundleRoot = async () => {
const stageRoot = resolve(tmpdir(), 'test');
// copy bundle targets to staging area
const testBundleRoot = resolve(testRoot, 'bundles');
const stageBundleRoot = resolve(stageRoot, 'bundles');
await mkdir(stageBundleRoot, { recursive: true });
const ext = '.js';
await Promise.all(
(await glob(join(testBundleRoot, `*${ext}`))).map(async (filePath) => {
const name = basename(filePath, ext);
await cp(filePath, format({ dir: stageBundleRoot, name, ext }));
}),
);
await cp(join(testRoot, 'test.bundle'), join(stageRoot, 'test.bundle'));
// return the staging area, ready for testing
return stageBundleRoot;
};
export const makeTestBundleStage = async () => {
const stageBundleRoot = await makeTestBundleRoot();
const resolveBundlePath = (bundleName: string): string => {
return join(stageBundleRoot, `${bundleName}.bundle`);
};
const resolveSourcePath = (bundleName: string): string => {
return join(stageBundleRoot, `${bundleName}.js`);
};
const getTestBundleSpecs = (testBundleNames: string[]) =>
testBundleNames.map((bundleName) => ({
name: bundleName,
source: resolveSourcePath(bundleName),
bundle: resolveBundlePath(bundleName),
}));
const globBundles = async (): Promise<string[]> =>
await glob(join(stageBundleRoot, '*.bundle'));
return {
testBundleRoot: stageBundleRoot,
getTestBundleSpecs,
resolveBundlePath,
resolveSourcePath,
globBundles,
};
};