diff --git a/src/compiler.ts b/src/compiler.ts index f874a13e31..f335c470da 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -101,7 +101,9 @@ export function createCompiler(configs: ConfigSet): TsCompiler { ? configs.filterDiagnostics(result.diagnostics) : [] - if (diagnosticList.length) throw configs.createTsError(diagnosticList) + if (diagnosticList.length) { + throw configs.createTsError(diagnosticList) + } return [result.outputText, result.sourceMapText as string] } @@ -174,16 +176,18 @@ export function createCompiler(configs: ConfigSet): TsCompiler { const output = service.getEmitOutput(fileName) - // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`. - const diagnostics = service - .getCompilerOptionsDiagnostics() - .concat(service.getSyntacticDiagnostics(fileName)) - .concat(service.getSemanticDiagnostics(fileName)) + if (configs.shouldReportDiagnostic(fileName)) { + // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`. + const diagnostics = service + .getCompilerOptionsDiagnostics() + .concat(service.getSyntacticDiagnostics(fileName)) + .concat(service.getSemanticDiagnostics(fileName)) - const diagnosticList = configs.filterDiagnostics(diagnostics) + const diagnosticList = configs.filterDiagnostics(diagnostics) - if (diagnosticList.length) { - throw configs.createTsError(diagnosticList) + if (diagnosticList.length) { + throw configs.createTsError(diagnosticList) + } } if (output.emitSkipped) { diff --git a/src/ts-jest-transformer.ts b/src/ts-jest-transformer.ts index 43537f1af5..8dc3c59474 100644 --- a/src/ts-jest-transformer.ts +++ b/src/ts-jest-transformer.ts @@ -89,9 +89,6 @@ export class TsJestTransformer implements jest.Transformer { const stringify = configs.shouldStringifyContent(filePath) const babelJest = stringify ? undefined : configs.babelJestTransformer - // get the compiler instance - const compiler = configs.tsCompiler - // handles here what we should simply stringify if (stringify) { source = `module.exports=${JSON.stringify(source)}` @@ -100,7 +97,7 @@ export class TsJestTransformer implements jest.Transformer { // transpile TS code (source maps are included) result = filePath.endsWith('.d.ts') ? '' // do not try to compile declaration files - : compiler.compile(source, filePath) + : configs.tsCompiler.compile(source, filePath) // calling babel-jest transformer if (babelJest) {