Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Integration Tests #627

Merged
merged 11 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
testEnvironment: 'node',
testMatch: [
'<rootDir>/**/*(*.)@(test).[tj]s?(x)'
],
testPathIgnorePatterns: [
'/node_modules/', // default
'<rootDir>/templates/' // don't run tests in the templates
]
}
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"prepare": "tsc -p tsconfig.json",
"build": "tsc -p tsconfig.json",
"lint": "yarn build && yarn lint:post-build",
"lint:post-build": "node dist/index.js lint src test --ignore-pattern 'test/tests/lint'",
"lint:post-build": "node dist/index.js lint src test --ignore-pattern 'test/e2e/fixtures/lint'",
"test": "yarn build && yarn test:post-build",
"test:post-build": "node dist/index.js test --config ./test/jest.config.json",
"test:post-build": "node dist/index.js test",
"start": "tsc -p tsconfig.json --watch",
"release": "np"
},
Expand Down Expand Up @@ -106,19 +106,27 @@
"@types/ms": "^0.7.30",
"@types/node": "^13.1.0",
"@types/ora": "^3.2.0",
"@types/ps-tree": "^1.1.0",
"@types/react": "^16.9.11",
"@types/rollup-plugin-json": "^3.0.2",
"@types/rollup-plugin-sourcemaps": "^0.4.2",
"@types/sade": "^1.6.0",
"@types/semver": "^7.1.0",
"@types/styled-components": "^5.0.1",
"autoprefixer": "^9.7.4",
"babel-plugin-replace-identifiers": "^0.1.1",
"cssnano": "^4.1.10",
"doctoc": "^1.4.0",
"husky": "^4.2.2",
"np": "^6.2.0",
"pretty-quick": "^2.0.0",
"ps-tree": "^1.2.0",
"react": "^16.8.6",
"semver": "^7.1.1"
"react-dom": "^16.13.0",
"react-is": "^16.13.0",
"rollup-plugin-postcss": "^2.5.0",
"semver": "^7.1.1",
"styled-components": "^5.0.1",
"tiny-invariant": "^1.1.0",
"tiny-warning": "^1.0.3"
},
"husky": {
"hooks": {
Expand Down
7 changes: 7 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Tests

There are two main directories here:

- `unit` contains unit tests of internals
- `e2e` contains end-to-end (E2E) tests of the CLI
- `integration` contains tests ensuring that common or recommended plugins work properly together with TSDX
6 changes: 2 additions & 4 deletions test/fixtures/README.md → test/e2e/fixtures/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
## Fixtures testing

here are some fixtures for manual testing things we don't have Jest tests for.
# E2E Test Fixtures Directory

- `build-default` focuses on our zero config defaults
- `build-invalid` lets us check what happens when we have invalid builds due to type errors
- `build-withConfig` lets us check that `tsdx.config.js` works as expected
- `build-withTsconfig` lets us check that `tsconfig.json` options are correctly used
- `lint` lets us check that lint errors are correctly detected
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const shell = require('shelljs');
const util = require('../fixtures/util');
const util = require('../utils/fixture');
const { execWithCache } = require('../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(stageName, fixtureName);
util.setupStageWithFixture(testDir, stageName, fixtureName);
});

it('should compile files into a dist directory', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const shell = require('shelljs');
const util = require('../fixtures/util');
const util = require('../utils/fixture');
const { execWithCache } = require('../utils/shell');

shell.config.silent = false;

const testDir = 'e2e';
const fixtureName = 'build-invalid';
const stageName = `stage-${fixtureName}`;

describe('tsdx build :: invalid build', () => {
beforeAll(() => {
util.teardownStage(stageName);
util.setupStageWithFixture(stageName, fixtureName);
util.setupStageWithFixture(testDir, stageName, fixtureName);
});

it('should fail gracefully with exit code 1 when build failed', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const shell = require('shelljs');
const util = require('../fixtures/util');
const util = require('../utils/fixture');
const { execWithCache } = require('../utils/shell');

shell.config.silent = false;

const testDir = 'e2e';
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);
util.setupStageWithFixture(testDir, stageName, fixtureName);
});

it('should use the declarationDir when set', () => {
Expand Down
23 changes: 11 additions & 12 deletions test/tests/lint/tsdx-lint.test.js → test/e2e/tsdx-lint.test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
/**
* @jest-environment node
*/
'use strict';

const shell = require('shelljs');
const util = require('../../fixtures/util');

const util = require('../utils/fixture');

shell.config.silent = true;

const testDir = 'e2e';
const stageName = 'stage-lint';

const lintDir = `test/${testDir}/fixtures/lint`;

describe('tsdx lint', () => {
it('should fail to lint a ts file with errors', () => {
const testFile = 'test/tests/lint/file-with-lint-errors.ts';
const testFile = `${lintDir}/file-with-lint-errors.ts`;
const output = shell.exec(`node dist/index.js lint ${testFile}`);
expect(output.code).toBe(1);
expect(output.stdout.includes('Parsing error:')).toBe(true);
});

it('should succeed linting a ts file without errors', () => {
const testFile = 'test/tests/lint/file-without-lint-error.ts';
const testFile = `${lintDir}/file-without-lint-error.ts`;
const output = shell.exec(`node dist/index.js lint ${testFile}`);
expect(output.code).toBe(0);
});

it('should fail to lint a ts file with prettier errors', () => {
const testFile = 'test/tests/lint/file-with-prettier-lint-errors.ts';
const testFile = `${lintDir}/file-with-prettier-lint-errors.ts`;
const output = shell.exec(`node dist/index.js lint ${testFile}`);
expect(output.code).toBe(1);
expect(output.stdout.includes('prettier/prettier')).toBe(true);
});

it('should fail to lint a tsx file with errors', () => {
const testFile = 'test/tests/lint/react-file-with-lint-errors.tsx';
const testFile = `${lintDir}/react-file-with-lint-errors.tsx`;
const output = shell.exec(`node dist/index.js lint ${testFile}`);
expect(output.code).toBe(1);
expect(output.stdout.includes('Parsing error:')).toBe(true);
});

it('should succeed linting a tsx file without errors', () => {
const testFile = 'test/tests/lint/react-file-without-lint-error.tsx';
const testFile = `${lintDir}/react-file-without-lint-error.tsx`;
const output = shell.exec(`node dist/index.js lint ${testFile}`);
expect(output.code).toBe(0);
});
Expand All @@ -56,7 +55,7 @@ describe('tsdx lint', () => {
describe('when --write-file is used', () => {
beforeEach(() => {
util.teardownStage(stageName);
util.setupStageWithFixture(stageName, 'build-default');
util.setupStageWithFixture(testDir, stageName, 'build-default');
});

it('should create the file', () => {
Expand Down
7 changes: 0 additions & 7 deletions test/fixtures/build-withConfig/errors/ErrorDev.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/fixtures/build-withConfig/errors/ErrorProd.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/fixtures/build-withConfig/errors/codes.json

This file was deleted.

17 changes: 0 additions & 17 deletions test/fixtures/build-withConfig/package.json

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/build-withConfig/src/foo.ts

This file was deleted.

Loading