Skip to content

Commit

Permalink
fix(config): support babel config file path as string (#1332)
Browse files Browse the repository at this point in the history
fix(config): support babel config file path as string
  • Loading branch information
ahnpnl authored Dec 31, 2019
1 parent 01615fd commit 78a53c2
Show file tree
Hide file tree
Showing 19 changed files with 5,394 additions and 18 deletions.
20 changes: 15 additions & 5 deletions docs/user/config/babelConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Babel Config option
The option is `babelConfig` and it works pretty much as the `tsConfig` option, except that it is disabled by default. Here is the possible values it can take:

- `false`: the default, disables the use of Babel
- `true`: enables Babel processing. `ts-jest` will try to find a `.babelrc`, `.babelrc.js` file or a `babel` section in the `package.json` file of your project and use it as the config to pass to `babel-jest` processor.
- `true`: enables Babel processing. `ts-jest` will try to find a `.babelrc`, `.babelrc.js`, `babel.config.js` file or a `babel` section in the `package.json` file of your project and use it as the config to pass to `babel-jest` processor.
- `{ ... }`: inline [Babel options](https://babeljs.io/docs/en/next/options). You can also set this to an empty object (`{}`) so that the default Babel config file is not used.

### Examples
Expand All @@ -30,7 +30,7 @@ module.exports = {

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

```js
```json5
// OR package.json
{
// [...]
Expand Down Expand Up @@ -63,10 +63,20 @@ module.exports = {
}
};
```

```js
// OR jest.config.js with require for babelrc
module.exports = {
// [...]
globals: {
'ts-jest': {
babelConfig: require('./babelrc.test.js'),
}
}
};
```
</div><div class="col-md-6" markdown="block">

```js
```json5
// OR package.json
{
// [...]
Expand Down Expand Up @@ -105,7 +115,7 @@ module.exports = {

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

```js
```json5
// OR package.json
{
// [...]
Expand Down
5 changes: 3 additions & 2 deletions e2e/__helpers__/templates.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export enum PackageSets {
default = 'default',
babel7 = 'with-babel-7',
babel7StringConfig = 'with-babel-7-string-config',
typescript2_7 = 'with-typescript-2-7',
// invalid
unsupportedVersion = 'with-unsupported-version',
}
export const allValidPackageSets = [PackageSets.default, PackageSets.babel7, PackageSets.typescript2_7]
export const allPackageSetsWithPreset = [PackageSets.default, PackageSets.babel7, PackageSets.typescript2_7]
export const allValidPackageSets = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig, PackageSets.typescript2_7]
export const allPackageSetsWithPreset = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig, PackageSets.typescript2_7]
2 changes: 2 additions & 0 deletions e2e/__templates__/with-babel-7-string-config/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = {
}
5 changes: 5 additions & 0 deletions e2e/__templates__/with-babel-7-string-config/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: { 'ts-jest': { tsConfig: {}, babelConfig: 'babel.config.js' } },
}
Loading

0 comments on commit 78a53c2

Please sign in to comment.