Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/legacy/compiler/__snapshots__/ts-compiler.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "supportsStaticESM": false, "useESM": true} 1`] = `
{
"allowSyntheticDefaultImports": undefined,
"customConditions": undefined,
"esModuleInterop": true,
"module": 1,
}
Expand All @@ -11,6 +12,7 @@ exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code
exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "supportsStaticESM": true, "useESM": false} 1`] = `
{
"allowSyntheticDefaultImports": undefined,
"customConditions": undefined,
"esModuleInterop": true,
"module": 1,
}
Expand All @@ -19,6 +21,7 @@ exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code
exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": false, "supportsStaticESM": true, "useESM": true} 1`] = `
{
"allowSyntheticDefaultImports": undefined,
"customConditions": undefined,
"esModuleInterop": true,
"module": 99,
}
Expand All @@ -27,6 +30,7 @@ exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code
exports[`TsCompiler getCompiledOutput isolatedModules true should transpile code with config {"babelConfig": true, "supportsStaticESM": false, "useESM": true} 1`] = `
{
"allowSyntheticDefaultImports": undefined,
"customConditions": undefined,
"esModuleInterop": true,
"module": 1,
}
Expand Down
40 changes: 35 additions & 5 deletions src/legacy/compiler/ts-compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ describe('TsCompiler', () => {
const compiler = makeCompiler({
tsJestConfig: {
...baseTsJestConfig,
isolatedModules: true,
tsconfig: {
isolatedModules: true,
},
},
})

Expand Down Expand Up @@ -111,7 +113,15 @@ describe('TsCompiler', () => {
},
])('should transpile code with config %p', ({ useESM, babelConfig, supportsStaticESM }) => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM, babelConfig },
tsJestConfig: {
...baseTsJestConfig,
useESM,
babelConfig,
tsconfig: {
isolatedModules: true,
customConditions: ['my-condition'],
},
},
})
const transformersStub = {
before: [],
Expand All @@ -138,12 +148,19 @@ describe('TsCompiler', () => {
module: usedCompilerOptions.module,
esModuleInterop: usedCompilerOptions.esModuleInterop,
allowSyntheticDefaultImports: usedCompilerOptions.allowSyntheticDefaultImports,
customConditions: usedCompilerOptions.customConditions,
}).toMatchSnapshot()
})

test.each([true, false])('should report diagnostics if shouldReportDiagnostics is %p', (shouldReport) => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM: false },
tsJestConfig: {
...baseTsJestConfig,
useESM: false,
tsconfig: {
isolatedModules: true,
},
},
})
compiler.configSet.raiseDiagnostics = jest.fn()
compiler.configSet.shouldReportDiagnostics = jest.fn().mockReturnValue(shouldReport)
Expand Down Expand Up @@ -227,6 +244,7 @@ describe('TsCompiler', () => {
tsconfig: {
module: moduleValue as unknown as RawCompilerOptions['module'],
esModuleInterop: false,
customConditions: ['my-condition'],
},
},
})
Expand All @@ -253,6 +271,7 @@ describe('TsCompiler', () => {
expect(usedCompilerOptions.module).toBe(expectedModule)
expect(usedCompilerOptions.esModuleInterop).toBe(expectedEsModuleInterop)
expect(usedCompilerOptions.moduleResolution).toBe(ts.ModuleResolutionKind.Node10)
expect(usedCompilerOptions.customConditions).toBeUndefined()
expect(output).toEqual({
code: updateOutput(jsOutput, fileName, sourceMap),
diagnostics: [],
Expand Down Expand Up @@ -355,7 +374,13 @@ describe('TsCompiler', () => {
describe('_makeTransformers', () => {
test('should return the transformers object which contains before, after and afterDeclarations transformers', () => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM: false },
tsJestConfig: {
...baseTsJestConfig,
useESM: false,
tsconfig: {
isolatedModules: true,
},
},
})
const transformerStub = join(mockFolder, 'dummy-transformer.js')
console.log = jest.fn()
Expand Down Expand Up @@ -395,7 +420,12 @@ describe('TsCompiler', () => {
const fileName = join(mockFolder, 'thing.ts')
const fileContent = 'const bar = 1'
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true },
tsJestConfig: {
...baseTsJestConfig,
tsconfig: {
isolatedModules: true,
},
},
})
const fileContentCache = new Map<string, string>()
const fileVersionCache = new Map<string, number>()
Expand Down
8 changes: 8 additions & 0 deletions src/legacy/compiler/ts-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export class TsCompiler implements TsCompilerInstance {
...compilerOptions,
module: this._ts.ModuleKind.CommonJS,
moduleResolution,
/**
* This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
*/
customConditions: undefined,
}
}

Expand All @@ -168,6 +172,10 @@ export class TsCompiler implements TsCompilerInstance {
module: moduleKind,
esModuleInterop,
moduleResolution,
/**
* This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
*/
customConditions: undefined,
}
}

Expand Down