Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8a29aaa

Browse files
authoredMay 7, 2020
fix(config): don't set include to empty array (#1606)
1 parent 5cdbabb commit 8a29aaa

File tree

5 files changed

+34
-53
lines changed

5 files changed

+34
-53
lines changed
 

‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ For example:
3131
{
3232
// ...other configs
3333
"files": [
34-
"my-custom-typings.d.ts".
34+
"my-custom-typings.d.ts",
3535
"my-global-module.ts"
3636
]
3737
}

‎docs/user/config/isolatedModules.md

+28
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,31 @@ module.exports = {
4343
```
4444

4545
</div></div>
46+
47+
# Performance
48+
49+
Using `isolatedModules: false` comes with a cost of performance comparing to `isolatedModules: true`. There is a way
50+
to improve the performance when using this mode by changing the value of `include` in `tsconfig` which is used by `ts-jest`.
51+
The least amount of files which are provided in `include`, the more performance the test run can gain.
52+
53+
### Example
54+
55+
```json5
56+
// tsconfig.json
57+
{
58+
// ...other configs
59+
include: [
60+
"my-typings/*",
61+
"my-global-modules/*",
62+
]
63+
}
64+
```
65+
66+
## Caveats
67+
68+
Limiting the amount of files loaded via `include` can greatly boost performance when running tests. However, the trade off
69+
is `ts-jest` might not recognize all files which are intended to use with `jest`. One can run into issues with custom typings,
70+
global modules, etc...
71+
72+
The suggested solution is what is needed for the test environment should be captured by
73+
glob patterns in `include`, to gain both performance boost and avoid breaking behaviors.

‎e2e/__external-repos__/custom-typings/tsconfig.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
"target": "es5",
44
"module": "commonjs",
55
"esModuleInterop": true
6-
},
7-
"files": [
8-
"jquery.d.ts"
9-
]
6+
}
107
}

‎src/config/config-set.spec.ts

+3-42
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,9 @@ describe('typescript', () => {
468468
createConfigSet({ tsJestConfig: tsJest, parentConfig }).parsedTsConfig
469469

470470
it('should read file list from default tsconfig', () => {
471-
// since the default is to lookup for tsconfig, but we set include to [] so we should not have this file in the list
472-
expect(get().fileNames).toEqual([])
471+
// since the default is to lookup for tsconfig,
472+
// we should have this file in the list
473+
expect(get().fileNames).toContain(normalizeSlashes(__filename))
473474
})
474475

475476
it.each(['tsConfig', 'tsconfig'])('should include compiler config from `%s` option key', (key: string) => {
@@ -610,11 +611,6 @@ describe('readTsConfig', () => {
610611
const conf = cs.readTsConfig()
611612
expect(conf.options.configFilePath).toBeUndefined()
612613
expect(readConfig).not.toHaveBeenCalled()
613-
expect(parseConfig.mock.calls[0][0]).toEqual(
614-
expect.objectContaining({
615-
include: [],
616-
}),
617-
)
618614
expect(parseConfig.mock.calls[0][2]).toBe('/root')
619615
expect(parseConfig.mock.calls[0][4]).toBeUndefined()
620616
})
@@ -661,11 +657,6 @@ describe('readTsConfig', () => {
661657
expect(conf.options.path).toBe('/root/tsconfig.json')
662658
expect(findConfig.mock.calls[0][0]).toBe('/root')
663659
expect(readConfig.mock.calls[0][0]).toBe('/root/tsconfig.json')
664-
expect(parseConfig.mock.calls[0][0]).toEqual(
665-
expect.objectContaining({
666-
include: [],
667-
}),
668-
)
669660
expect(parseConfig.mock.calls[0][2]).toBe('/root')
670661
expect(parseConfig.mock.calls[0][4]).toBe('/root/tsconfig.json')
671662
expect(conf.options.allowSyntheticDefaultImports).toEqual(true)
@@ -677,11 +668,6 @@ describe('readTsConfig', () => {
677668
expect(conf.options.path).toBe('/foo/tsconfig.bar.json')
678669
expect(findConfig).not.toBeCalled()
679670
expect(readConfig.mock.calls[0][0]).toBe('/foo/tsconfig.bar.json')
680-
expect(parseConfig.mock.calls[0][0]).toEqual(
681-
expect.objectContaining({
682-
include: [],
683-
}),
684-
)
685671
expect(parseConfig.mock.calls[0][2]).toBe('/foo')
686672
expect(parseConfig.mock.calls[0][4]).toBe('/foo/tsconfig.bar.json')
687673
expect(conf.errors).toMatchSnapshot()
@@ -710,11 +696,6 @@ describe('readTsConfig', () => {
710696
expect(conf.options.path).toBe('/root/tsconfig.json')
711697
expect(findConfig.mock.calls[0][0]).toBe('/root')
712698
expect(readConfig.mock.calls[0][0]).toBe('/root/tsconfig.json')
713-
expect(parseConfig.mock.calls[0][0]).toEqual(
714-
expect.objectContaining({
715-
include: [],
716-
}),
717-
)
718699
expect(parseConfig.mock.calls[0][2]).toBe('/root')
719700
expect(parseConfig.mock.calls[0][4]).toBe('/root/tsconfig.json')
720701
expect(conf.options.allowSyntheticDefaultImports).toEqual(true)
@@ -754,11 +735,6 @@ describe('readTsConfig', () => {
754735
expect(conf.options.path).toBe('/root/tsconfig.json')
755736
expect(findConfig.mock.calls[0][0]).toBe('/root')
756737
expect(readConfig.mock.calls[0][0]).toBe('/root/tsconfig.json')
757-
expect(parseConfig.mock.calls[0][0]).toEqual(
758-
expect.objectContaining({
759-
include: [],
760-
}),
761-
)
762738
expect(parseConfig.mock.calls[0][2]).toBe('/root')
763739
expect(parseConfig.mock.calls[0][4]).toBe('/root/tsconfig.json')
764740
expect(conf.options.allowSyntheticDefaultImports).toBeUndefined()
@@ -770,11 +746,6 @@ describe('readTsConfig', () => {
770746
expect(conf.options.path).toBe('/foo/tsconfig.bar.json')
771747
expect(findConfig).not.toBeCalled()
772748
expect(readConfig.mock.calls[0][0]).toBe('/foo/tsconfig.bar.json')
773-
expect(parseConfig.mock.calls[0][0]).toEqual(
774-
expect.objectContaining({
775-
include: [],
776-
}),
777-
)
778749
expect(parseConfig.mock.calls[0][2]).toBe('/foo')
779750
expect(parseConfig.mock.calls[0][4]).toBe('/foo/tsconfig.bar.json')
780751
expect(conf.errors).toEqual([])
@@ -803,11 +774,6 @@ describe('readTsConfig', () => {
803774
expect(conf.options.path).toBe('/root/tsconfig.json')
804775
expect(findConfig.mock.calls[0][0]).toBe('/root')
805776
expect(readConfig.mock.calls[0][0]).toBe('/root/tsconfig.json')
806-
expect(parseConfig.mock.calls[0][0]).toEqual(
807-
expect.objectContaining({
808-
include: [],
809-
}),
810-
)
811777
expect(parseConfig.mock.calls[0][2]).toBe('/root')
812778
expect(parseConfig.mock.calls[0][4]).toBe('/root/tsconfig.json')
813779
expect(conf.errors).toEqual([])
@@ -819,11 +785,6 @@ describe('readTsConfig', () => {
819785
expect(conf.options.path).toBe('/foo/tsconfig.bar.json')
820786
expect(findConfig).not.toBeCalled()
821787
expect(readConfig.mock.calls[0][0]).toBe('/foo/tsconfig.bar.json')
822-
expect(parseConfig.mock.calls[0][0]).toEqual(
823-
expect.objectContaining({
824-
include: [],
825-
}),
826-
)
827788
expect(parseConfig.mock.calls[0][2]).toBe('/foo')
828789
expect(parseConfig.mock.calls[0][4]).toBe('/foo/tsconfig.bar.json')
829790
expect(conf.errors).toEqual([])

‎src/config/config-set.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ export class ConfigSet {
712712
resolvedConfigFile?: string | null,
713713
noProject?: boolean | null,
714714
): ParsedCommandLine {
715-
let config = { compilerOptions: {}, include: [] }
715+
let config = { compilerOptions: {} }
716716
let basePath = normalizeSlashes(this.rootDir)
717717
let configFileName: string | undefined
718718
const ts = this.compilerModule
@@ -741,11 +741,6 @@ export class ConfigSet {
741741
...config.compilerOptions,
742742
...compilerOptions,
743743
}
744-
/**
745-
* Always set include to empty array so fileNames after parseJsonConfigFileContent only contains the least minimum initial
746-
* files to utilize LanguageService incremental feature
747-
*/
748-
config.include = []
749744

750745
// parse json, merge config extending others, ...
751746
const result = ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName)

0 commit comments

Comments
 (0)
Please sign in to comment.