Skip to content

Commit

Permalink
Use babel-preset-node6 on Node.js 6 and higher
Browse files Browse the repository at this point in the history
Less transpilation, better performance, better stack traces, and less dependencies \o/
  • Loading branch information
sindresorhus committed Nov 22, 2016
1 parent fa82a24 commit 5158ac8
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 23 deletions.
14 changes: 7 additions & 7 deletions docs/recipes/babelrc.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ There are multiple options for configuring how AVA transpiles your tests using B

## AVA's default transpiler behavior

By default, AVA transpiles your tests (and only your tests) using the [`es2015`](http://babeljs.io/docs/plugins/preset-es2015/) and [`stage-2`](http://babeljs.io/docs/plugins/preset-stage-2/) Babel presets. This is a great option for small modules where you do not desire a build step to transpile your source before deploying to `npm`.
By default, AVA transpiles your tests (and only your tests) using the [`es2015-node4`](https://github.com/jbach/babel-preset-es2015-node4) on Node.js 4 or [`node6`](https://github.com/salakar/babel-preset-node6) on Node.js 6 and higher, and [`stage-2`](http://babeljs.io/docs/plugins/preset-stage-2/) Babel presets. This is a great option for small modules where you do not desire a build step to transpile your source before deploying to `npm`.

## Customizing how AVA transpiles your tests

Expand All @@ -25,7 +25,7 @@ You can override the default Babel configuration AVA uses for test transpilation
"ava": {
"babel": {
"plugins": ["rewire"],
"presets": ["es2015", "stage-3"]
"presets": ["es2015-node4", "stage-3"]
}
}
}
Expand All @@ -43,7 +43,7 @@ To transpile your sources, you will need to define a [`babel config` ](http://ba
"require": ["babel-register"]
},
"babel": {
"presets": ["es2015"]
"presets": ["es2015-node4"]
}
}
```
Expand All @@ -63,12 +63,12 @@ Using the `"inherit"` shortcut will cause your tests to be transpiled the same a
"babel": "inherit"
},
"babel": {
"presets": ["es2015", "react"]
"presets": ["es2015-node4", "react"]
}
}
```

