Skip to content

Commit 05e5b64

Browse files
committed
(refactor): split build tests into separate files per fixture
- better organized that way as the tests are somewhat independent of one another and previously even I was confused where to put different types of tests - also refactor some test naming and some redundant usage of flags - especially for 0-config, where flags shouldn't be used - and remove testEnvironment comment as it's already set in jest config (optim): now that it's one fixture per file, we only need to copy the fixture directory once per file, which should be a speed boost - and sometimes may not need to re-run `tsdx build` when not necessary - also the different test files get parallelized, which is also faster - before: 53s avg on my machine, after: 37s avg on my machine - avg for running all tests - pretty BIG difference
1 parent 985a97b commit 05e5b64

File tree

4 files changed

+178
-164
lines changed

4 files changed

+178
-164
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const shell = require('shelljs');
2+
const util = require('../fixtures/util');
3+
4+
shell.config.silent = false;
5+
6+
const fixtureName = 'build-default';
7+
const stageName = `stage-${fixtureName}`;
8+
9+
describe('tsdx build :: zero-config defaults', () => {
10+
beforeAll(() => {
11+
util.teardownStage(stageName);
12+
util.setupStageWithFixture(stageName, fixtureName);
13+
});
14+
15+
it('should compile files into a dist directory', () => {
16+
const output = shell.exec('node ../dist/index.js build');
17+
18+
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
19+
expect(
20+
shell.test('-f', 'dist/build-default.cjs.development.js')
21+
).toBeTruthy();
22+
expect(
23+
shell.test('-f', 'dist/build-default.cjs.production.min.js')
24+
).toBeTruthy();
25+
expect(shell.test('-f', 'dist/build-default.esm.js')).toBeTruthy();
26+
27+
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();
28+
29+
expect(output.code).toBe(0);
30+
});
31+
32+
it('should create the library correctly', () => {
33+
const lib = require(`../../${stageName}/dist`);
34+
expect(lib.foo()).toBe('bar');
35+
expect(lib.__esModule).toBe(true);
36+
});
37+
38+
it('should clean the dist directory before rebuilding', () => {
39+
shell.mv('package.json', 'package-og.json');
40+
shell.mv('package2.json', 'package.json');
41+
42+
const output = shell.exec('node ../dist/index.js build');
43+
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
44+
45+
// build-default files have been cleaned out
46+
expect(
47+
shell.test('-f', 'dist/build-default.cjs.development.js')
48+
).toBeFalsy();
49+
expect(
50+
shell.test('-f', 'dist/build-default.cjs.production.min.js')
51+
).toBeFalsy();
52+
expect(shell.test('-f', 'dist/build-default.esm.js')).toBeFalsy();
53+
54+
// build-default-2 files have been added
55+
expect(
56+
shell.test('-f', 'dist/build-default-2.cjs.development.js')
57+
).toBeTruthy();
58+
expect(
59+
shell.test('-f', 'dist/build-default-2.cjs.production.min.js')
60+
).toBeTruthy();
61+
expect(shell.test('-f', 'dist/build-default-2.esm.js')).toBeTruthy();
62+
63+
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();
64+
65+
expect(output.code).toBe(0);
66+
67+
// reset package.json files
68+
shell.mv('package.json', 'package2.json');
69+
shell.mv('package-og.json', 'package.json');
70+
});
71+
72+
afterAll(() => {
73+
util.teardownStage(stageName);
74+
});
75+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const shell = require('shelljs');
2+
const util = require('../fixtures/util');
3+
4+
shell.config.silent = false;
5+
6+
const fixtureName = 'build-invalid';
7+
const stageName = `stage-${fixtureName}`;
8+
9+
describe('tsdx build :: invalid build', () => {
10+
beforeAll(() => {
11+
util.teardownStage(stageName);
12+
util.setupStageWithFixture(stageName, fixtureName);
13+
});
14+
15+
it('should fail gracefully with exit code 1 when build failed', () => {
16+
const code = shell.exec('node ../dist/index.js build').code;
17+
expect(code).toBe(1);
18+
});
19+
20+
it('should only transpile and not type check', () => {
21+
const code = shell.exec('node ../dist/index.js build --transpileOnly').code;
22+
23+
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
24+
expect(
25+
shell.test('-f', 'dist/build-invalid.cjs.development.js')
26+
).toBeTruthy();
27+
expect(
28+
shell.test('-f', 'dist/build-invalid.cjs.production.min.js')
29+
).toBeTruthy();
30+
expect(shell.test('-f', 'dist/build-invalid.esm.js')).toBeTruthy();
31+
32+
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();
33+
34+
expect(code).toBe(0);
35+
});
36+
37+
afterAll(() => {
38+
util.teardownStage(stageName);
39+
});
40+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const shell = require('shelljs');
2+
const util = require('../fixtures/util');
3+
4+
shell.config.silent = false;
5+
6+
const fixtureName = 'build-withTsconfig';
7+
const stageName = `stage-${fixtureName}`;
8+
9+
describe('tsdx build :: build with custom tsconfig.json options', () => {
10+
beforeAll(() => {
11+
util.teardownStage(stageName);
12+
util.setupStageWithFixture(stageName, fixtureName);
13+
});
14+
15+
it('should use the declarationDir when set', () => {
16+
const output = shell.exec('node ../dist/index.js build');
17+
18+
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
19+
expect(
20+
shell.test('-f', 'dist/build-withtsconfig.cjs.development.js')
21+
).toBeTruthy();
22+
expect(
23+
shell.test('-f', 'dist/build-withtsconfig.cjs.production.min.js')
24+
).toBeTruthy();
25+
expect(shell.test('-f', 'dist/build-withtsconfig.esm.js')).toBeTruthy();
26+
27+
expect(shell.test('-f', 'dist/index.d.ts')).toBeFalsy();
28+
expect(shell.test('-f', 'typings/index.d.ts')).toBeTruthy();
29+
expect(shell.test('-f', 'typings/index.d.ts.map')).toBeTruthy();
30+
31+
expect(output.code).toBe(0);
32+
});
33+
34+
it('should set __esModule according to esModuleInterop', () => {
35+
const lib = require(`../../${stageName}/dist/build-withtsconfig.cjs.production.min.js`);
36+
// if esModuleInterop: false, no __esModule is added, therefore undefined
37+
expect(lib.__esModule).toBe(undefined);
38+
});
39+
40+
it('should read custom --tsconfig path', () => {
41+
const output = shell.exec(
42+
'node ../dist/index.js build --format cjs --tsconfig ./src/tsconfig.json'
43+
);
44+
45+
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
46+
expect(
47+
shell.test('-f', 'dist/build-withtsconfig.cjs.development.js')
48+
).toBeTruthy();
49+
expect(
50+
shell.test('-f', 'dist/build-withtsconfig.cjs.production.min.js')
51+
).toBeTruthy();
52+
53+
expect(shell.test('-f', 'dist/index.d.ts')).toBeFalsy();
54+
expect(shell.test('-f', 'typingsCustom/index.d.ts')).toBeTruthy();
55+
expect(shell.test('-f', 'typingsCustom/index.d.ts.map')).toBeTruthy();
56+
57+
expect(output.code).toBe(0);
58+
});
59+
60+
afterAll(() => {
61+
util.teardownStage(stageName);
62+
});
63+
});

test/tests/tsdx-build.test.js

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)