Skip to content

Commit b4ea435

Browse files
authored
Remove built-in Babel support
This updates code and tests to remove built-in Babel support. In the future, it needs to be opted in to, and @ava/babel needs to be installed besides AVA itself. Our tests have become quite muddled, and some of them require Babel to still be enabled, but that's all OK for now. * Remove outdated JSPM recipe * Update documentation to reflect the removal of built-in Babel * Move responsibility for power-assert to @ava/babel
1 parent 4953457 commit b4ea435

File tree

227 files changed

+812
-2321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+812
-2321
lines changed

contributing.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ The [`question` label](https://github.com/avajs/ava/labels/question) is a good p
2828

2929
You can use issue labels to discover issues you could help out with:
3030

31-
* [`babel` issues](https://github.com/avajs/ava/labels/babel) relate to our Babel infrastructure
3231
* [`blocked` issues](https://github.com/avajs/ava/labels/blocked) need help getting unstuck
3332
* [`bug` issues](https://github.com/avajs/ava/labels/bug) are known bugs we'd like to fix
3433
* [`enhancement` issues](https://github.com/avajs/ava/labels/enhancement) are features we're open to including

docs/01-writing-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ AVA tries to run test files with their current working directory set to the dire
1212

1313
Each test file is run in a separate Node.js process. This allows you to change the global state or overriding a built-in in one test file, without affecting another. It's also great for performance on modern multi-core processors, allowing multiple test files to execute in parallel.
1414

15-
AVA will set `process.env.NODE_ENV` to `test`, unless the `NODE_ENV` environment variable has been set. This is useful if the code you're testing has test defaults (for example when picking what database to connect to, or environment-specific Babel options). It may cause your code or its dependencies to behave differently though. Note that `'NODE_ENV' in process.env` will always be `true`.
15+
AVA will set `process.env.NODE_ENV` to `test`, unless the `NODE_ENV` environment variable has been set. This is useful if the code you're testing has test defaults (for example when picking what database to connect to). It may cause your code or its dependencies to behave differently though. Note that `'NODE_ENV' in process.env` will always be `true`.
1616

1717
## Declaring tests
1818

docs/03-assertions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test('skip assertion', t => {
8484

8585
## Enhanced assertion messages
8686

87-
AVA comes with [`power-assert`](https://github.com/power-assert-js/power-assert) built-in, giving you more descriptive assertion messages.
87+
Enabling [Babel](./recipes/babel.md) will also enable [`power-assert`](https://github.com/power-assert-js/power-assert), giving you more descriptive assertion messages.
8888

8989
Let's take this example, using Node's standard [`assert` library](https://nodejs.org/api/assert.html):
9090

docs/05-command-line.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ test(function foo(t) {
133133

134134
## Resetting AVA's cache
135135

136-
AVA caches the compiled test and helper files. It automatically recompiles these files when you change them. AVA tries its best to detect changes to your Babel configuration files, plugins and presets. If it seems like your latest Babel configuration isn't being applied, however, you can run AVA with the `--reset-cache` flag to reset AVA's cache. If set, all files in the `node_modules/.cache/ava` directory are deleted. Run AVA as normal to apply your new Babel configuration.
136+
AVA may cache certain files, especially when you use our [`@ava/babel`](https://github.com/avajs/babel) provider. If it seems like your latest changes aren't being picked up by AVA you can reset the cache by running:
137+
138+
```console
139+
npx ava reset-cache
140+
```
141+
142+
This deletes all files in the `node_modules/.cache/ava` directory.
137143

138144
## Reporters
139145

docs/06-configuration.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,16 @@ To ignore files, prefix the pattern with an `!` (exclamation mark).
2626
"*oo",
2727
"!foo"
2828
],
29-
"cache": true,
3029
"concurrency": 5,
3130
"failFast": true,
3231
"failWithoutAssertions": false,
3332
"environmentVariables": {
3433
"MY_ENVIRONMENT_VARIABLE": "some value"
3534
},
36-
"tap": true,
3735
"verbose": true,
38-
"compileEnhancements": false,
3936
"require": [
40-
"@babel/register"
41-
],
42-
"babel": {
43-
"extensions": ["js", "jsx"],
44-
"testOptions": {
45-
"babelrc": false
46-
}
47-
}
37+
"./my-helper-module.js"
38+
]
4839
}
4940
}
5041
```
@@ -53,8 +44,8 @@ Arguments passed to the CLI will always take precedence over the CLI options con
5344

5445
## Options
5546

56-
- `files`: an array of glob patterns to select test files. Files with an underscore prefix are ignored. By default only selects files with `js` extensions, even if the pattern matches other files. Specify `extensions` and `babel.extensions` to allow other file extensions
57-
- `helpers`: an array of glob patterns to select helper files. Files matched here are never considered as tests. By default only selects files with `js` extensions, even if the pattern matches other files. Specify `extensions` and `babel.extensions` to allow other file extensions
47+
- `files`: an array of glob patterns to select test files. Files with an underscore prefix are ignored. By default only selects files with `js` extensions, even if the pattern matches other files. Specify `extensions` to allow other file extensions
48+
- `helpers`: an array of glob patterns to select helper files. Files matched here are never considered as tests. By default only selects files with `js` extensions, even if the pattern matches other files. Specify `extensions` to allow other file extensions
5849
- `sources`: an array of glob patterns to match files that, when changed, cause tests to be re-run (when in watch mode). See the [watch mode recipe for details](https://github.com/avajs/ava/blob/master/docs/recipes/watch-mode.md#source-files-and-test-files)
5950
- `match`: not typically useful in the `package.json` configuration, but equivalent to [specifying `--match` on the CLI](./05-command-line.md#running-tests-with-matching-titles)
6051
- `cache`: cache compiled test and helper files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead
@@ -64,15 +55,14 @@ Arguments passed to the CLI will always take precedence over the CLI options con
6455
- `tap`: if `true`, enables the [TAP reporter](./05-command-line.md#tap-reporter)
6556
- `verbose`: if `true`, enables verbose output
6657
- `snapshotDir`: specifies a fixed location for storing snapshot files. Use this if your snapshots are ending up in the wrong location
67-
- `compileEnhancements`: if `false`, disables [`power-assert`](./03-assertions.md#enhanced-assertion-messages) — which otherwise helps provide more descriptive error messages — and detection of improper use of the `t.throws()` assertion
68-
- `extensions`: extensions of test files that are not precompiled using AVA's Babel presets. Note that files are still compiled to enable `power-assert` and other features, so you may also need to set `compileEnhancements` to `false` if your files are not valid JavaScript. Setting this overrides the default `"js"` value, so make sure to include that extension in the list, as long as it's not included in `babel.extensions`
58+
- `extensions`: extensions of test files. Setting this overrides the default `"js"` value, so make sure to include that extension in the list
6959
- `require`: extra modules to require before tests are run. Modules are required in the [worker processes](./01-writing-tests.md#process-isolation)
70-
- `babel`: test file specific Babel options. See our [Babel recipe](./recipes/babel.md#configuring-babel) for more details
71-
- `babel.extensions`: extensions of test files that will be precompiled using AVA's Babel presets. Setting this overrides the default `"js"` value, so make sure to include that extension in the list
7260
- `timeout`: Timeouts in AVA behave differently than in other test frameworks. AVA resets a timer after each test, forcing tests to quit if no new test results were received within the specified timeout. This can be used to handle stalled tests. See our [timeout documentation](./07-test-timeouts.md) for more options.
7361

7462
Note that providing files on the CLI overrides the `files` option.
7563

64+
Provide the `babel` option (and install [`@ava/babel`](https://github.com/avajs/babel) as an additional dependency) to enable Babel compilation.
65+
7666
## Using `ava.config.js`
7767

7868
To use an `ava.config.js` file:

docs/08-common-pitfalls.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/do
44

55
If you use [ESLint](http://eslint.org/), you can install [eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava). It will help you use AVA correctly and avoid some common pitfalls.
66

7-
## Transpiling imported modules
8-
9-
AVA currently only transpiles test and helper files. *It will not transpile modules you `import` from outside of the test.* This may be unexpected but there are workarounds.
10-
11-
If you use Babel you can use its [require hook](https://babeljs.io/docs/usage/require/) to transpile imported modules on-the-fly. To add it, [configure it in your `package.json`](./06-configuration.md).
12-
13-
You can also transpile your modules in a separate process and refer to the transpiled files rather than the sources from your tests.
14-
157
## AVA in Docker
168

179
If you run AVA in Docker as part of your CI, you need to fix the appropriate environment variables. Specifically, adding `-e CI=true` in the `docker exec` command. See [#751](https://github.com/avajs/ava/issues/751).
@@ -81,6 +73,8 @@ test('one is one', t => {
8173
});
8274
```
8375

76+
Also make sure to enable [Babel](./recipes/babel.md).
77+
8478
## Sharing variables between asynchronous tests
8579

8680
By default AVA executes tests concurrently. This can cause problems if your tests are asynchronous and share variables.

0 commit comments

Comments
 (0)