Skip to content

Commit

Permalink
Remove built-in Babel support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
novemberborn committed Dec 24, 2019
1 parent 4953457 commit b4ea435
Show file tree
Hide file tree
Showing 227 changed files with 812 additions and 2,321 deletions.
1 change: 0 additions & 1 deletion contributing.md
Expand Up @@ -28,7 +28,6 @@ The [`question` label](https://github.com/avajs/ava/labels/question) is a good p


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


* [`babel` issues](https://github.com/avajs/ava/labels/babel) relate to our Babel infrastructure
* [`blocked` issues](https://github.com/avajs/ava/labels/blocked) need help getting unstuck * [`blocked` issues](https://github.com/avajs/ava/labels/blocked) need help getting unstuck
* [`bug` issues](https://github.com/avajs/ava/labels/bug) are known bugs we'd like to fix * [`bug` issues](https://github.com/avajs/ava/labels/bug) are known bugs we'd like to fix
* [`enhancement` issues](https://github.com/avajs/ava/labels/enhancement) are features we're open to including * [`enhancement` issues](https://github.com/avajs/ava/labels/enhancement) are features we're open to including
Expand Down
2 changes: 1 addition & 1 deletion docs/01-writing-tests.md
Expand Up @@ -12,7 +12,7 @@ AVA tries to run test files with their current working directory set to the dire


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


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


## Declaring tests ## Declaring tests


Expand Down
2 changes: 1 addition & 1 deletion docs/03-assertions.md
Expand Up @@ -84,7 +84,7 @@ test('skip assertion', t => {


## Enhanced assertion messages ## Enhanced assertion messages


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


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


Expand Down
8 changes: 7 additions & 1 deletion docs/05-command-line.md
Expand Up @@ -133,7 +133,13 @@ test(function foo(t) {


## Resetting AVA's cache ## Resetting AVA's cache


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

```console
npx ava reset-cache
```

This deletes all files in the `node_modules/.cache/ava` directory.


## Reporters ## Reporters


Expand Down
24 changes: 7 additions & 17 deletions docs/06-configuration.md
Expand Up @@ -26,25 +26,16 @@ To ignore files, prefix the pattern with an `!` (exclamation mark).
"*oo", "*oo",
"!foo" "!foo"
], ],
"cache": true,
"concurrency": 5, "concurrency": 5,
"failFast": true, "failFast": true,
"failWithoutAssertions": false, "failWithoutAssertions": false,
"environmentVariables": { "environmentVariables": {
"MY_ENVIRONMENT_VARIABLE": "some value" "MY_ENVIRONMENT_VARIABLE": "some value"
}, },
"tap": true,
"verbose": true, "verbose": true,
"compileEnhancements": false,
"require": [ "require": [
"@babel/register" "./my-helper-module.js"
], ]
"babel": {
"extensions": ["js", "jsx"],
"testOptions": {
"babelrc": false
}
}
} }
} }
``` ```
Expand All @@ -53,8 +44,8 @@ Arguments passed to the CLI will always take precedence over the CLI options con


## Options ## Options


- `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 - `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
- `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 - `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
- `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) - `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)
- `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) - `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)
- `cache`: cache compiled test and helper files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead - `cache`: cache compiled test and helper files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead
Expand All @@ -64,15 +55,14 @@ Arguments passed to the CLI will always take precedence over the CLI options con
- `tap`: if `true`, enables the [TAP reporter](./05-command-line.md#tap-reporter) - `tap`: if `true`, enables the [TAP reporter](./05-command-line.md#tap-reporter)
- `verbose`: if `true`, enables verbose output - `verbose`: if `true`, enables verbose output
- `snapshotDir`: specifies a fixed location for storing snapshot files. Use this if your snapshots are ending up in the wrong location - `snapshotDir`: specifies a fixed location for storing snapshot files. Use this if your snapshots are ending up in the wrong location
- `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 - `extensions`: extensions of test files. Setting this overrides the default `"js"` value, so make sure to include that extension in the list
- `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`
- `require`: extra modules to require before tests are run. Modules are required in the [worker processes](./01-writing-tests.md#process-isolation) - `require`: extra modules to require before tests are run. Modules are required in the [worker processes](./01-writing-tests.md#process-isolation)
- `babel`: test file specific Babel options. See our [Babel recipe](./recipes/babel.md#configuring-babel) for more details
- `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
- `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. - `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.


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


Provide the `babel` option (and install [`@ava/babel`](https://github.com/avajs/babel) as an additional dependency) to enable Babel compilation.

## Using `ava.config.js` ## Using `ava.config.js`


To use an `ava.config.js` file: To use an `ava.config.js` file:
Expand Down
10 changes: 2 additions & 8 deletions docs/08-common-pitfalls.md
Expand Up @@ -4,14 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/do


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


## Transpiling imported modules

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.

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

You can also transpile your modules in a separate process and refer to the transpiled files rather than the sources from your tests.

## AVA in Docker ## AVA in Docker


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). 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).
Expand Down Expand Up @@ -81,6 +73,8 @@ test('one is one', t => {
}); });
``` ```


Also make sure to enable [Babel](./recipes/babel.md).

## Sharing variables between asynchronous tests ## Sharing variables between asynchronous tests


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

0 comments on commit b4ea435

Please sign in to comment.