Skip to content

Commit

Permalink
feat(config): define 'ts-jest' on ConfigGlobals interface of `@jest…
Browse files Browse the repository at this point in the history
…/types` (#1592)
  • Loading branch information
ahnpnl authored May 4, 2020
1 parent 526265d commit 4526392
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
17 changes: 17 additions & 0 deletions docs/user/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ module.exports = {

</div></div>

#### IDE `ts-jest` config suggestion

To ultilize IDE suggestion, you can use `JSDOC` to provide suggested `ts-jest` configs for your Jest config:

```js
/** @type {import('@jest/types').Config.InitialOptions} */
/** @typedef {import('ts-jest')} */
module.exports = {
// [...]
globals: {
'ts-jest': {
// ts-jest configuration goes here and your IDE will suggest which configs when typing
}
}
};
```

### Options

All options have default values which should fit most of the projects. Click on the option's name to see details and example(s).
Expand Down
2 changes: 1 addition & 1 deletion e2e/__helpers__/test-case/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function run(name: string, options: RunTestOptions = {}): RunResult {
merge(extraConfig, options.jestConfig)
}
if (options.tsJestConfig) {
const globalConfig: any = extraConfig.globals || (extraConfig.globals = {})
const globalConfig: any = extraConfig.globals || (extraConfig.globals = {'ts-jest': {}})
const tsJestConfig = globalConfig['ts-jest'] || (globalConfig['ts-jest'] = {})
merge(tsJestConfig, options.tsJestConfig)
}
Expand Down
17 changes: 4 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import { Deprecateds, interpolate } from './util/messages'
import { mocked as mockedCore } from './util/testing'
import { VersionCheckers } from './util/version-checkers'

declare module '@jest/types' {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Config {
interface ConfigGlobals {
'ts-jest': TsJestGlobalOptions
}
}
}

// deprecate helpers
const warn = rootLogger.child({ [LogContexts.logLevel]: LogLevels.warn })
const helperMoved = <T extends (...args: any[]) => any>(name: string, helper: T) =>
Expand Down

0 comments on commit 4526392

Please sign in to comment.