Skip to content

Commit

Permalink
fix(compiler): do not force module kind if piping babel
Browse files Browse the repository at this point in the history
Closes #767
  • Loading branch information
huafu committed Sep 27, 2018
1 parent 13cb48d commit acebc8c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/config/config-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
11 changes: 8 additions & 3 deletions src/config/config-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export class ConfigSet {

@Memoize()
get overriddenCompilerOptions(): Partial<CompilerOptions> {
return {
const options: Partial<CompilerOptions> = {
// we handle sourcemaps this way and not another
sourceMap: true,
inlineSourceMap: false,
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
) {
Expand Down

0 comments on commit acebc8c

Please sign in to comment.