Skip to content

Commit

Permalink
chore: Use custom tsconfig for ts-jest
Browse files Browse the repository at this point in the history
By default, `ts-jest` will use `tsconfig.json` for TypeScript configuration.

Our `tsconfig.json` sets `noUnusedLocals` to `true`.
This means compilation will fail if we import something and don't use it.

If you're running tests locally (using `script/start`, for example)
and comment out a block of code that results in an import not being used,
a compile error will result and the tests will not run until resolved.

In reality you are going to use it, so you end up temporarily commenting out the import
(once you've expanded them as the IDE collapses them 😅)

This whole process is slow.

In this change we instruct `ts-jest` to use a custom configuration,
specifically allowing unused locals.
This results in `jest` no longer complaining about unused imports and a faster feedback loop.

Unused locals will continue to get caught in the compile and lint steps, which are run in CI.
That is, this change simply improves the experience when running the tests.

See:
  - https://www.typescriptlang.org/tsconfig#noUnusedLocals
  - https://huafu.github.io/ts-jest/user/config/tsConfig
  • Loading branch information
akash1810 committed May 24, 2021
1 parent d902d64 commit e90b52d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ module.exports = {
- #448
*/
modulePathIgnorePatterns: ["<rootDir>/lib"],
globals: {
"ts-jest": {
tsconfig: "tsconfig.test.json",
},
},
};
6 changes: 6 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noUnusedLocals": false
}
}

0 comments on commit e90b52d

Please sign in to comment.