Skip to content
Permalink
Browse files

feat(config): add `tsconfig` alias to `tsConfig` option (#1565)

Co-authored-by: Ahn <anhpnnd@gmail.com>
  • Loading branch information
jedmao and ahnpnl committed Apr 28, 2020
1 parent 4ab3265 commit c10eb6d6641f62c649ea3c65a34635f379efa21c
Showing with 62 additions and 32 deletions.
  1. +4 −4 docs/user/config/index.md
  2. +6 −4 docs/user/config/tsConfig.md
  3. +2 −2 src/config/config-set.spec.ts
  4. +2 −2 src/config/config-set.ts
  5. +48 −20 src/types.ts
@@ -188,10 +188,10 @@ All options have default values which should fit most of the projects. Click on
| Option | Description | Type | Default |
|---|---|---|---|
| [**`compiler`**][compiler] | [TypeScript module to use as compiler.][compiler] | `string` | `"typescript"` |
| [**`tsConfig`**][tsConfig] | [TypeScript compiler related configuration.][tsConfig] | `string`\|`object`\|`boolean` | _auto_ |
| [**`isolatedModules`**][isolatedModules] | [Disable type-checking][isolatedModules] | `boolean` | `false` |
| [**`diagnostics`**][diagnostics] | [Diagnostics related configuration.][diagnostics] | `boolean`\|`object` | `true` |
| [**`babelConfig`**][babelConfig] | [Babel(Jest) related configuration.][babelConfig] | `boolean`\|`object` | _disabled_ |
| [**`tsConfig` or `tsconfig`**][tsConfig] | [TypeScript compiler related configuration.][tsConfig] | `string`\|`object`\|`boolean` | _auto_ |
| [**`isolatedModules`**][isolatedModules] | [Disable type-checking][isolatedModules] | `boolean` | _disabled_ |
| [**`diagnostics`**][diagnostics] | [Diagnostics related configuration.][diagnostics] | `boolean`\|`object` | _enabled_ |
| [**`babelConfig`**][babelConfig] | [Babel(Jest) related configuration.][babelConfig] | `boolean`\|`string`\|`object` | _disabled_ |
| [**`stringifyContentPathRegex`**][stringifyContentPathRegex] | [Files which will become modules returning self content.][stringifyContentPathRegex] | `string`\|`RegExp` | _disabled_ |
| [**`packageJson`**][packageJson] | [Package metadata.][packageJson] | `string`\|`object`\|`boolean` | _auto_ |

@@ -2,9 +2,9 @@
title: TypeScript Config option
---

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.
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.

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`).
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`.

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`.

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

#### Inline compiler options

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

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

#### Disable auto-lookup

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`.
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`.

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

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

</div></div>

[compiler options]: https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options
@@ -478,8 +478,8 @@ describe('typescript', () => {
expect(get().fileNames).toContain(normalizeSlashes(__filename))
})

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

it('should include compiler config from base config', () => {
@@ -222,9 +222,9 @@ export class ConfigSet {
const options: TsJestGlobalOptions = { ...globals['ts-jest'] }

// tsconfig
const { tsConfig: tsConfigOpt } = options
const tsConfigOpt = options.tsConfig ?? options.tsconfig ?? true
let tsConfig: TsJestConfig['tsConfig']
if (typeof tsConfigOpt === 'string' || tsConfigOpt == null || tsConfigOpt === true) {
if (typeof tsConfigOpt === 'string' || tsConfigOpt === true) {
tsConfig = {
kind: 'file',
value: typeof tsConfigOpt === 'string' ? this.resolvePath(tsConfigOpt) : undefined,
@@ -30,28 +30,44 @@ export type BabelConfig = _babel.TransformOptions
export interface TsJestGlobalOptions {
/**
* Compiler options. It can be:
* - `true` (or `undefined`, it's the default): use default tsconfig file
* - `false`: do NOT use default config file
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
* - `{...}`: an object with inline compiler options
* - `true` (or `undefined`, it's the default): use default tsconfig file
* - `false`: do NOT use default config file
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
* - `{...}`: an object with inline compiler options
* @default undefined uses the default tsconfig file
* @alias tsconfig
*/
tsConfig?: boolean | string | _ts.CompilerOptions

/**
* Compiler options. It can be:
* - `true` (or `undefined`, it's the default): use default tsconfig file
* - `false`: do NOT use default config file
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
* - `{...}`: an object with inline compiler options
* @default undefined uses the default tsconfig file
* @alias tsConfig
*/
tsconfig?: boolean | string | _ts.CompilerOptions

/**
* packageJson. It can be:
* - `true` (or `undefined`, it's the default): use default package.json file
* - `path/to/package.json`: path to a specific package.json file (<rootDir> can be used)
* - `{...}`: contents of a package.json
* - `true` (or `undefined`, it's the default): use default package.json file
* - `path/to/package.json`: path to a specific package.json file (<rootDir> can be used)
* - `{...}`: contents of a package.json
* @default undefined uses the default package.json file
*/
packageJson?: boolean | string | object

/**
* Whether to compile files as isolated modules (disables some features and type-checking, default to `false`):
* Compiles files as isolated modules (disables some features and type-checking)
* @default undefined (disabled)
*/
isolatedModules?: boolean

/**
* Compiler to use (default to 'typescript'):
* Compiler to use
* @default 'typescript'
*/
compiler?: string

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

/**
* TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be:
* - `true` (or `undefined`, it's the default): show all diagnostics
* - `false`: hide diagnostics of all files (kind of useless)
* - `{...}`: an inline object with fine grained settings
* - `true` (or `undefined`, it's the default): show all diagnostics
* - `false`: hide diagnostics of all files (kind of useless)
* - `{...}`: an inline object with fine grained settings
* @default undefined shows all diagnostics
*/
diagnostics?:
| boolean
| {
/**
* Enables colorful and pretty output of errors
* @default undefined (enabled)
*/
pretty?: boolean
/**
* Ignore TypeScript warnings by diagnostic code.
* List of TypeScript diagnostic error codes to ignore
* [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
* @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
* @default [6059,18002,18003]
*/
ignoreCodes?: number | string | (number | string)[]
/**
* If specified, diagnostics of source files which path does **not** match
* will be ignored
*/
pathRegex?: RegExp | string
/**
* Logs TypeScript errors to stderr instead of throwing exceptions.
*
* @default false
* Logs TypeScript errors to stderr instead of throwing exceptions
* @default undefined (disabled)
*/
warnOnly?: boolean
}

/**
* Babel config. It can be:
* - `false` (or `undefined`, it's the default): do NOT use babel
* - `true`: use babel using default babelrc file
* - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
* - `{...}`: an object with inline babel options
* - `false` (or `undefined`, it's the default): do NOT use babel
* - `true`: use babel using default babelrc file
* - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
* - `{...}`: an object with inline babel options
* @default undefined does NOT use babel
*/
babelConfig?: boolean | string | BabelConfig

0 comments on commit c10eb6d

Please sign in to comment.
You can’t perform that action at this time.