Skip to content

Commit

Permalink
fix: correct error handling in processAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and Anh Pham committed Jan 19, 2024
1 parent e31d953 commit 2ebf2c1
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/legacy/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,31 +189,29 @@ export class TsJestTransformer implements SyncTransformer {
): Promise<TransformedSource> {
this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath)

return new Promise(async (resolve, reject) => {
const configs = this._configsFor(transformOptions)
const shouldStringifyContent = configs.shouldStringifyContent(sourcePath)
const babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer
let result: TransformedSource
const processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions)
result = {
code: processWithTsResult.code,
}
if (processWithTsResult.diagnostics?.length) {
reject(configs.createTsError(processWithTsResult.diagnostics))
}
if (babelJest) {
this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor')
const configs = this._configsFor(transformOptions)
const shouldStringifyContent = configs.shouldStringifyContent(sourcePath)
const babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer
let result: TransformedSource
const processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions)
result = {
code: processWithTsResult.code,
}
if (processWithTsResult.diagnostics?.length) {
throw configs.createTsError(processWithTsResult.diagnostics)
}
if (babelJest) {
this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor')

// do not instrument here, jest will do it anyway afterwards
result = await babelJest.processAsync(result.code, sourcePath, {
...transformOptions,
instrument: false,
})
}
result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result)
// do not instrument here, jest will do it anyway afterwards
result = await babelJest.processAsync(result.code, sourcePath, {
...transformOptions,
instrument: false,
})
}
result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result)

resolve(result)
})
return result
}

private processWithTs(
Expand Down

0 comments on commit 2ebf2c1

Please sign in to comment.