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

Added support for babel config under package.json/ava key (Fixes #448) #573

Closed
wants to merge 12 commits into from
Closed

Conversation

spudly
Copy link
Contributor

@spudly spudly commented Feb 25, 2016

Here's an initial commit that allows package owners to specify a babel config for tests under the package.json/ava key.

This conforms to the proposal in the following comment: #448 (comment)

I chose not to implement an extends key discussed in the thread because 1) it adds to the complexity, 2) I personally don't need it, and 3) how to solve that request is still somewhat unresolved. If needed, someone can add that later in another pull request.

Let me know what you think. I'm a little unsure about whether my method for obtaining babelConfig is the best one.

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @novemberborn, @sotojuan and @ariporad to be potential reviewers

@@ -97,7 +97,8 @@ var api = new Api(cli.input.length ? cli.input : arrify(conf.files), {
failFast: cli.flags.failFast,
serial: cli.flags.serial,
require: arrify(cli.flags.require),
cacheEnabled: cli.flags.cache !== false
cacheEnabled: cli.flags.cache !== false,
babelConfig: conf.babel,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation here.

@sindresorhus
Copy link
Member

Good start :) This will need tests and docs too.

@spudly
Copy link
Contributor Author

spudly commented Feb 26, 2016

Fixed indentation, added tests, and added docs.

}
```

If you do not specify a "babel" key in your ava configuration, or if you set it to `"default"`, AVA will transpile the test files with AVA's default babel configuration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this default configuration defined anywhere else in the docs? If not, it should be. Then this should link to that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I don't believe it is defined anywhere, but it should be.

@vadimdemedes
Copy link
Contributor

Hey @spudly, could you rebase from master to resolve a conflict? Thanks for the great work!

@spudly
Copy link
Contributor Author

spudly commented Feb 29, 2016

@vdemedes

It's been rebased.

@vadimdemedes
Copy link
Contributor

Great, I think it's good to go!

@sindresorhus @novemberborn @jamestalmage ?

};

if (!babelConfig || babelConfig === 'default') {
return objectAssign({}, baseOptions, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the empty object here, baseOptions is already fresh so it's safe to mix other properties into it.

@novemberborn
Copy link
Member

Haven't looked at the tests yet, sorry. Been staring at AVA issues all day :)

Could you follow up on #448 (comment)?

Looking really good though, nice work.

}

if (babelConfig === 'inherit') {
return objectAssign({}, baseOptions, {babelrc: true});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we will want to ensure powerAssert is added as a plugin regardless.

@novemberborn
Copy link
Member

The tests exercise caching-compiler, which is good. I'd like to see some integration tests in test/cli, though that does not have to hold up this PR. Happy to undertake that myself or help you @spudly if you're interested. It might be a bit tricky to verify the differing Babel behaviors.


Right now package.json/ava/babel allows any Babel option to be changed. To avoid footguns though I think filename, sourceMaps, ast and inputSourceMap should not be configurable.


@spudly thanks for the hard work on this. It's solving so many of our issues!

@spudly
Copy link
Contributor Author

spudly commented Mar 1, 2016

Pushed a new commit & rebased. I believe I've addressed all of the concerns that were discussed, with the exception of the babel: false option, which I believe should be addressed in a separate pull request.

@spudly
Copy link
Contributor Author

spudly commented Mar 1, 2016

Can anyone help explain why these 44 tests are failing?

https://travis-ci.org/sindresorhus/ava/jobs/112878667

They're unrelated to my changes - the master branch of AVA fails the same tests. These tests were passing yesterday, but today they fail. Perhaps one of the dependencies had a release that broke with semver?

@wyze
Copy link

wyze commented Mar 1, 2016

Might be related to babel 6.6 release yesterday.

I noticed that your previous build used 6.5.2 while this one used 6.6.

test('creation with new', function (t) {
var tempDir = uniqueTempDir();
var precompiler = new CachingPrecompiler(tempDir);
var precompiler = new CachingPrecompiler(tempDir, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should pass 'default' here (and below).

@MoOx
Copy link

MoOx commented Mar 1, 2016

Failures may be similar to MoOx/phenomic#229 (or may not)

@novemberborn
Copy link
Member

@spudly did a fresh checkout and install, master still passes but this branch does not.

@novemberborn
Copy link
Member

@spudly ah! The failing tests use api.js directly, without setting the babelConfig option. Now I feel bad 😢

I still think using the default config in cli.js is the right move, but maybe add the !babelConfig || babelConfig === 'default' clause back in caching-precompiler.js. Quite bothersome passing it in the 44 tests that instantiate Api.

@spudly
Copy link
Contributor Author

spudly commented Mar 2, 2016

My bad, I must have made a mistake when I checked out master and ran the tests again yesterday. Did it again this morning and the tests are passing. I'll fix this very soon.

@spudly
Copy link
Contributor Author

spudly commented Mar 2, 2016

I'm stumped guys. If I do the following, all tests pass as expected.

git clone https://github.com/sindresorhus/ava.git
cd ava
git reset --hard 58e1c561296a409a9557ceb1c7684685404c4278
npm install
npm test

But if I do this, 44 tests fail:

git clone https://github.com/spudly/ava.git
cd ava
git reset --hard 58e1c561296a409a9557ceb1c7684685404c4278
npm install
npm test

Both repos are being reset to the same initial commit (the one before any of my changes), so there should be absolutely no difference between the two, right?

@kentcdodds
Copy link
Contributor

I'm running both of those series of commands now. I'll let you know what I get

@kentcdodds
Copy link
Contributor

Everything passed for me for both of those. Sounds like an environment issue...

@spudly
Copy link
Contributor Author

spudly commented Mar 7, 2016

Is there a reason we have return statements on cli.js:13 and cli.js:96? It's causing lint errors with the latest XO config.

@spudly
Copy link
Contributor Author

spudly commented Mar 7, 2016

Nevermind. running npm install fixed that issue. Still curious though, why are those return statements there?

@spudly
Copy link
Contributor Author

spudly commented Mar 7, 2016

made requested changes and rebased again.

@novemberborn
Copy link
Member

Is there a reason we have return statements on cli.js:13 and cli.js:96?

They're shorthand for exiting the CLI.

@novemberborn
Copy link
Member

@spudly what's the reason for adding the babel-cli dependency in package.json?

@spudly
Copy link
Contributor Author

spudly commented Mar 7, 2016

@novemberborn,

That dependency was added by @jamestalmage in the babel-plugin-for-integration-tests branch, which is merged into my code.

@vadimdemedes
Copy link
Contributor

I guess "outside" commits shouldn't be in this PR, should they?

@novemberborn
Copy link
Member

That dependency was added by @jamestalmage in the babel-plugin-for-integration-tests branch, which is merged into my code.

Ah!

@vdemedes are you in Gitter at the moment? Let's see about landing the integration test plugin in master etc.

@novemberborn
Copy link
Member

Landed in a03f826 yay! (Messed up the commit so it didn't close automatically… oops)

@novemberborn
Copy link
Member

Awesome work, thanks @spudly!

@spudly
Copy link
Contributor Author

spudly commented Mar 7, 2016

Nice! Thanks for the help everyone!

@sindresorhus
Copy link
Member

Yay! Nice work @spudly 💃

od3vvoq

@kentcdodds
Copy link
Contributor

Hooray! 🎉🎉🎉

@Wildhoney
Copy link

👏 👏

For those wondering, it appears as though this hasn't yet been published to npm — however a npm i https://github.com/sindresorhus/ava will suffice for the moment.

@vadimdemedes
Copy link
Contributor

giphy 7

@tleunen
Copy link

tleunen commented Mar 9, 2016

Can we get a cli option for that as well? I prefer specifying it there instead of adding a config in the package.json

@jamestalmage
Copy link
Contributor

@tleunen

Please raise an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.