-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtransform-unit.test.ts
More file actions
67 lines (56 loc) · 2.05 KB
/
Copy pathtransform-unit.test.ts
File metadata and controls
67 lines (56 loc) · 2.05 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
import { mkdirSync, mkdtempSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { checkOverwrite, orderPackages, resolveOutBase } from '../src/commands/transform';
describe('resolveOutBase', () => {
it('defaults to the source module parent (packages land as siblings)', () => {
expect(resolveOutBase('/ws/my-mod')).toBe('/ws');
});
it('resolves --out when given', () => {
expect(resolveOutBase('/ws/my-mod', '/tmp/out')).toBe('/tmp/out');
});
});
describe('checkOverwrite', () => {
let dir: string;
beforeEach(() => {
dir = mkdtempSync(join(tmpdir(), 'pgpm-transform-guard-'));
});
afterEach(() => {
rmSync(dir, { recursive: true, force: true });
});
it('refuses to overwrite the source module without --write', () => {
const mod = join(dir, 'my-mod');
mkdirSync(mod);
expect(checkOverwrite(mod, mod, false)).toMatch(/source module/);
expect(checkOverwrite(mod, mod, true)).toBeNull();
});
it('refuses to clobber an existing output directory without --write', () => {
const mod = join(dir, 'my-mod');
const out = join(dir, 'my-mod-object');
mkdirSync(mod);
mkdirSync(out);
expect(checkOverwrite(out, mod, false)).toMatch(/already exists/);
expect(checkOverwrite(out, mod, true)).toBeNull();
});
it('allows a fresh output directory', () => {
const mod = join(dir, 'my-mod');
mkdirSync(mod);
expect(checkOverwrite(join(dir, 'fresh'), mod, false)).toBeNull();
});
});
describe('orderPackages', () => {
it('orders prerequisites before dependents', () => {
const ordered = orderPackages([
{ name: 'pkg-security', requires: ['pkg-app'], rows: [] },
{ name: 'pkg-app', requires: [], rows: [] }
]);
expect(ordered.map(p => p.name)).toEqual(['pkg-app', 'pkg-security']);
});
it('keeps independent packages in input order', () => {
const ordered = orderPackages([
{ name: 'a', requires: [], rows: [] },
{ name: 'b', requires: [], rows: [] }
]);
expect(ordered.map(p => p.name)).toEqual(['a', 'b']);
});
});