From 2195e90ba4ea3b695fdfa253c4c17fdc2e491a36 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 27 Mar 2020 03:09:17 -0400 Subject: [PATCH] (fix): remove faulty tsconfig.json include of test dir - `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 - add a note about this to the moveTypes() deprecation warning (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 --- jest.config.js | 2 ++ src/deprecated.ts | 4 +++- templates/basic/tsconfig.json | 2 +- templates/react-with-storybook/tsconfig.json | 2 +- templates/react/tsconfig.json | 2 +- test/e2e/fixtures/build-default/test/some-test.test.ts | 3 +++ test/e2e/fixtures/build-default/test/testUtil.ts | 4 ++++ test/e2e/fixtures/build-default/types/blar.d.ts | 3 +++ test/e2e/tsdx-build-default.test.js | 9 +++++++++ 9 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 test/e2e/fixtures/build-default/test/some-test.test.ts create mode 100644 test/e2e/fixtures/build-default/test/testUtil.ts create mode 100644 test/e2e/fixtures/build-default/types/blar.d.ts diff --git a/jest.config.js b/jest.config.js index 8a1e80a66..c39fb5316 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,5 +4,7 @@ module.exports = { testPathIgnorePatterns: [ '/node_modules/', // default '/templates/', // don't run tests in the templates + '/test/.*/fixtures/', // don't run tests in fixtures + '/stage-.*/', // don't run tests in auto-generated (and auto-removed) test dirs ], }; diff --git a/src/deprecated.ts b/src/deprecated.ts index 1eb9cc550..275caadb8 100644 --- a/src/deprecated.ts +++ b/src/deprecated.ts @@ -22,7 +22,9 @@ export async function moveTypes() { 'rootDir to "./src".\n' + 'TSDX has deprecated setting tsconfig.compilerOptions.rootDir to ' + '"./" as it caused buggy output for declarationMaps and occassionally ' + - 'for type declarations themselves.' + 'for type declarations themselves.\n' + + 'You may also need to change your include to remove "test", which also ' + + 'caused declarations to be unnecessarily created for test files.' ); try { diff --git a/templates/basic/tsconfig.json b/templates/basic/tsconfig.json index a63b7e132..a502b91b6 100644 --- a/templates/basic/tsconfig.json +++ b/templates/basic/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src", "types", "test"], + "include": ["src", "types"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], diff --git a/templates/react-with-storybook/tsconfig.json b/templates/react-with-storybook/tsconfig.json index e0b677e59..06ffbb74c 100644 --- a/templates/react-with-storybook/tsconfig.json +++ b/templates/react-with-storybook/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src", "types", "test"], + "include": ["src", "types"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], diff --git a/templates/react/tsconfig.json b/templates/react/tsconfig.json index a63b7e132..a502b91b6 100644 --- a/templates/react/tsconfig.json +++ b/templates/react/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src", "types", "test"], + "include": ["src", "types"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], diff --git a/test/e2e/fixtures/build-default/test/some-test.test.ts b/test/e2e/fixtures/build-default/test/some-test.test.ts new file mode 100644 index 000000000..0a394b564 --- /dev/null +++ b/test/e2e/fixtures/build-default/test/some-test.test.ts @@ -0,0 +1,3 @@ +// this is to test that .test/.spec files in the test/ dir are excluded + +// and that rootDir: './src' doesn't error with test/ files diff --git a/test/e2e/fixtures/build-default/test/testUtil.ts b/test/e2e/fixtures/build-default/test/testUtil.ts new file mode 100644 index 000000000..d5c76f081 --- /dev/null +++ b/test/e2e/fixtures/build-default/test/testUtil.ts @@ -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 diff --git a/test/e2e/fixtures/build-default/types/blar.d.ts b/test/e2e/fixtures/build-default/types/blar.d.ts new file mode 100644 index 000000000..a93bfc167 --- /dev/null +++ b/test/e2e/fixtures/build-default/types/blar.d.ts @@ -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/ diff --git a/test/e2e/tsdx-build-default.test.js b/test/e2e/tsdx-build-default.test.js index 7ce8bca5d..5a1c0f527 100644 --- a/test/e2e/tsdx-build-default.test.js +++ b/test/e2e/tsdx-build-default.test.js @@ -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('-d', 'dist/test/')).toBeFalsy(); + expect(shell.test('-d', 'dist/types/')).toBeFalsy(); + + expect(output.code).toBe(0); + }); + it('should create the library correctly', () => { const output = execWithCache('node ../dist/index.js build');