From 8a29aaa3b1f30cd51cd2507f236b314a966baa29 Mon Sep 17 00:00:00 2001 From: Ahn Date: Thu, 7 May 2020 11:23:17 +0200 Subject: [PATCH] fix(config): don't set include to empty array (#1606) --- CHANGELOG.md | 2 +- docs/user/config/isolatedModules.md | 28 ++++++++++++ .../custom-typings/tsconfig.json | 5 +-- src/config/config-set.spec.ts | 45 ++----------------- src/config/config-set.ts | 7 +-- 5 files changed, 34 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88625c996c..fbe382aba1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ For example: { // ...other configs "files": [ - "my-custom-typings.d.ts". + "my-custom-typings.d.ts", "my-global-module.ts" ] } diff --git a/docs/user/config/isolatedModules.md b/docs/user/config/isolatedModules.md index 733c59fa04..194f1a9ad4 100644 --- a/docs/user/config/isolatedModules.md +++ b/docs/user/config/isolatedModules.md @@ -43,3 +43,31 @@ module.exports = { ``` + +# Performance + +Using `isolatedModules: false` comes with a cost of performance comparing to `isolatedModules: true`. There is a way +to improve the performance when using this mode by changing the value of `include` in `tsconfig` which is used by `ts-jest`. +The least amount of files which are provided in `include`, the more performance the test run can gain. + +### Example + +```json5 +// tsconfig.json +{ + // ...other configs + include: [ + "my-typings/*", + "my-global-modules/*", + ] +} +``` + +## Caveats + +Limiting the amount of files loaded via `include` can greatly boost performance when running tests. However, the trade off +is `ts-jest` might not recognize all files which are intended to use with `jest`. One can run into issues with custom typings, +global modules, etc... + +The suggested solution is what is needed for the test environment should be captured by +glob patterns in `include`, to gain both performance boost and avoid breaking behaviors. diff --git a/e2e/__external-repos__/custom-typings/tsconfig.json b/e2e/__external-repos__/custom-typings/tsconfig.json index ea489cdd6f..07db1ee948 100644 --- a/e2e/__external-repos__/custom-typings/tsconfig.json +++ b/e2e/__external-repos__/custom-typings/tsconfig.json @@ -3,8 +3,5 @@ "target": "es5", "module": "commonjs", "esModuleInterop": true - }, - "files": [ - "jquery.d.ts" - ] + } } diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index daced3bf96..583b781358 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -468,8 +468,9 @@ describe('typescript', () => { createConfigSet({ tsJestConfig: tsJest, parentConfig }).parsedTsConfig it('should read file list from default tsconfig', () => { - // since the default is to lookup for tsconfig, but we set include to [] so we should not have this file in the list - expect(get().fileNames).toEqual([]) + // since the default is to lookup for tsconfig, + // we should have this file in the list + expect(get().fileNames).toContain(normalizeSlashes(__filename)) }) it.each(['tsConfig', 'tsconfig'])('should include compiler config from `%s` option key', (key: string) => { @@ -610,11 +611,6 @@ describe('readTsConfig', () => { const conf = cs.readTsConfig() expect(conf.options.configFilePath).toBeUndefined() expect(readConfig).not.toHaveBeenCalled() - expect(parseConfig.mock.calls[0][0]).toEqual( - expect.objectContaining({ - include: [], - }), - ) expect(parseConfig.mock.calls[0][2]).toBe('/root') expect(parseConfig.mock.calls[0][4]).toBeUndefined() }) @@ -661,11 +657,6 @@ describe('readTsConfig', () => { expect(conf.options.path).toBe('/root/tsconfig.json') expect(findConfig.mock.calls[0][0]).toBe('/root') expect(readConfig.mock.calls[0][0]).toBe('/root/tsconfig.json') - expect(parseConfig.mock.calls[0][0]).toEqual( - expect.objectContaining({ - include: [], - }), - ) expect(parseConfig.mock.calls[0][2]).toBe('/root') expect(parseConfig.mock.calls[0][4]).toBe('/root/tsconfig.json') expect(conf.options.allowSyntheticDefaultImports).toEqual(true) @@ -677,11 +668,6 @@ describe('readTsConfig', () => { expect(conf.options.path).toBe('/foo/tsconfig.bar.json') expect(findConfig).not.toBeCalled() expect(readConfig.mock.calls[0][0]).toBe('/foo/tsconfig.bar.json') - expect(parseConfig.mock.calls[0][0]).toEqual( - expect.objectContaining({ - include: [], - }), - ) expect(parseConfig.mock.calls[0][2]).toBe('/foo') expect(parseConfig.mock.calls[0][4]).toBe('/foo/tsconfig.bar.json') expect(conf.errors).toMatchSnapshot() @@ -710,11 +696,6 @@ describe('readTsConfig', () => { expect(conf.options.path).toBe('/root/tsconfig.json') expect(findConfig.mock.calls[0][0]).toBe('/root') expect(readConfig.mock.calls[0][0]).toBe('/root/tsconfig.json') - expect(parseConfig.mock.calls[0][0]).toEqual( - expect.objectContaining({ - include: [], - }), - ) expect(parseConfig.mock.calls[0][2]).toBe('/root') expect(parseConfig.mock.calls[0][4]).toBe('/root/tsconfig.json') expect(conf.options.allowSyntheticDefaultImports).toEqual(true) @@ -754,11 +735,6 @@ describe('readTsConfig', () => { expect(conf.options.path).toBe('/root/tsconfig.json') expect(findConfig.mock.calls[0][0]).toBe('/root') expect(readConfig.mock.calls[0][0]).toBe('/root/tsconfig.json') - expect(parseConfig.mock.calls[0][0]).toEqual( - expect.objectContaining({ - include: [], - }), - ) expect(parseConfig.mock.calls[0][2]).toBe('/root') expect(parseConfig.mock.calls[0][4]).toBe('/root/tsconfig.json') expect(conf.options.allowSyntheticDefaultImports).toBeUndefined() @@ -770,11 +746,6 @@ describe('readTsConfig', () => { expect(conf.options.path).toBe('/foo/tsconfig.bar.json') expect(findConfig).not.toBeCalled() expect(readConfig.mock.calls[0][0]).toBe('/foo/tsconfig.bar.json') - expect(parseConfig.mock.calls[0][0]).toEqual( - expect.objectContaining({ - include: [], - }), - ) expect(parseConfig.mock.calls[0][2]).toBe('/foo') expect(parseConfig.mock.calls[0][4]).toBe('/foo/tsconfig.bar.json') expect(conf.errors).toEqual([]) @@ -803,11 +774,6 @@ describe('readTsConfig', () => { expect(conf.options.path).toBe('/root/tsconfig.json') expect(findConfig.mock.calls[0][0]).toBe('/root') expect(readConfig.mock.calls[0][0]).toBe('/root/tsconfig.json') - expect(parseConfig.mock.calls[0][0]).toEqual( - expect.objectContaining({ - include: [], - }), - ) expect(parseConfig.mock.calls[0][2]).toBe('/root') expect(parseConfig.mock.calls[0][4]).toBe('/root/tsconfig.json') expect(conf.errors).toEqual([]) @@ -819,11 +785,6 @@ describe('readTsConfig', () => { expect(conf.options.path).toBe('/foo/tsconfig.bar.json') expect(findConfig).not.toBeCalled() expect(readConfig.mock.calls[0][0]).toBe('/foo/tsconfig.bar.json') - expect(parseConfig.mock.calls[0][0]).toEqual( - expect.objectContaining({ - include: [], - }), - ) expect(parseConfig.mock.calls[0][2]).toBe('/foo') expect(parseConfig.mock.calls[0][4]).toBe('/foo/tsconfig.bar.json') expect(conf.errors).toEqual([]) diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 50fb164cba..a982942ea8 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -712,7 +712,7 @@ export class ConfigSet { resolvedConfigFile?: string | null, noProject?: boolean | null, ): ParsedCommandLine { - let config = { compilerOptions: {}, include: [] } + let config = { compilerOptions: {} } let basePath = normalizeSlashes(this.rootDir) let configFileName: string | undefined const ts = this.compilerModule @@ -741,11 +741,6 @@ export class ConfigSet { ...config.compilerOptions, ...compilerOptions, } - /** - * Always set include to empty array so fileNames after parseJsonConfigFileContent only contains the least minimum initial - * files to utilize LanguageService incremental feature - */ - config.include = [] // parse json, merge config extending others, ... const result = ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName)