Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): support babel config file path as string #1332

Merged
merged 5 commits into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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' } },
}