In the above example, both tests and sources will be transpiled using the [`es2015`](http://babeljs.io/docs/plugins/preset-es2015/) and [`react`](http://babeljs.io/docs/plugins/preset-react/) presets.
In the above example, both tests and sources will be transpiled using the [`es2015-node4`](https://github.com/jbach/babel-preset-es2015-node4) and [`react`](http://babeljs.io/docs/plugins/preset-react/) presets.

## Extend your source transpilation configuration

Expand All @@ -87,12 +87,12 @@ When specifying the Babel config for your tests, you can set the `babelrc` optio
}
},
"babel": {
"presets": ["es2015", "react"]
"presets": ["es2015-node4", "react"]
}
}
```

In the above example, *sources* are compiled use [`es2015`](http://babeljs.io/docs/plugins/preset-es2015/) and [`react`](http://babeljs.io/docs/plugins/preset-react/), *tests* use those same plugins, plus the additional `custom` plugins specified.
In the above example, *sources* are compiled use [`es2015-node4`](https://github.com/jbach/babel-preset-es2015-node4) and [`react`](http://babeljs.io/docs/plugins/preset-react/), *tests* use those same plugins, plus the additional `custom` plugins specified.

## Extend an alternate config file.

Expand Down
6 changes: 3 additions & 3 deletions lib/babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function lazy(initFn) {
}

const defaultPresets = lazy(() => {
const esPreset = semver.satisfies(process.version, '>=4') ?
'babel-preset-es2015-node4' :
'babel-preset-es2015';
const esPreset = semver.satisfies(process.version, '>=6') ?
'babel-preset-node6' :
'babel-preset-es2015-node4';

return [
require('babel-preset-stage-2'),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"test-win": "tap --no-cov --reporter=classic --timeout=150 test/*.js test/reporters/*.js",
"visual": "node test/visual/run-visual-tests.js",
"prepublish": "npm run make-ts",
"make-ts": "babel-node --presets=babel-preset-es2015 --plugins=transform-runtime types/make.js"
"make-ts": "babel-node --presets=babel-preset-es2015-node4 --plugins=transform-runtime types/make.js"
},
"files": [
"lib",
Expand Down Expand Up @@ -99,8 +99,8 @@
"babel-plugin-detective": "^2.0.0",
"babel-plugin-espower": "^2.3.1",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-es2015-node4": "^2.1.0",
"babel-preset-node6": "^11.0.0",
"babel-preset-stage-2": "^6.17.0",
"babel-runtime": "^6.11.6",
"bluebird": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ function generateTests(prefix, apiCreator) {

var api = apiCreator({
babelConfig: {
presets: ['react', 'es2015', 'stage-2']
presets: ['react', 'es2015-node4', 'stage-2']
}
});

Expand Down Expand Up @@ -840,7 +840,7 @@ function generateTests(prefix, apiCreator) {

var api = apiCreator({
babelConfig: {
presets: ['es2015', 'stage-2'],
presets: ['es2015-node4', 'stage-2'],
plugins: [testCapitalizerPlugin]
},
cacheEnabled: false
Expand Down
10 changes: 5 additions & 5 deletions test/babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('uses babelConfig for babel options when babelConfig is an object', t => {
});

const babelConfig = {
presets: ['stage-2', 'es2015'],
presets: ['stage-2', 'es2015-node4'],
plugins: [customPlugin]
};

Expand All @@ -50,7 +50,7 @@ test('uses babelConfig for babel options when babelConfig is an object', t => {
t.false(options.ast);
t.true('inputSourceMap' in options);
t.false(options.babelrc);
t.strictDeepEqual(options.presets, ['stage-2', 'es2015']);
t.strictDeepEqual(options.presets, ['stage-2', 'es2015-node4']);
t.strictDeepEqual(options.plugins, [customPlugin, setup.powerAssert, throwsHelper, setup.rewrite, transformRuntime]);
t.end();
});
Expand All @@ -65,7 +65,7 @@ test('should reuse existing source maps', t => {
});

const babelConfig = {
presets: ['stage-2', 'es2015'],
presets: ['stage-2', 'es2015-node4'],
plugins: [customPlugin]
};

Expand All @@ -79,7 +79,7 @@ test('should reuse existing source maps', t => {
t.true(options.sourceMaps);
t.false(options.ast);
t.true('inputSourceMap' in options);
t.strictDeepEqual(options.presets, ['stage-2', 'es2015']);
t.strictDeepEqual(options.presets, ['stage-2', 'es2015-node4']);
t.strictDeepEqual(options.plugins, [customPlugin, setup.powerAssert, throwsHelper, setup.rewrite, transformRuntime]);
t.end();
});
Expand All @@ -94,7 +94,7 @@ test('should disable power-assert when powerAssert is false', t => {
});

const babelConfig = {
presets: ['stage-2', 'es2015'],
presets: ['stage-2', 'es2015-node4'],
plugins: [customPlugin]
};

Expand Down
2 changes: 1 addition & 1 deletion test/fixture/babelrc/.alt-babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["es2015", "stage-2"],
"presets": ["es2015-node4", "stage-2"],
"plugins": ["../babel-plugin-foo-to-bar"]
}
2 changes: 1 addition & 1 deletion test/fixture/babelrc/.babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["es2015", "stage-2"],
"presets": ["es2015-node4", "stage-2"],
"plugins": ["../babel-plugin-test-doubler"]
}
11 changes: 9 additions & 2 deletions test/fixture/babelrc/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import test from '../../../'
import test from '../../../';

test('foo', t => t.pass());
const fixture = [1, 2];

test('foo', t => {
// using destructuring to ensure it transpiles on Node.js 4
// since that is a Node.js 6 feature
const [one, two] = fixture;
t.pass();
});

0 comments on commit 5158ac8

Please sign in to comment.