Skip to content

Commit 78a53c2

Browse files
authored
fix(config): support babel config file path as string (#1332)
fix(config): support babel config file path as string
1 parent 01615fd commit 78a53c2

19 files changed

+5394
-18
lines changed

docs/user/config/babelConfig.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Babel Config option
77
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:
88

99
- `false`: the default, disables the use of Babel
10-
- `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.
10+
- `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.
1111
- `{ ... }`: 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.
1212

1313
### Examples
@@ -30,7 +30,7 @@ module.exports = {
3030

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

33-
```js
33+
```json5
3434
// OR package.json
3535
{
3636
// [...]
@@ -63,10 +63,20 @@ module.exports = {
6363
}
6464
};
6565
```
66-
66+
```js
67+
// OR jest.config.js with require for babelrc
68+
module.exports = {
69+
// [...]
70+
globals: {
71+
'ts-jest': {
72+
babelConfig: require('./babelrc.test.js'),
73+
}
74+
}
75+
};
76+
```
6777
</div><div class="col-md-6" markdown="block">
6878

69-
```js
79+
```json5
7080
// OR package.json
7181
{
7282
// [...]
@@ -105,7 +115,7 @@ module.exports = {
105115

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

108-
```js
118+
```json5
109119
// OR package.json
110120
{
111121
// [...]

e2e/__helpers__/templates.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export enum PackageSets {
22
default = 'default',
33
babel7 = 'with-babel-7',
4+
babel7StringConfig = 'with-babel-7-string-config',
45
typescript2_7 = 'with-typescript-2-7',
56
// invalid
67
unsupportedVersion = 'with-unsupported-version',
78
}
8-
export const allValidPackageSets = [PackageSets.default, PackageSets.babel7, PackageSets.typescript2_7]
9-
export const allPackageSetsWithPreset = [PackageSets.default, PackageSets.babel7, PackageSets.typescript2_7]
9+
export const allValidPackageSets = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig, PackageSets.typescript2_7]
10+
export const allPackageSetsWithPreset = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig, PackageSets.typescript2_7]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module.exports = {
2+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
globals: { 'ts-jest': { tsConfig: {}, babelConfig: 'babel.config.js' } },
5+
}

0 commit comments

Comments
 (0)