diff --git a/resources/jestPreprocessor.js b/resources/jestPreprocessor.js index 52892f245c..1d3776899a 100644 --- a/resources/jestPreprocessor.js +++ b/resources/jestPreprocessor.js @@ -7,29 +7,18 @@ var typescript = require('typescript'); -module.exports = { - process: function(src, filePath) { - var compiled; - - var options = { - noEmitOnError: true, - target: typescript.ScriptTarget.ES2015, - module: typescript.ModuleKind.CommonJS, - strictNullChecks: true, - }; - - var host = typescript.createCompilerHost(options); - var program = typescript.createProgram([filePath], options, host); - - host.writeFile = (name, text) => compiled = text; - var emitResult = program.emit(); - var diagnostics = typescript.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); +var options = { + noEmitOnError: true, + target: typescript.ScriptTarget.ES2015, + module: typescript.ModuleKind.CommonJS, + strictNullChecks: true, +}; - if (diagnostics.length === 0) { - return compiled; +module.exports = { + process(src, path) { + if (path.endsWith('.ts') || path.endsWith('.tsx')) { + return typescript.transpile(src, options, path, []); } - - var report = typescript.formatDiagnostics(diagnostics, host); - throw new Error('Compiling ' + filePath + ' failed' + '\n' + report); - } + return src; + }, };