Skip to content

Commit

Permalink
Fix detection of existing syntax plugins
Browse files Browse the repository at this point in the history
AVA needs to add syntax plugins for stage-4 features, however it
shouldn't do so if the user has already specified them. This fixes the
detection of existing plugins by also comparing a `default` export of
the plugin package.

Fixes #1828.
  • Loading branch information
novemberborn committed Aug 27, 2018
1 parent 8f54022 commit d3bfb73
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/babel-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function validate(conf) {
// more reliable.
function makeValueChecker(ref) {
const expected = require(ref);
return ({value}) => value === expected;
return ({value}) => value === expected || value === expected.default;
}

// Resolved paths are used to create the config item, rather than the plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ava": {
"cache": false
},
"babel": {
"plugins": [
"@babel/plugin-syntax-async-generators"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from '../../../../..';

test('pass', t => t.pass());
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ava": {
"cache": false
},
"babel": {
"plugins": [
"@babel/plugin-syntax-object-rest-spread"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from '../../../../..';

test('pass', t => t.pass());
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ava": {
"cache": false
},
"babel": {
"plugins": [
"@babel/plugin-syntax-optional-catch-binding"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from '../../../../..';

test('pass', t => t.pass());
9 changes: 9 additions & 0 deletions test/integration/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ test('includes relative paths in source map', t => {
t.end();
});
});

for (const plugin of ['async-generators', 'object-rest-spread', 'optional-catch-binding']) {
test(`avoids applying '@babel/plugin-syntax-${plugin}' if already in config`, t => {
execCli([], {dirname: `fixture/babel/with-explicit-syntax-plugins/${plugin}`}, err => {
t.ifError(err);
t.end();
});
});
}

0 comments on commit d3bfb73

Please sign in to comment.