Skip to content

Commit 1a287ad

Browse files
authoredApr 4, 2020
fix(config): set default outDir when allowJs is true and no outDir in tsconfig (#1502)
1 parent bb8d84c commit 1a287ad

21 files changed

+294
-46
lines changed
 
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as foo from './foo'
2+
import bar = require('./bar')
3+
4+
test('foo', () => {
5+
expect(foo).toBe('FOO!')
6+
})
7+
8+
test('bar', () => {
9+
expect(bar).toBe('BAR!')
10+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export = 'BAR!'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as bar from './bar'
2+
3+
test('esm', () => {
4+
expect(bar).toBe('BAR!')
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'FOO!'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const foo = require('./foo')
2+
const bar = require('./bar')
3+
4+
test('foo', () => {
5+
expect(foo).toBe('FOO!')
6+
})
7+
8+
test('bar', () => {
9+
expect(bar).toBe('BAR!')
10+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"allowJs": true
5+
}
6+
}

‎e2e/__tests__/__snapshots__/allow-js.test.ts.snap

+72-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ exports[`using babel-jest for js files should pass using template "with-typescri
6868
================================================================================
6969
`;
7070

71-
exports[`using ts-jest for js files should pass using template "default" 1`] = `
71+
exports[`using ts-jest for js files with outDir should pass using template "default" 1`] = `
7272
√ jest
7373
↳ exit code: 0
7474
===[ STDOUT ]===================================================================
@@ -85,7 +85,7 @@ exports[`using ts-jest for js files should pass using template "default" 1`] = `
8585
================================================================================
8686
`;
8787

88-
exports[`using ts-jest for js files should pass using template "with-babel-7" 1`] = `
88+
exports[`using ts-jest for js files with outDir should pass using template "with-babel-7" 1`] = `
8989
√ jest
9090
↳ exit code: 0
9191
===[ STDOUT ]===================================================================
@@ -102,7 +102,7 @@ exports[`using ts-jest for js files should pass using template "with-babel-7" 1`
102102
================================================================================
103103
`;
104104

105-
exports[`using ts-jest for js files should pass using template "with-babel-7-string-config" 1`] = `
105+
exports[`using ts-jest for js files with outDir should pass using template "with-babel-7-string-config" 1`] = `
106106
√ jest
107107
↳ exit code: 0
108108
===[ STDOUT ]===================================================================
@@ -119,7 +119,75 @@ exports[`using ts-jest for js files should pass using template "with-babel-7-str
119119
================================================================================
120120
`;
121121

122-
exports[`using ts-jest for js files should pass using template "with-typescript-2-7" 1`] = `
122+
exports[`using ts-jest for js files with outDir should pass using template "with-typescript-2-7" 1`] = `
123+
√ jest
124+
↳ exit code: 0
125+
===[ STDOUT ]===================================================================
126+
127+
===[ STDERR ]===================================================================
128+
PASS ./esm.spec.js
129+
√ esm
130+
131+
Test Suites: 1 passed, 1 total
132+
Tests: 1 passed, 1 total
133+
Snapshots: 0 total
134+
Time: XXs
135+
Ran all test suites.
136+
================================================================================
137+
`;
138+
139+
exports[`using ts-jest for js files without outDir should pass using template "default" 1`] = `
140+
√ jest
141+
↳ exit code: 0
142+
===[ STDOUT ]===================================================================
143+
144+
===[ STDERR ]===================================================================
145+
PASS ./esm.spec.js
146+
√ esm
147+
148+
Test Suites: 1 passed, 1 total
149+
Tests: 1 passed, 1 total
150+
Snapshots: 0 total
151+
Time: XXs
152+
Ran all test suites.
153+
================================================================================
154+
`;
155+
156+
exports[`using ts-jest for js files without outDir should pass using template "with-babel-7" 1`] = `
157+
√ jest
158+
↳ exit code: 0
159+
===[ STDOUT ]===================================================================
160+
161+
===[ STDERR ]===================================================================
162+
PASS ./esm.spec.js
163+
√ esm
164+
165+
Test Suites: 1 passed, 1 total
166+
Tests: 1 passed, 1 total
167+
Snapshots: 0 total
168+
Time: XXs
169+
Ran all test suites.
170+
================================================================================
171+
`;
172+
173+
exports[`using ts-jest for js files without outDir should pass using template "with-babel-7-string-config" 1`] = `
174+
√ jest
175+
↳ exit code: 0
176+
===[ STDOUT ]===================================================================
177+
178+
===[ STDERR ]===================================================================
179+
PASS ./esm.spec.js
180+
√ esm
181+
182+
Test Suites: 1 passed, 1 total
183+
Tests: 1 passed, 1 total
184+
Snapshots: 0 total
185+
Time: XXs
186+
Ran all test suites.
187+
================================================================================
188+
`;
189+
190+
exports[`using ts-jest for js files without outDir should pass using template "with-typescript-2-7" 1`] = `
123191
√ jest
124192
↳ exit code: 0
125193
===[ STDOUT ]===================================================================

‎e2e/__tests__/allow-js.test.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { allPackageSetsWithPreset, allValidPackageSets } from '../__helpers__/te
22
import { configureTestCase } from '../__helpers__/test-case'
33

44
describe('using babel-jest for js files', () => {
5-
const testCase = configureTestCase('allow-js', {
5+
const testCase = configureTestCase('allow-js/with-outDir', {
66
jestConfig: { testMatch: null, testRegex: '(foo|bar)\\.spec\\.[jt]s$' },
77
})
88

@@ -15,8 +15,26 @@ describe('using babel-jest for js files', () => {
1515
})
1616
})
1717

18-
describe('using ts-jest for js files', () => {
19-
const testCase = configureTestCase('allow-js', {
18+
describe('using ts-jest for js files with outDir', () => {
19+
const testCase = configureTestCase('allow-js/with-outDir', {
20+
jestConfig: {
21+
preset: 'ts-jest/presets/js-with-ts',
22+
testMatch: null,
23+
testRegex: 'esm\\.spec\\.[jt]s$',
24+
},
25+
})
26+
27+
testCase.runWithTemplates(allPackageSetsWithPreset, 0, (runTest, { testLabel }) => {
28+
it(testLabel, () => {
29+
const result = runTest()
30+
expect(result.status).toBe(0)
31+
expect(result).toMatchSnapshot()
32+
})
33+
})
34+
})
35+
36+
describe('using ts-jest for js files without outDir', () => {
37+
const testCase = configureTestCase('allow-js/without-outDir', {
2038
jestConfig: {
2139
preset: 'ts-jest/presets/js-with-ts',
2240
testMatch: null,

‎src/compiler/__snapshots__/language-service.spec.ts.snap

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`language service should compile js file for allowJs true 1`] = `
4-
===[ FILE: test-allow-js.js ]===================================================
3+
exports[`language service should compile js file for allowJs true with outDir 1`] = `
4+
===[ FILE: test-allow-js-with-outDir.js ]=======================================
55
"use strict";
66
Object.defineProperty(exports, "__esModule", { value: true });
77
exports.default = 42;
8-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvdy1qcy5qcyIsIm1hcHBpbmdzIjoiOztBQUFBLGtCQUFlLEVBQUUsQ0FBQSIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJ0ZXN0LWFsbG93LWpzLmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IDQyIl0sInZlcnNpb24iOjN9
8+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvdy1qcy13aXRoLW91dERpci5qcyIsIm1hcHBpbmdzIjoiOztBQUFBLGtCQUFlLEVBQUUsQ0FBQSIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJ0ZXN0LWFsbG93LWpzLXdpdGgtb3V0RGlyLmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IDQyIl0sInZlcnNpb24iOjN9
99
===[ INLINE SOURCE MAPS ]=======================================================
10-
file: test-allow-js.js
10+
file: test-allow-js-with-outDir.js
1111
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
1212
names: []
1313
sources:
14-
- test-allow-js.js
14+
- test-allow-js-with-outDir.js
15+
sourcesContent:
16+
- export default 42
17+
version: 3
18+
================================================================================
19+
`;
20+
21+
exports[`language service should compile js file for allowJs true without outDir 1`] = `
22+
===[ FILE: test-allow-js-no-outDir.js ]=========================================
23+
"use strict";
24+
Object.defineProperty(exports, "__esModule", { value: true });
25+
exports.default = 42;
26+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvdy1qcy1uby1vdXREaXIuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvdy1qcy1uby1vdXREaXIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
27+
===[ INLINE SOURCE MAPS ]=======================================================
28+
file: test-allow-js-no-outDir.js
29+
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
30+
names: []
31+
sources:
32+
- test-allow-js-no-outDir.js
1533
sourcesContent:
1634
- export default 42
1735
version: 3

‎src/compiler/__snapshots__/program.spec.ts.snap

+46-10
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,71 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`allowJs should compile js file for allowJs true with incremental program 1`] = `
4-
===[ FILE: test-allowJs.test.js ]===============================================
3+
exports[`allowJs with incremental program should compile js file for allowJs true with outDir 1`] = `
4+
===[ FILE: test-allowJs-incremental-outDir.test.js ]============================
55
"use strict";
66
Object.defineProperty(exports, "__esModule", { value: true });
77
exports.default = 42;
8-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLnRlc3QuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvd0pzLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
8+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLWluY3JlbWVudGFsLW91dERpci50ZXN0LmpzIiwibWFwcGluZ3MiOiI7O0FBQUEsa0JBQWUsRUFBRSxDQUFBIiwibmFtZXMiOltdLCJzb3VyY2VzIjpbInRlc3QtYWxsb3dKcy1pbmNyZW1lbnRhbC1vdXREaXIudGVzdC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCA0MiJdLCJ2ZXJzaW9uIjozfQ==
99
===[ INLINE SOURCE MAPS ]=======================================================
10-
file: test-allowJs.test.js
10+
file: test-allowJs-incremental-outDir.test.js
1111
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
1212
names: []
1313
sources:
14-
- test-allowJs.test.js
14+
- test-allowJs-incremental-outDir.test.js
1515
sourcesContent:
1616
- export default 42
1717
version: 3
1818
================================================================================
1919
`;
2020

21-
exports[`allowJs should compile js file for allowJs true with normal program 1`] = `
22-
===[ FILE: test-allowJs.test.js ]===============================================
21+
exports[`allowJs with incremental program should compile js file for allowJs true without outDir 1`] = `
22+
===[ FILE: test-allowJs-incremental-no-outDir.test.js ]=========================
2323
"use strict";
2424
Object.defineProperty(exports, "__esModule", { value: true });
2525
exports.default = 42;
26-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLnRlc3QuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvd0pzLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
26+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLWluY3JlbWVudGFsLW5vLW91dERpci50ZXN0LmpzIiwibWFwcGluZ3MiOiI7O0FBQUEsa0JBQWUsRUFBRSxDQUFBIiwibmFtZXMiOltdLCJzb3VyY2VzIjpbInRlc3QtYWxsb3dKcy1pbmNyZW1lbnRhbC1uby1vdXREaXIudGVzdC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCA0MiJdLCJ2ZXJzaW9uIjozfQ==
2727
===[ INLINE SOURCE MAPS ]=======================================================
28-
file: test-allowJs.test.js
28+
file: test-allowJs-incremental-no-outDir.test.js
2929
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
3030
names: []
3131
sources:
32-
- test-allowJs.test.js
32+
- test-allowJs-incremental-no-outDir.test.js
33+
sourcesContent:
34+
- export default 42
35+
version: 3
36+
================================================================================
37+
`;
38+
39+
exports[`allowJs with program should compile js file for allowJs true with outDir 1`] = `
40+
===[ FILE: test-allowJs-program-outDir.test.js ]================================
41+
"use strict";
42+
Object.defineProperty(exports, "__esModule", { value: true });
43+
exports.default = 42;
44+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLXByb2dyYW0tb3V0RGlyLnRlc3QuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvd0pzLXByb2dyYW0tb3V0RGlyLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
45+
===[ INLINE SOURCE MAPS ]=======================================================
46+
file: test-allowJs-program-outDir.test.js
47+
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
48+
names: []
49+
sources:
50+
- test-allowJs-program-outDir.test.js
51+
sourcesContent:
52+
- export default 42
53+
version: 3
54+
================================================================================
55+
`;
56+
57+
exports[`allowJs with program should compile js file for allowJs true without outDir 1`] = `
58+
===[ FILE: test-allowJs-program-no-outDir.test.js ]=============================
59+
"use strict";
60+
Object.defineProperty(exports, "__esModule", { value: true });
61+
exports.default = 42;
62+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLXByb2dyYW0tbm8tb3V0RGlyLnRlc3QuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvd0pzLXByb2dyYW0tbm8tb3V0RGlyLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
63+
===[ INLINE SOURCE MAPS ]=======================================================
64+
file: test-allowJs-program-no-outDir.test.js
65+
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
66+
names: []
67+
sources:
68+
- test-allowJs-program-no-outDir.test.js
3369
sourcesContent:
3470
- export default 42
3571
version: 3

‎src/compiler/language-service.spec.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,25 @@ describe('language service', () => {
6060
removeSync(fileName)
6161
})
6262

63-
it('should compile js file for allowJs true', () => {
64-
const fileName = `test-allow-js.js`
63+
it('should compile js file for allowJs true with outDir', () => {
64+
const fileName = `test-allow-js-with-outDir.js`
6565
const compiler = makeCompiler({
66-
tsJestConfig: { tsConfig: { allowJs: true, outDir: '$$ts-jest$$' } },
66+
tsJestConfig: { tsConfig: { allowJs: true, outDir: '$$foo$$' } },
67+
})
68+
const source = 'export default 42'
69+
70+
writeFileSync(fileName, source, 'utf8')
71+
const compiled = compiler.compile(source, fileName)
72+
73+
expect(new ProcessedSource(compiled, fileName)).toMatchSnapshot()
74+
75+
removeSync(fileName)
76+
})
77+
78+
it('should compile js file for allowJs true without outDir', () => {
79+
const fileName = `test-allow-js-no-outDir.js`
80+
const compiler = makeCompiler({
81+
tsJestConfig: { tsConfig: { allowJs: true } },
6782
})
6883
const source = 'export default 42'
6984

‎src/compiler/program.spec.ts

+65-18
Original file line numberDiff line numberDiff line change
@@ -108,36 +108,83 @@ describe('cache', () => {
108108
})
109109

110110
describe('allowJs', () => {
111-
const fileName = 'test-allowJs.test.js'
111+
const baseFileName = 'test-allowJs'
112+
const baseFileExt = 'test.js'
112113
const source = 'export default 42'
113-
const tsConfig = { allowJs: true, outDir: '$$ts-jest$$' }
114+
const tsConfig = { allowJs: true }
114115

115-
beforeAll(() => {
116-
writeFileSync(fileName, source, 'utf8')
117-
})
116+
describe(`with program`, () => {
117+
it('should compile js file for allowJs true with outDir', () => {
118+
const fileName = `${baseFileName}-program-outDir.${baseFileExt}`
119+
writeFileSync(fileName, source, 'utf8')
120+
const compiler = makeCompiler({
121+
tsJestConfig: {
122+
...baseTsJestConfig,
123+
incremental: false,
124+
tsConfig: {
125+
...tsConfig,
126+
outDir: '$$foo$$',
127+
},
128+
},
129+
})
118130

119-
afterAll(() => {
120-
removeSync(fileName)
121-
})
131+
const compiled = compiler.compile(source, fileName)
122132

123-
it('should compile js file for allowJs true with normal program', () => {
124-
const compiler = makeCompiler({
125-
tsJestConfig: { ...baseTsJestConfig, incremental: false, tsConfig },
133+
expect(new ProcessedSource(compiled, fileName)).toMatchSnapshot()
134+
135+
removeSync(fileName)
126136
})
127137

128-
const compiled = compiler.compile(source, fileName)
138+
it('should compile js file for allowJs true without outDir', () => {
139+
const fileName = `${baseFileName}-program-no-outDir.${baseFileExt}`
140+
writeFileSync(fileName, source, 'utf8')
141+
const compiler = makeCompiler({
142+
tsJestConfig: { ...baseTsJestConfig, incremental: false, tsConfig },
143+
})
129144

130-
expect(new ProcessedSource(compiled, fileName)).toMatchSnapshot()
145+
const compiled = compiler.compile(source, fileName)
146+
147+
expect(new ProcessedSource(compiled, fileName)).toMatchSnapshot()
148+
149+
removeSync(fileName)
150+
})
131151
})
132152

133-
it('should compile js file for allowJs true with incremental program', () => {
134-
const compiler = makeCompiler({
135-
tsJestConfig: { ...baseTsJestConfig, incremental: true, tsConfig },
153+
describe(`with incremental program`, () => {
154+
it('should compile js file for allowJs true with outDir', () => {
155+
const fileName = `${baseFileName}-incremental-outDir.${baseFileExt}`
156+
writeFileSync(fileName, source, 'utf8')
157+
const compiler = makeCompiler({
158+
tsJestConfig: {
159+
...baseTsJestConfig,
160+
incremental: true,
161+
tsConfig: {
162+
...tsConfig,
163+
outDir: '$$foo$$',
164+
},
165+
},
166+
})
167+
168+
const compiled = compiler.compile(source, fileName)
169+
170+
expect(new ProcessedSource(compiled, fileName)).toMatchSnapshot()
171+
172+
removeSync(fileName)
136173
})
137174

138-
const compiled = compiler.compile(source, fileName)
175+
it('should compile js file for allowJs true without outDir', () => {
176+
const fileName = `${baseFileName}-incremental-no-outDir.${baseFileExt}`
177+
writeFileSync(fileName, source, 'utf8')
178+
const compiler = makeCompiler({
179+
tsJestConfig: { ...baseTsJestConfig, incremental: true, tsConfig },
180+
})
139181

140-
expect(new ProcessedSource(compiled, fileName)).toMatchSnapshot()
182+
const compiled = compiler.compile(source, fileName)
183+
184+
expect(new ProcessedSource(compiled, fileName)).toMatchSnapshot()
185+
186+
removeSync(fileName)
187+
})
141188
})
142189
})
143190

‎src/compiler/transpile-module.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { removeSync, writeFileSync } from 'fs-extra'
44
import { makeCompiler } from '../__helpers__/fakers'
55
import { logTargetMock } from '../__helpers__/mocks'
66
import ProcessedSource from '../__helpers__/processed-source'
7+
import { TS_JEST_OUT_DIR } from '../config/config-set'
78

89
const logTarget = logTargetMock()
910

@@ -42,7 +43,7 @@ describe('transpile module with isolatedModule: true', () => {
4243
it('should compile js file for allowJs true', () => {
4344
const fileName = `${__filename}.test.js`
4445
const compiler = makeCompiler({
45-
tsJestConfig: { ...baseTsJestConfig, tsConfig: { allowJs: true, outDir: '$$ts-jest$$' } },
46+
tsJestConfig: { ...baseTsJestConfig, tsConfig: { allowJs: true, outDir: TS_JEST_OUT_DIR } },
4647
})
4748
const source = 'export default 42'
4849

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getPackageVersion } from '../util/get-package-version'
1515
import { normalizeSlashes } from '../util/normalize-slashes'
1616
import { mocked } from '../util/testing'
1717

18-
import { ConfigSet, IGNORE_DIAGNOSTIC_CODES, MATCH_NOTHING } from './config-set'
18+
import { ConfigSet, IGNORE_DIAGNOSTIC_CODES, MATCH_NOTHING, TS_JEST_OUT_DIR } from './config-set'
1919

2020
jest.mock('../util/backports')
2121
jest.mock('../index')
@@ -462,6 +462,10 @@ describe('typescript', () => {
462462
})
463463
})
464464

465+
it('should include default outDir $$ts-jest$$ when allowJs is enabled and no outDir from config', () => {
466+
expect(get(void 0, { tsConfig: { allowJs: true } }).options.outDir).toBe(TS_JEST_OUT_DIR)
467+
})
468+
465469
it('should be able to read extends', () => {
466470
const cs = createConfigSet({
467471
tsJestConfig: { tsConfig: 'tsconfig.build.json' },

‎src/config/config-set.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export const IGNORE_DIAGNOSTIC_CODES = [
7070
18002, // "The 'files' list in config file is empty."
7171
18003, // "No inputs were found in config file."
7272
]
73+
/**
74+
* @internal
75+
*/
76+
export const TS_JEST_OUT_DIR = '$$ts-jest$$'
7377

7478
/**
7579
* @internal
@@ -584,7 +588,7 @@ export class ConfigSet {
584588
inlineSources: true,
585589
// we don't want to create declaration files
586590
declaration: false,
587-
noEmit: false,
591+
noEmit: false, // set to true will make compiler API not emit any compiled results.
588592
// else istanbul related will be dropped
589593
removeComments: false,
590594
// to clear out else it's buggy
@@ -778,6 +782,10 @@ export class ConfigSet {
778782
finalOptions.allowSyntheticDefaultImports = true
779783
}
780784
}
785+
// Make sure when allowJs is enabled, outDir is required to have when using allowJs: true
786+
if (finalOptions.allowJs && !finalOptions.outDir) {
787+
finalOptions.outDir = TS_JEST_OUT_DIR
788+
}
781789

782790
// ensure undefined are removed and other values are overridden
783791
for (const key of Object.keys(forcedOptions)) {

0 commit comments

Comments
 (0)
Please sign in to comment.