Skip to content

Commit c10eb6d

Browse files
jedmaoahnpnl
andauthoredApr 28, 2020
feat(config): add tsconfig alias to tsConfig option (#1565)
Co-authored-by: Ahn <anhpnnd@gmail.com>
1 parent 4ab3265 commit c10eb6d

File tree

5 files changed

+62
-32
lines changed

5 files changed

+62
-32
lines changed
 

‎docs/user/config/index.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ All options have default values which should fit most of the projects. Click on
188188
| Option | Description | Type | Default |
189189
|---|---|---|---|
190190
| [**`compiler`**][compiler] | [TypeScript module to use as compiler.][compiler] | `string` | `"typescript"` |
191-
| [**`tsConfig`**][tsConfig] | [TypeScript compiler related configuration.][tsConfig] | `string`\|`object`\|`boolean` | _auto_ |
192-
| [**`isolatedModules`**][isolatedModules] | [Disable type-checking][isolatedModules] | `boolean` | `false` |
193-
| [**`diagnostics`**][diagnostics] | [Diagnostics related configuration.][diagnostics] | `boolean`\|`object` | `true` |
194-
| [**`babelConfig`**][babelConfig] | [Babel(Jest) related configuration.][babelConfig] | `boolean`\|`object` | _disabled_ |
191+
| [**`tsConfig` or `tsconfig`**][tsConfig] | [TypeScript compiler related configuration.][tsConfig] | `string`\|`object`\|`boolean` | _auto_ |
192+
| [**`isolatedModules`**][isolatedModules] | [Disable type-checking][isolatedModules] | `boolean` | _disabled_ |
193+
| [**`diagnostics`**][diagnostics] | [Diagnostics related configuration.][diagnostics] | `boolean`\|`object` | _enabled_ |
194+
| [**`babelConfig`**][babelConfig] | [Babel(Jest) related configuration.][babelConfig] | `boolean`\|`string`\|`object` | _disabled_ |
195195
| [**`stringifyContentPathRegex`**][stringifyContentPathRegex] | [Files which will become modules returning self content.][stringifyContentPathRegex] | `string`\|`RegExp` | _disabled_ |
196196
| [**`packageJson`**][packageJson] | [Package metadata.][packageJson] | `string`\|`object`\|`boolean` | _auto_ |
197197

‎docs/user/config/tsConfig.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
title: TypeScript Config option
33
---
44

5-
The `tsConfig` option allows you to define the which `tsconfig` JSON file to use. An inline compiler options object can also be specified instead of the path to a file.
5+
The `tsConfig` option (alias `tsconfig`) allows you to define which `tsconfig` JSON file to use. An inline [compiler options][] object can also be specified instead of a file path.
66

7-
By default, it'll use the default TypeScript and use the project's `tsconfig.json` file. If it cannot find one, it'll use defaults TypeScript compiler options (except `es5` is used as target instead of `es3`).
7+
By default `ts-jest` will try to find a `tsconfig.json` in your project. If it cannot find one, it will use the default TypeScript [compiler options][]; except, `ES5` is used as `target` instead of `ES3`.
88

99
If you need to use defaults and force `ts-jest` to use the defaults even if there is a `tsconfig.json` in your project, you can set this option to `false`.
1010

@@ -48,7 +48,7 @@ module.exports = {
4848

4949
#### Inline compiler options
5050

51-
Refer to the [TypeScript compiler options](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to know what can be used.
51+
Refer to the TypeScript [compiler options][] for reference.
5252
It's basically the same object you'd put in your `tsconfig.json`'s `compilerOptions`.
5353

5454
<div class="row"><div class="col-md-6" markdown="block">
@@ -89,7 +89,7 @@ module.exports = {
8989

9090
#### Disable auto-lookup
9191

92-
By default `ts-jest` will try to find the `tsconfig.json` in your project. But you may want to not use it at all and keep TypeScript default options. You can achieve this by setting `tsConfig` to `false`.
92+
By default `ts-jest` will try to find a `tsconfig.json` in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting `tsConfig` to `false`.
9393

9494
<div class="row"><div class="col-md-6" markdown="block">
9595

@@ -122,3 +122,5 @@ module.exports = {
122122
```
123123

124124
</div></div>
125+
126+
[compiler options]: https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options

‎src/config/config-set.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ describe('typescript', () => {
478478
expect(get().fileNames).toContain(normalizeSlashes(__filename))
479479
})
480480

481-
it('should include compiler config from `tsConfig` option key', () => {
482-
expect(get({ tsConfig: { baseUrl: 'src/config' } }).options.baseUrl).toBe(normalizeSlashes(__dirname))
481+
it.each(['tsConfig', 'tsconfig'])('should include compiler config from `%s` option key', (key: string) => {
482+
expect(get({ [key]: { baseUrl: 'src/config' } }).options.baseUrl).toBe(normalizeSlashes(__dirname))
483483
})
484484

485485
it('should include compiler config from base config', () => {

‎src/config/config-set.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ export class ConfigSet {
222222
const options: TsJestGlobalOptions = { ...globals['ts-jest'] }
223223

224224
// tsconfig
225-
const { tsConfig: tsConfigOpt } = options
225+
const tsConfigOpt = options.tsConfig ?? options.tsconfig ?? true
226226
let tsConfig: TsJestConfig['tsConfig']
227-
if (typeof tsConfigOpt === 'string' || tsConfigOpt == null || tsConfigOpt === true) {
227+
if (typeof tsConfigOpt === 'string' || tsConfigOpt === true) {
228228
tsConfig = {
229229
kind: 'file',
230230
value: typeof tsConfigOpt === 'string' ? this.resolvePath(tsConfigOpt) : undefined,

‎src/types.ts

+48-20
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,44 @@ export type BabelConfig = _babel.TransformOptions
3030
export interface TsJestGlobalOptions {
3131
/**
3232
* Compiler options. It can be:
33-
* - `true` (or `undefined`, it's the default): use default tsconfig file
34-
* - `false`: do NOT use default config file
35-
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
36-
* - `{...}`: an object with inline compiler options
33+
* - `true` (or `undefined`, it's the default): use default tsconfig file
34+
* - `false`: do NOT use default config file
35+
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
36+
* - `{...}`: an object with inline compiler options
37+
* @default undefined uses the default tsconfig file
38+
* @alias tsconfig
3739
*/
3840
tsConfig?: boolean | string | _ts.CompilerOptions
3941

42+
/**
43+
* Compiler options. It can be:
44+
* - `true` (or `undefined`, it's the default): use default tsconfig file
45+
* - `false`: do NOT use default config file
46+
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
47+
* - `{...}`: an object with inline compiler options
48+
* @default undefined uses the default tsconfig file
49+
* @alias tsConfig
50+
*/
51+
tsconfig?: boolean | string | _ts.CompilerOptions
52+
4053
/**
4154
* packageJson. It can be:
42-
* - `true` (or `undefined`, it's the default): use default package.json file
43-
* - `path/to/package.json`: path to a specific package.json file (<rootDir> can be used)
44-
* - `{...}`: contents of a package.json
55+
* - `true` (or `undefined`, it's the default): use default package.json file
56+
* - `path/to/package.json`: path to a specific package.json file (<rootDir> can be used)
57+
* - `{...}`: contents of a package.json
58+
* @default undefined uses the default package.json file
4559
*/
4660
packageJson?: boolean | string | object
4761

4862
/**
49-
* Whether to compile files as isolated modules (disables some features and type-checking, default to `false`):
63+
* Compiles files as isolated modules (disables some features and type-checking)
64+
* @default undefined (disabled)
5065
*/
5166
isolatedModules?: boolean
5267

5368
/**
54-
* Compiler to use (default to 'typescript'):
69+
* Compiler to use
70+
* @default 'typescript'
5571
*/
5672
compiler?: string
5773

@@ -62,33 +78,45 @@ export interface TsJestGlobalOptions {
6278

6379
/**
6480
* TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be:
65-
* - `true` (or `undefined`, it's the default): show all diagnostics
66-
* - `false`: hide diagnostics of all files (kind of useless)
67-
* - `{...}`: an inline object with fine grained settings
81+
* - `true` (or `undefined`, it's the default): show all diagnostics
82+
* - `false`: hide diagnostics of all files (kind of useless)
83+
* - `{...}`: an inline object with fine grained settings
84+
* @default undefined shows all diagnostics
6885
*/
6986
diagnostics?:
7087
| boolean
7188
| {
89+
/**
90+
* Enables colorful and pretty output of errors
91+
* @default undefined (enabled)
92+
*/
7293
pretty?: boolean
7394
/**
74-
* Ignore TypeScript warnings by diagnostic code.
95+
* List of TypeScript diagnostic error codes to ignore
96+
* [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
97+
* @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
98+
* @default [6059,18002,18003]
7599
*/
76100
ignoreCodes?: number | string | (number | string)[]
101+
/**
102+
* If specified, diagnostics of source files which path does **not** match
103+
* will be ignored
104+
*/
77105
pathRegex?: RegExp | string
78106
/**
79-
* Logs TypeScript errors to stderr instead of throwing exceptions.
80-
*
81-
* @default false
107+
* Logs TypeScript errors to stderr instead of throwing exceptions
108+
* @default undefined (disabled)
82109
*/
83110
warnOnly?: boolean
84111
}
85112

86113
/**
87114
* Babel config. It can be:
88-
* - `false` (or `undefined`, it's the default): do NOT use babel
89-
* - `true`: use babel using default babelrc file
90-
* - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
91-
* - `{...}`: an object with inline babel options
115+
* - `false` (or `undefined`, it's the default): do NOT use babel
116+
* - `true`: use babel using default babelrc file
117+
* - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
118+
* - `{...}`: an object with inline babel options
119+
* @default undefined does NOT use babel
92120
*/
93121
babelConfig?: boolean | string | BabelConfig
94122

0 commit comments

Comments
 (0)
Please sign in to comment.