Skip to content

Commit

Permalink
(test): ensure --extractErrors kind of works
Browse files Browse the repository at this point in the history
- 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
agilgur5 committed Mar 27, 2020
1 parent a43da8d commit 7617726
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 33 deletions.
1 change: 1 addition & 0 deletions test/integration-tests/fixtures/README.md
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
7 changes: 7 additions & 0 deletions test/integration-tests/fixtures/build-options/package.json
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 test/integration-tests/fixtures/build-options/src/index.ts
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 test/integration-tests/fixtures/build-options/tsconfig.json
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"],
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "tsdx build --extractErrors"
"build": "tsdx build"
},
"name": "build-withconfig",
"license": "MIT"
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions test/integration-tests/fixtures/build-withConfig/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import invariant from 'tiny-invariant';
import warning from 'tiny-warning';
invariant(true, 'error occurred! o no');
warning(false, 'warning - water is wet');
export { foo } from './foo';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
Expand Down
59 changes: 59 additions & 0 deletions test/integration-tests/tsdx-build-options.test.js
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);
});
});

0 comments on commit 7617726

Please sign in to comment.