-
Notifications
You must be signed in to change notification settings - Fork 509
/
Copy pathtsdx-build-default.test.ts
134 lines (102 loc) · 4.29 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import * as shell from 'shelljs';
import * as util from '../utils/fixture';
import { execWithCache, grep } 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', async () => {
const output = execWithCache('node ../dist/index.js build');
const lib = require(`../../${stageName}/dist`);
expect(lib.returnsTrue()).toBe(true);
expect(lib.__esModule).toBe(true); // test that ESM -> CJS interop was output
// syntax tests
expect(lib.testNullishCoalescing()).toBe(true);
expect(lib.testOptionalChaining()).toBe(true);
// can't use an async generator in Jest yet, so use next().value instead of yield
expect(lib.testGenerator().next().value).toBe(true);
expect(await lib.testAsync()).toBe(true);
expect(output.code).toBe(0);
});
it('should bundle regeneratorRuntime', () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
const matched = grep(/regeneratorRuntime = r/, ['dist/build-default.*.js']);
expect(matched).toBeTruthy();
});
it('should use lodash for the CJS build', () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
const matched = grep(/lodash/, ['dist/build-default.cjs.*.js']);
expect(matched).toBeTruthy();
});
it('should use lodash-es for the ESM build', () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
const matched = grep(/lodash-es/, ['dist/build-default.esm.js']);
expect(matched).toBeTruthy();
});
it("shouldn't replace lodash/fp", () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
const matched = grep(/lodash\/fp/, ['dist/build-default.*.js']);
expect(matched).toBeTruthy();
});
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);
});
});