Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): do not force module kind if piping babel #768

Merged
merged 2 commits into from Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/config/config-set.spec.ts
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
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