Skip to content

Commit 2ae8df4

Browse files
authoredFeb 14, 2021
fix(config): improve emit skipped error message (#2358)
Closes #2350
1 parent 4726b1f commit 2ae8df4

19 files changed

+11
-223
lines changed
 
File renamed without changes.
File renamed without changes.

‎e2e/__cases__/allow-js/without-outDir/bar.spec.ts

-10
This file was deleted.

‎e2e/__cases__/allow-js/without-outDir/bar.ts

-1
This file was deleted.

‎e2e/__cases__/allow-js/without-outDir/esm.spec.js

-5
This file was deleted.

‎e2e/__cases__/allow-js/without-outDir/foo.js

-1
This file was deleted.

‎e2e/__cases__/allow-js/without-outDir/foo.spec.js

-10
This file was deleted.

‎e2e/__cases__/allow-js/without-outDir/tsconfig.json

-6
This file was deleted.

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

-154
This file was deleted.

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

+3-22
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ 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/with-outDir', {
5+
const testCase = configureTestCase('allow-js', {
66
jestConfig: { testRegex: '(foo|bar)\\.spec\\.[jt]s$' },
77
})
88

99
testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
1010
it(testLabel, () => {
1111
const result = runTest()
1212
expect(result.status).toBe(0)
13-
expect(result).toMatchSnapshot()
1413
})
1514
})
1615
})
1716

18-
describe('using ts-jest for js files with outDir', () => {
19-
const testCase = configureTestCase('allow-js/with-outDir', {
17+
describe('using ts-jest for js files', () => {
18+
const testCase = configureTestCase('allow-js', {
2019
jestConfig: {
2120
preset: 'ts-jest/presets/js-with-ts',
2221
testRegex: 'esm\\.spec\\.[jt]s$',
@@ -27,24 +26,6 @@ describe('using ts-jest for js files with outDir', () => {
2726
it(testLabel, () => {
2827
const result = runTest()
2928
expect(result.status).toBe(0)
30-
expect(result).toMatchSnapshot()
31-
})
32-
})
33-
})
34-
35-
describe('using ts-jest for js files without outDir', () => {
36-
const testCase = configureTestCase('allow-js/without-outDir', {
37-
jestConfig: {
38-
preset: 'ts-jest/presets/js-with-ts',
39-
testRegex: 'esm\\.spec\\.[jt]s$',
40-
},
41-
})
42-
43-
testCase.runWithTemplates(allPackageSetsWithPreset, 0, (runTest, { testLabel }) => {
44-
it(testLabel, () => {
45-
const result = runTest()
46-
expect(result.status).toBe(0)
47-
expect(result).toMatchSnapshot()
4829
})
4930
})
5031
})

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { createConfigSet, makeCompiler } from '../__helpers__/fakers'
77
import { logTargetMock } from '../__helpers__/mocks'
88
import { mockFolder } from '../__helpers__/path'
99
import ProcessedSource from '../__helpers__/processed-source'
10-
import { TS_JEST_OUT_DIR } from '../config/config-set'
1110

1211
import { TsCompiler } from './ts-compiler'
1312

@@ -33,7 +32,7 @@ describe('TsCompiler', () => {
3332
test('should compile js file for allowJs true', () => {
3433
const fileName = 'foo.js'
3534
const compiler = makeCompiler({
36-
tsJestConfig: { ...baseTsJestConfig, tsconfig: { allowJs: true, outDir: TS_JEST_OUT_DIR } },
35+
tsJestConfig: { ...baseTsJestConfig, tsconfig: { allowJs: true } },
3736
})
3837
const source = 'export default 42'
3938

@@ -189,7 +188,6 @@ const t: string = f(5)
189188
...baseTsJestConfig,
190189
tsconfig: {
191190
allowJs: true,
192-
outDir: TS_JEST_OUT_DIR,
193191
},
194192
astTransformers: {
195193
before: ['dummy-transformer'],

‎src/compiler/ts-compiler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { basename, normalize, relative } from 'path'
1+
import { basename, normalize } from 'path'
22

33
import { LogContexts, Logger, LogLevels } from 'bs-logger'
44
import memoize from 'lodash/memoize'
@@ -201,7 +201,7 @@ export class TsCompiler implements TsCompilerInstance {
201201
this._doTypeChecking(fileName)
202202
/* istanbul ignore next (this should never happen but is kept for security) */
203203
if (output.emitSkipped) {
204-
throw new TypeError(`${relative(this.configSet.cwd, fileName)}: Emit skipped for language service`)
204+
throw new Error(interpolate(Errors.CannotCompile, { file: fileName }))
205205
}
206206
// Throw an error when requiring `.d.ts` files.
207207
if (!output.outputFiles.length) {

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,12 @@ describe('parsedTsConfig', () => {
5151
})
5252

5353
it('should override some options', () => {
54-
expect(get({ tsconfig: { inlineSources: false } }).options).toMatchObject({
54+
expect(get({ tsconfig: { inlineSources: false, outDir: 'build' } }).options).toMatchObject({
5555
inlineSources: true,
56+
outDir: TS_JEST_OUT_DIR,
5657
})
5758
})
5859

59-
it('should include default outDir $$ts-jest$$ when allowJs is enabled and no outDir from config', () => {
60-
expect(get({ tsconfig: { allowJs: true } }).options.outDir).toBe(TS_JEST_OUT_DIR)
61-
})
62-
6360
it('should be able to read extends', () => {
6461
const cs = createConfigSet({
6562
tsJestConfig: { tsconfig: 'tsconfig.build.json' },

‎src/config/config-set.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ export class ConfigSet {
158158
// to clear out else it's buggy
159159
out: undefined,
160160
outFile: undefined,
161+
// ensure that `LanguageService` won't pick up things from `build` folder which can lead to emit skipped error
162+
outDir: TS_JEST_OUT_DIR,
161163
composite: undefined, // see https://github.com/TypeStrong/ts-node/pull/657/files
162164
declarationDir: undefined,
163165
declarationMap: undefined,
@@ -419,10 +421,6 @@ export class ConfigSet {
419421
finalOptions.allowSyntheticDefaultImports = true
420422
}
421423
}
422-
// Make sure when allowJs is enabled, outDir is required to have when using allowJs: true
423-
if (finalOptions.allowJs && !finalOptions.outDir) {
424-
finalOptions.outDir = TS_JEST_OUT_DIR
425-
}
426424

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

‎src/utils/messages.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const enum Errors {
1717
GotUnknownFileTypeWithBabel = 'Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files.',
1818
ConfigNoModuleInterop = 'If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.',
1919
MismatchNodeTargetMapping = 'There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping',
20+
CannotCompile = "Unable to process '{{file}}'. Please check your tsconfig.",
2021
}
2122

2223
/**

0 commit comments

Comments
 (0)
Please sign in to comment.