Skip to content

Commit

Permalink
Merge pull request #427 from alan-agius4/feature/emit-error
Browse files Browse the repository at this point in the history
feat: add option to run TypeScript diagnostics
  • Loading branch information
kulshekhar committed Feb 3, 2018
2 parents 17c2862 + 32ac27c commit 8350b4f
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 225 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#
# Name/Organization <email address>

Alan Agius <[email protected]>
Alex Jover Morales <[email protected]>
Andreas Krummsdorf <[email protected]>
Anonymous <[email protected]>
Bartosz Gościński <[email protected]>
Blake Embrey <[email protected]>
Bnaya Peretz <[email protected]>
Brian Ruddy <[email protected]>
Chong Guo <[email protected]>
Chris Sauve <[email protected]>
Expand Down Expand Up @@ -46,5 +48,6 @@ Rikki Tooley <[email protected]>
Simen Bekkhus <[email protected]>
Thomas Fontaine <[email protected]>
Tom Crockett <[email protected]>
Tony Valderrama <[email protected]>
Trivikram Kamat <[email protected]>
Umidbek Karimov <[email protected]>
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,19 @@ By default Jest ignores everything in `node_modules`. This setting prevents Jest
}
```
### TS compiler && error reporting
- ts-jest only returns syntax errors from [tsc](https://github.com/Microsoft/TypeScript/issues/4864#issuecomment-141567247)
- Non syntactic errors do not show up in [jest](https://github.com/facebook/jest/issues/2168)
- If you only want to run jest if tsc does not output any errors, a workaround is `tsc --noEmit -p . && jest`
If you want to enable Syntactic & Semantic TypeScript error reporting you can enable this through `enableTsDiagnostics` flag;

```json
{
"jest": {
"globals": {
"ts-jest": {
"enableTsDiagnostics": true
}
}
}
}
```

### Known Limitations for hoisting
If the `jest.mock()` calls is placed after actual code, (e.g. after functions or classes) and `skipBabel` is not set,
Expand Down
11 changes: 1 addition & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-jest",
"version": "22.0.2",
"version": "22.0.3",
"main": "index.js",
"types": "./dist/index.d.ts",
"description": "A preprocessor with sourcemap support to help use Typescript with Jest",
Expand Down Expand Up @@ -30,15 +30,6 @@
"testing"
],
"author": "Kulshekhar Kabra <[email protected]> (https://github.com/kulshekhar)",
"contributors": [
"Bnaya Peretz <[email protected]> (https://github.com/Bnaya)",
"Brian Ruddy <[email protected]> (https://github.com/bcruddy)",
"Emil Persson <[email protected]> (https://github.com/emilniklas)",
"Gustav Wengel <[email protected]>(https://github.com/GeeWee)",
"Ihor Chulinda <[email protected]> (https://github.com/Igmat)",
"OJ Kwon <[email protected]> (https://github.com/kwonoj)",
"Tony Valderrama <[email protected]> (https://github.com/tvald)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/kulshekhar/ts-jest/issues"
Expand Down
1 change: 1 addition & 0 deletions src/jest-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ export interface TsJestConfig {
babelConfig?: BabelTransformOpts;
tsConfigFile?: string;
enableInternalCache?: boolean;
enableTsDiagnostics?: boolean;
}
11 changes: 8 additions & 3 deletions src/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
cacheFile,
getTSConfig,
getTSJestConfig,
runTsDiagnostics,
injectSourcemapHook,
} from './utils';

Expand Down Expand Up @@ -41,14 +42,18 @@ export function process(
return src;
}

const tsJestConfig = getTSJestConfig(jestConfig.globals);
logOnce('tsJestConfig: ', tsJestConfig);

if (tsJestConfig.enableTsDiagnostics) {
runTsDiagnostics(filePath, compilerOptions);
}

const tsTranspiled = tsc.transpileModule(src, {
compilerOptions,
fileName: filePath,
});

const tsJestConfig = getTSJestConfig(jestConfig.globals);
logOnce('tsJestConfig: ', tsJestConfig);

const postHook = getPostProcessHook(
compilerOptions,
jestConfig,
Expand Down
Loading

0 comments on commit 8350b4f

Please sign in to comment.