Skip to content

Commit acebc8c

Browse files
committedSep 27, 2018
fix(compiler): do not force module kind if piping babel
Closes #767
1 parent 13cb48d commit acebc8c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed
 

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

+19
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,25 @@ message TS151001: If you have issues related to imports, you should consider set
311311
"
312312
`)
313313
})
314+
315+
it('should not warn neither set synth. default imports if using babel', () => {
316+
const target = logTargetMock()
317+
target.clear()
318+
const cs = createConfigSet({
319+
tsJestConfig: {
320+
tsConfig: { module: 'amd', esModuleInterop: false } as any,
321+
diagnostics: { warnOnly: true, pretty: false },
322+
babelConfig: { babelrc: false },
323+
},
324+
resolve: null,
325+
})
326+
expect(cs.typescript.options).toMatchObject({
327+
module: ModuleKind.AMD,
328+
esModuleInterop: false,
329+
})
330+
expect(cs.typescript.options.allowSyntheticDefaultImports).toBeFalsy()
331+
expect(target.lines.warn).toHaveLength(0)
332+
})
314333
}) // typescript
315334

316335
describe('resolvePath', () => {

‎src/config/config-set.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ export class ConfigSet {
453453

454454
@Memoize()
455455
get overriddenCompilerOptions(): Partial<CompilerOptions> {
456-
return {
456+
const options: Partial<CompilerOptions> = {
457457
// we handle sourcemaps this way and not another
458458
sourceMap: true,
459459
inlineSourceMap: false,
@@ -462,8 +462,6 @@ export class ConfigSet {
462462
declaration: false,
463463
noEmit: false,
464464
outDir: '$$ts-jest$$',
465-
// commonjs is required for jest
466-
module: this.compilerModule.ModuleKind.CommonJS,
467465
// else istanbul related will be dropped
468466
removeComments: false,
469467
// to clear out else it's buggy
@@ -475,6 +473,12 @@ export class ConfigSet {
475473
emitDeclarationOnly: undefined,
476474
sourceRoot: undefined,
477475
}
476+
// force the module kind if not piping babel-jest
477+
if (!this.tsJest.babelConfig) {
478+
// commonjs is required for jest
479+
options.module = this.compilerModule.ModuleKind.CommonJS
480+
}
481+
return options
478482
}
479483

480484
@Memoize()
@@ -627,6 +631,7 @@ export class ConfigSet {
627631
: ts.ModuleKind.ESNext
628632
const moduleValue = finalOptions.module == null ? defaultModule : finalOptions.module
629633
if (
634+
'module' in forcedOptions &&
630635
moduleValue !== forcedOptions.module &&
631636
!(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)
632637
) {

0 commit comments

Comments
 (0)
Please sign in to comment.