-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(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
- Loading branch information
Showing
4 changed files
with
178 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const shell = require('shelljs'); | ||
const util = require('../fixtures/util'); | ||
|
||
shell.config.silent = false; | ||
|
||
const fixtureName = 'build-default'; | ||
const stageName = `stage-${fixtureName}`; | ||
|
||
describe('tsdx build :: zero-config defaults', () => { | ||
beforeAll(() => { | ||
util.teardownStage(stageName); | ||
util.setupStageWithFixture(stageName, fixtureName); | ||
}); | ||
|
||
it('should compile files into a dist directory', () => { | ||
const output = shell.exec('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('should create the library correctly', () => { | ||
const lib = require(`../../${stageName}/dist`); | ||
expect(lib.foo()).toBe('bar'); | ||
expect(lib.__esModule).toBe(true); | ||
}); | ||
|
||
it('should clean the dist directory before rebuilding', () => { | ||
shell.mv('package.json', 'package-og.json'); | ||
shell.mv('package2.json', 'package.json'); | ||
|
||
const output = shell.exec('node ../dist/index.js build'); | ||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const shell = require('shelljs'); | ||
const util = require('../fixtures/util'); | ||
|
||
shell.config.silent = false; | ||
|
||
const fixtureName = 'build-invalid'; | ||
const stageName = `stage-${fixtureName}`; | ||
|
||
describe('tsdx build :: invalid build', () => { | ||
beforeAll(() => { | ||
util.teardownStage(stageName); | ||
util.setupStageWithFixture(stageName, fixtureName); | ||
}); | ||
|
||
it('should fail gracefully with exit code 1 when build failed', () => { | ||
const code = shell.exec('node ../dist/index.js build').code; | ||
expect(code).toBe(1); | ||
}); | ||
|
||
it('should only transpile and not type check', () => { | ||
const code = shell.exec('node ../dist/index.js build --transpileOnly').code; | ||
|
||
expect(shell.test('-f', 'dist/index.js')).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-invalid.cjs.development.js') | ||
).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-invalid.cjs.production.min.js') | ||
).toBeTruthy(); | ||
expect(shell.test('-f', 'dist/build-invalid.esm.js')).toBeTruthy(); | ||
|
||
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy(); | ||
|
||
expect(code).toBe(0); | ||
}); | ||
|
||
afterAll(() => { | ||
util.teardownStage(stageName); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const shell = require('shelljs'); | ||
const util = require('../fixtures/util'); | ||
|
||
shell.config.silent = false; | ||
|
||
const fixtureName = 'build-withTsconfig'; | ||
const stageName = `stage-${fixtureName}`; | ||
|
||
describe('tsdx build :: build with custom tsconfig.json options', () => { | ||
beforeAll(() => { | ||
util.teardownStage(stageName); | ||
util.setupStageWithFixture(stageName, fixtureName); | ||
}); | ||
|
||
it('should use the declarationDir when set', () => { | ||
const output = shell.exec('node ../dist/index.js build'); | ||
|
||
expect(shell.test('-f', 'dist/index.js')).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withtsconfig.cjs.development.js') | ||
).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withtsconfig.cjs.production.min.js') | ||
).toBeTruthy(); | ||
expect(shell.test('-f', 'dist/build-withtsconfig.esm.js')).toBeTruthy(); | ||
|
||
expect(shell.test('-f', 'dist/index.d.ts')).toBeFalsy(); | ||
expect(shell.test('-f', 'typings/index.d.ts')).toBeTruthy(); | ||
expect(shell.test('-f', 'typings/index.d.ts.map')).toBeTruthy(); | ||
|
||
expect(output.code).toBe(0); | ||
}); | ||
|
||
it('should set __esModule according to esModuleInterop', () => { | ||
const lib = require(`../../${stageName}/dist/build-withtsconfig.cjs.production.min.js`); | ||
// if esModuleInterop: false, no __esModule is added, therefore undefined | ||
expect(lib.__esModule).toBe(undefined); | ||
}); | ||
|
||
it('should read custom --tsconfig path', () => { | ||
const output = shell.exec( | ||
'node ../dist/index.js build --format cjs --tsconfig ./src/tsconfig.json' | ||
); | ||
|
||
expect(shell.test('-f', 'dist/index.js')).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withtsconfig.cjs.development.js') | ||
).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withtsconfig.cjs.production.min.js') | ||
).toBeTruthy(); | ||
|
||
expect(shell.test('-f', 'dist/index.d.ts')).toBeFalsy(); | ||
expect(shell.test('-f', 'typingsCustom/index.d.ts')).toBeTruthy(); | ||
expect(shell.test('-f', 'typingsCustom/index.d.ts.map')).toBeTruthy(); | ||
|
||
expect(output.code).toBe(0); | ||
}); | ||
|
||
afterAll(() => { | ||
util.teardownStage(stageName); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.