Skip to content

Commit d16e78c

Browse files
kwelchazz
authored andcommitted
feat: update runner to load tsconfig from jest rootDir (#3)
1 parent a73556e commit d16e78c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/runTsc.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path');
12
const codeFrame = require('@babel/code-frame').codeFrameColumns;
23
const ts = require('typescript');
34
const fs = require('fs');
@@ -46,12 +47,31 @@ const convertErrors = ({ start, end, errors, testPath }) => ({
4647
),
4748
});
4849

49-
const runTsc = ({ testPath /*, config */ }, workerCallback) => {
50+
const runTsc = ({ testPath, config: jestConfig }, workerCallback) => {
5051
try {
52+
const configPath = path.resolve(jestConfig.rootDir, 'tsconfig.json');
53+
const configContents = fs.readFileSync(configPath).toString();
54+
const { config, error } = ts.parseConfigFileTextToJson(
55+
configPath,
56+
configContents
57+
);
58+
59+
if (error) {
60+
return {
61+
errorMessage: error,
62+
filePath: testPath,
63+
};
64+
}
65+
66+
const settings = ts.convertCompilerOptionsFromJson(
67+
config['compilerOptions'] || {},
68+
process.cwd()
69+
);
70+
71+
const options = Object.assign({}, { noEmit: true }, settings.options);
72+
5173
const start = +new Date();
52-
const program = ts.createProgram([testPath], {
53-
noEmit: true,
54-
});
74+
const program = ts.createProgram([testPath], options);
5575

5676
const emitResult = program.emit();
5777

0 commit comments

Comments
 (0)