From acebc8cfd7937c28df096480091e32078c496752 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 27 Sep 2018 07:58:54 +0200 Subject: [PATCH] fix(compiler): do not force module kind if piping babel Closes #767 --- src/config/config-set.spec.ts | 19 +++++++++++++++++++ src/config/config-set.ts | 11 ++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index eef9b851ae..73fb88f9e8 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -311,6 +311,25 @@ message TS151001: If you have issues related to imports, you should consider set " `) }) + + it('should not warn neither set synth. default imports if using babel', () => { + const target = logTargetMock() + target.clear() + const cs = createConfigSet({ + tsJestConfig: { + tsConfig: { module: 'amd', esModuleInterop: false } as any, + diagnostics: { warnOnly: true, pretty: false }, + babelConfig: { babelrc: false }, + }, + resolve: null, + }) + expect(cs.typescript.options).toMatchObject({ + module: ModuleKind.AMD, + esModuleInterop: false, + }) + expect(cs.typescript.options.allowSyntheticDefaultImports).toBeFalsy() + expect(target.lines.warn).toHaveLength(0) + }) }) // typescript describe('resolvePath', () => { diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 16cc661c61..4331144fa4 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -453,7 +453,7 @@ export class ConfigSet { @Memoize() get overriddenCompilerOptions(): Partial { - return { + const options: Partial = { // we handle sourcemaps this way and not another sourceMap: true, inlineSourceMap: false, @@ -462,8 +462,6 @@ export class ConfigSet { declaration: false, noEmit: false, outDir: '$$ts-jest$$', - // commonjs is required for jest - module: this.compilerModule.ModuleKind.CommonJS, // else istanbul related will be dropped removeComments: false, // to clear out else it's buggy @@ -475,6 +473,12 @@ export class ConfigSet { emitDeclarationOnly: undefined, sourceRoot: undefined, } + // force the module kind if not piping babel-jest + if (!this.tsJest.babelConfig) { + // commonjs is required for jest + options.module = this.compilerModule.ModuleKind.CommonJS + } + return options } @Memoize() @@ -627,6 +631,7 @@ export class ConfigSet { : ts.ModuleKind.ESNext const moduleValue = finalOptions.module == null ? defaultModule : finalOptions.module if ( + 'module' in forcedOptions && moduleValue !== forcedOptions.module && !(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports) ) {