-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(test): ensure --extractErrors kind of works
- the test output strips away `invariant` entirely in all builds, instead of replacing it with ErrorProd/ErrorDev etc... - it leaves an empty import however... - which gives an unused import warning during builds - and it doesn't do anything with `warning` at all, it doesn't get stripped or changed, and it's message is not in codes.json - the source code indeed only checks for 'invariant' - and it does generate errors/codes.json, ErrorProd.js, ErrorDev.js - I'm not 100% sure, but that seems to be buggy to me (refactor): split --extractError code into a build-options fixture - as it doesn't require tsdx.config.js at all - but it is an integration test, as it requires tiny-invariant etc (clean): remove the errors/ directory as that's auto-generated by --extractErrors and is the thing being tested (clean): remove src/foo.ts as it's extraneous
- Loading branch information
Showing
11 changed files
with
108 additions
and
33 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Integration Test Fixtures Directory | ||
|
||
- `build-options` lets us check that TSDX's flags work as expected | ||
- `build-withConfig` lets us check that `tsdx.config.js` works as expected |
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,7 @@ | ||
{ | ||
"scripts": { | ||
"build": "tsdx build --extractErrors" | ||
}, | ||
"name": "build-options", | ||
"license": "MIT" | ||
} |
12 changes: 12 additions & 0 deletions
12
test/integration-tests/fixtures/build-options/src/index.ts
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,12 @@ | ||
import invariant from 'tiny-invariant'; | ||
import warning from 'tiny-warning'; | ||
|
||
invariant(true, 'error occurred! o no'); | ||
warning(true, 'warning - water is wet'); | ||
|
||
export const sum = (a: number, b: number) => { | ||
if ('development' === process.env.NODE_ENV) { | ||
console.log('fuck'); | ||
} | ||
return a + b; | ||
}; |
28 changes: 28 additions & 0 deletions
28
test/integration-tests/fixtures/build-options/tsconfig.json
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,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"lib": ["dom", "esnext"], | ||
"declaration": true, | ||
"sourceMap": true, | ||
"rootDir": "./src", | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"strictPropertyInitialization": true, | ||
"noImplicitThis": true, | ||
"alwaysStrict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"moduleResolution": "node", | ||
"baseUrl": "./", | ||
"paths": { | ||
"*": ["src/*", "node_modules/*"] | ||
}, | ||
"jsx": "react", | ||
"esModuleInterop": true | ||
}, | ||
"include": ["src", "types"], | ||
} |
7 changes: 0 additions & 7 deletions
7
test/integration-tests/fixtures/build-withConfig/errors/ErrorDev.js
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
test/integration-tests/fixtures/build-withConfig/errors/ErrorProd.js
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
test/integration-tests/fixtures/build-withConfig/errors/codes.json
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
test/integration-tests/fixtures/build-withConfig/src/index.ts
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
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,59 @@ | ||
const shell = require('shelljs'); | ||
|
||
const util = require('../utils/fixture'); | ||
const { execWithCache } = require('../utils/shell'); | ||
|
||
shell.config.silent = false; | ||
|
||
const testDir = 'integration-tests'; | ||
const fixtureName = 'build-options'; | ||
const stageName = `stage-integration-${fixtureName}`; | ||
|
||
describe('integration :: tsdx build :: options', () => { | ||
beforeAll(() => { | ||
util.teardownStage(stageName); | ||
util.setupStageWithFixture(testDir, stageName, fixtureName); | ||
}); | ||
|
||
it('should create errors/ dir with --extractErrors', () => { | ||
const output = execWithCache('node ../dist/index.js build --extractErrors'); | ||
|
||
expect(shell.test('-f', 'errors/ErrorDev.js')).toBeTruthy(); | ||
expect(shell.test('-f', 'errors/ErrorProd.js')).toBeTruthy(); | ||
expect(shell.test('-f', 'errors/codes.json')).toBeTruthy(); | ||
|
||
expect(output.code).toBe(0); | ||
}); | ||
|
||
it('should have correct errors/codes.json', () => { | ||
const output = execWithCache('node ../dist/index.js build --extractErrors'); | ||
|
||
const errors = require(`../../${stageName}/errors/codes.json`); | ||
expect(errors['0']).toBe('error occurred! o no'); | ||
// TODO: warning is actually not extracted, only invariant | ||
// expect(errors['1']).toBe('warning - water is wet'); | ||
|
||
expect(output.code).toBe(0); | ||
}); | ||
|
||
it('should compile files into a dist directory', () => { | ||
const output = execWithCache('node ../dist/index.js build --extractErrors'); | ||
|
||
expect(shell.test('-f', 'dist/index.js')).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-options.cjs.development.js') | ||
).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-options.cjs.production.min.js') | ||
).toBeTruthy(); | ||
expect(shell.test('-f', 'dist/build-options.esm.js')).toBeTruthy(); | ||
|
||
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy(); | ||
|
||
expect(output.code).toBe(0); | ||
}); | ||
|
||
afterAll(() => { | ||
util.teardownStage(stageName); | ||
}); | ||
}); |