Skip to content

Commit

Permalink
(fix): remove faulty tsconfig.json include of test dir
Browse files Browse the repository at this point in the history
- `include` means all files that should be compiled, and the test dir
  should definitely not be compiled
  - this was causing issues where declarations were being output into
    dist/ for all files in test/
    - that shouldn't happen and it means `build` was unnecessarily
      slowed down in order to process test/ files
    - default `exclude` that was added of *.spec/*.test files,
      originally for co-located tests, ended up making most test/ dir
      files excluded too, but not, say, test utils that don't have a
      .spec or .test suffix

- this was also causing errors with the `rootDir: './src'` change as
  the test/ dir is outside of the rootDir
  - problem wasn't the rootDir, but that the test/ dir shouldn't be
    compiled or processed in any way

(test): ensure test/*.test.ts and test/*.ts files are correctly
excluded and don't have declarations generated
- and that they don't error with rootDir: './src'

(test): ensure types/*.d.ts don't error with rootDir and don't have
declarations re-generated either
- n.b. tsc won't re-generate them either, they don't get copied to
  outDir, this isn't new or different behavior

(env/test): Jest shouldn't run / should ignore tests inside of fixtures
  • Loading branch information
agilgur5 committed Mar 27, 2020
1 parent 3cb3841 commit 5776f7f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ module.exports = {
testPathIgnorePatterns: [
'/node_modules/', // default
'<rootDir>/templates/', // don't run tests in the templates
'<rootDir>/test/.*/fixtures/', // don't run tests in fixtures
'<rootDir>/stage-.*/', // don't run tests in auto-generated (and auto-removed) test dirs
],
};
2 changes: 1 addition & 1 deletion templates/basic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src", "types", "test"],
"include": ["src", "types"],
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "esnext"],
Expand Down
2 changes: 1 addition & 1 deletion templates/react-with-storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src", "types", "test"],
"include": ["src", "types"],
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "esnext"],
Expand Down
2 changes: 1 addition & 1 deletion templates/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src", "types", "test"],
"include": ["src", "types"],
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "esnext"],
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/fixtures/build-default/test/some-test.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// this is to test .test/.spec files in the test/ dir are excluded

// and that rootDir: './src' doesn't error with test/ files
4 changes: 4 additions & 0 deletions test/e2e/fixtures/build-default/test/testUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// this is to test that test helper files in the test/ dir are excluded
// i.e. files in test/ that don't have a .spec/.test suffix

// and that rootDir: './src' doesn't error with test/ files
3 changes: 3 additions & 0 deletions test/e2e/fixtures/build-default/types/blar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// this is to test that rootDir: './src' doesn't error with types/ files

// and that declaration files aren't re-output in dist/
9 changes: 9 additions & 0 deletions test/e2e/tsdx-build-default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ describe('tsdx build :: zero-config defaults', () => {
expect(output.code).toBe(0);
});

it("shouldn't compile files in test/ or types/", () => {
const output = execWithCache('node ../dist/index.js build');

expect(shell.test('-f', 'dist/test/')).toBeFalsy();
expect(shell.test('-f', 'dist/types/')).toBeFalsy();

expect(output.code).toBe(0);
});

it('should create the library correctly', () => {
const output = execWithCache('node ../dist/index.js build');

Expand Down

0 comments on commit 5776f7f

Please sign in to comment.