-
Notifications
You must be signed in to change notification settings - Fork 504
/
tsdx-build-default.test.ts
95 lines (72 loc) · 2.9 KB
/
tsdx-build-default.test.ts
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import * as shell from 'shelljs';
import * as util from '../utils/fixture';
import { execWithCache } from '../utils/shell';
shell.config.silent = false;
const testDir = 'e2e';
const fixtureName = 'build-default';
const stageName = `stage-${fixtureName}`;
describe('tsdx build :: zero-config defaults', () => {
beforeAll(() => {
util.teardownStage(stageName);
util.setupStageWithFixture(testDir, stageName, fixtureName);
});
it('should compile files into a dist directory', () => {
const output = execWithCache('node ../dist/index.js build');
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
shell.test('-f', 'dist/build-default.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-default.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-default.esm.js')).toBeTruthy();
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();
expect(output.code).toBe(0);
});
it("shouldn't compile files in test/ or types/", () => {
const output = execWithCache('node ../dist/index.js build');
expect(shell.test('-d', 'dist/test/')).toBeFalsy();
expect(shell.test('-d', 'dist/types/')).toBeFalsy();
expect(output.code).toBe(0);
});
it('should create the library correctly', () => {
const output = execWithCache('node ../dist/index.js build');
const lib = require(`../../${stageName}/dist`);
expect(lib.foo()).toBe('bar');
expect(lib.__esModule).toBe(true);
expect(output.code).toBe(0);
});
it('should clean the dist directory before rebuilding', () => {
let output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
shell.mv('package.json', 'package-og.json');
shell.mv('package2.json', 'package.json');
// cache bust because we want to re-run this command with new package.json
output = execWithCache('node ../dist/index.js build', { noCache: true });
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
// build-default files have been cleaned out
expect(
shell.test('-f', 'dist/build-default.cjs.development.js')
).toBeFalsy();
expect(
shell.test('-f', 'dist/build-default.cjs.production.min.js')
).toBeFalsy();
expect(shell.test('-f', 'dist/build-default.esm.js')).toBeFalsy();
// build-default-2 files have been added
expect(
shell.test('-f', 'dist/build-default-2.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-default-2.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-default-2.esm.js')).toBeTruthy();
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();
expect(output.code).toBe(0);
// reset package.json files
shell.mv('package.json', 'package2.json');
shell.mv('package-og.json', 'package.json');
});
afterAll(() => {
util.teardownStage(stageName);
});
});