-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve Babel recipe #1290
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
Improve Babel recipe #1290
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @florianb. Some comments below.
docs/recipes/babelrc.md
Outdated
| { | ||
| "ava": { | ||
| "require": [ | ||
| "babel-register", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary for babel-polyfill, so let's leave it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, thanks!
- Remove the polyfill-snippet
docs/recipes/babelrc.md
Outdated
| } | ||
| ``` | ||
|
|
||
| ## Provide ES2015 Polyfills to your tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps Polyfill tests? I'm trying to avoid ES2015 mentions since the standard is continuously evolving. AVA tries to support stage-4 syntax which means currently we're supporting more than ES2016, but not ES2017 since it isn't official yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @novemberborn - that's a absolute valid point. I will change that.
- Remove ES2015-reference
docs/recipes/babelrc.md
Outdated
|
|
||
| ## Provide ES2015 Polyfills to your tests | ||
|
|
||
| You might run into issues when relying on ES2015-features your current environment do not support. Since Ava isn't providing any polyfills per default you might want to enable them by adding `babel-polyfill` manually to the `require` section: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good start. I think it could be clearer on what AVA does out of the box, and what kind of features end up being missing. There's also a big downside to using babel-polyfill, which is that it impacts how your program behaves (not just the tests!)
What do you think about this:
AVA lets you write tests using new JavaScript syntax, even on Node.js version that do not support it otherwise. However it doesn't add or modify built-ins. For example
Array.prototype.includes()is not available in Node.js 4 even when you use AVA.You can opt in to these features by loading Babel's Polyfill module. Note that this modifies the environment, which impacts how your program itself behaves.
You can load
babel-polyfillby adding it to AVA'srequireoptions:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much @novemberborn - i somehow assumed it could be wanted to write not too much. 🤔 I guess that assumption was just a bit stupid. 😄
- Elaborate the description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@novemberborn I rewrote the description. I think it reads better now (even though my mother-tongue is German, so don't expect too much) but i have still a note on it:
- The documentation should probably elaborate on the distinction between the execution environment of tests and the execution environment of the tested code. The current wording may leave that as a question to the beginner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewrote the description. I think it reads better now (even though my mother-tongue is German, so don't expect too much)
No worries, English isn't my first language either. Writing is hard!
The documentation should probably elaborate on the distinction between the execution environment of tests and the execution environment of the tested code. The current wording may leave that as a question to the beginner.
The point is that there is no distinction. Whether it impacts your program depends on how it's written. You take on the responsibility of figuring that out when you use polyfills. That said, my intent was to say that your program, when it actually runs, without the polyfills present, may malfunction. We could indeed make that more explicit.
docs/recipes/babelrc.md
Outdated
| ## Use Babel Polyfills | ||
|
|
||
| You might run into issues when relying on ES2015-features your current environment do not support. Since Ava isn't providing any polyfills per default you might want to enable them by adding `babel-polyfill` manually to the `require` section: | ||
| AVA lets you write your tests using new JavaScript syntax, even on Node.js versions that otherwise wouldn't support it. However, it doesn't add or modify built-ins of your current environment. Using AVA would, for example, not provide modern features such as `Array.prototype.includes()` to an underlying NodeJ.js 4 environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in NodeJ.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for that..
- Fix typo
docs/recipes/babelrc.md
Outdated
| You might run into issues when relying on ES2015-features your current environment do not support. Since Ava isn't providing any polyfills per default you might want to enable them by adding `babel-polyfill` manually to the `require` section: | ||
| AVA lets you write your tests using new JavaScript syntax, even on Node.js versions that otherwise wouldn't support it. However, it doesn't add or modify built-ins of your current environment. Using AVA would, for example, not provide modern features such as `Array.prototype.includes()` to an underlying NodeJ.js 4 environment. | ||
|
|
||
| By loading [Babel's Polyfill module](https://babeljs.io/docs/usage/polyfill/) you're able to opt these features in. Note that this will modify the environment, which may influence how your program itself behaves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
able to opt in to these features.
Let's get rid of itself in how your program itself behaves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Remove
itself
docs/recipes/babelrc.md
Outdated
|
|
||
| By loading [Babel's Polyfill module](https://babeljs.io/docs/usage/polyfill/) you're able to opt these features in. Note that this will modify the environment, which may influence how your program itself behaves. | ||
|
|
||
| You can enable `babel-polyfill` by adding it to AVA's require options: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps:
…
requireoption:
(Marking require as code, and singular "option".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- make
require-option more explicit
|
Thanks for your understanding. 😄 So what we would need to say is that the user must ensure he provides the same "polyfilled" environment for AVA as he does to the execution environment of his program (in the case he uses more features than defined in AVA's stage-4)? |
Yes.
AVA's test transpilation doesn't impact the user's program. I agree it's a general topic which is why I was trying to get away with just hinting at it. |
|
Okay, i guess i'd like to try to clarify this a bit more on the default's transpiler behavior section. If you don't mind, of course. 😄 |
|
@florianb by all means. |
|
Okay @novemberborn, i hope i could make the description of the default transpilation behavior a little bit more clear. I tried to become a little bit more explicit, even though i am not sure i got the meaning of
I think that former sentence implies that AVA allows you using ES-features even in projects you otherwise don't do any transpilation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting back to this. I think we're getting there!
I think that former sentence implies that AVA allows you using ES-features even in projects you otherwise don't do any transpilation.
Yes.
docs/recipes/babelrc.md
Outdated
|
|
||
| AVA lets you write your tests using new JavaScript syntax, even on Node.js versions that otherwise wouldn't support it. However, it doesn't add or modify built-ins of your current environment. Using AVA would, for example, not provide modern features such as `Array.prototype.includes()` to an underlying Node.js 4 environment. | ||
|
|
||
| By loading [Babel's Polyfill module](https://babeljs.io/docs/usage/polyfill/) you're able to opt these features in. Note that this will modify the environment, which may influence how your program behaves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By loading Babel's Polyfill module you can opt in to these features. …
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 😄
- fix style
docs/recipes/babelrc.md
Outdated
| ## AVA's default transpiler behavior | ||
|
|
||
| By default, AVA transpiles your tests and helper files using the [`@ava/stage-4`](https://github.com/avajs/babel-preset-stage-4) Babel preset. This is a great option for small modules where you do not desire a build step to transpile your source before deploying to `npm`. | ||
| AVA by default provides some nifty ECMAScript features, like [`async`](https://github.com/avajs/ava#async-function-support), to your test-environment. To make this possible AVA transpiles the tests and helper files using the [`@ava/stage-4`](https://github.com/avajs/babel-preset-stage-4) Babel preset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just call it JavaScript.
How about:
AVA lets you use some nifty JavaScript features in your tests, like async functions. To make this work on older Node.js versions AVA transpiles the tests and helper files using the
@ava/stage-4Babel preset. This is great for projects where you don't otherwise use Babel for your source, but do want to use the newest JavaScript features in your tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am somehow torn between using JS over ECMAScript for these reasons:
- JavaScript sounds just slight and handy
- This paragraph is about the differences between good old vanilla JS and the new (not backward compatible) language features introduced by ES.
I think this topic is read by people who already know the term "ECMAScript" and i think in this case it supports understanding (and avoids confusion for less experienced programmers ["Isn't that feature an ES-feature?"]).
But i am really not insisting on that - so if you'd prefer using JS, i am fine with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our main page talks about JavaScript, so I don't see why we should start using a different term here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay - i just thought about the use of "ES2017" to explicitly spot on ES-features.
But as i said, i'm not insisting on it.
- Replace ES by JS
docs/recipes/babelrc.md
Outdated
|
|
||
| AVA lets you write your tests using new JavaScript syntax, even on Node.js versions that otherwise wouldn't support it. However, it doesn't add or modify built-ins of your current environment. Using AVA would, for example, not provide modern features such as `Array.prototype.includes()` to an underlying Node.js 4 environment. | ||
|
|
||
| By loading [Babel's Polyfill module](https://babeljs.io/docs/usage/polyfill/) you can opt in to these features in. Note that this will modify the environment, which may influence how your program behaves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the "in" after "features".
docs/recipes/babelrc.md
Outdated
| By default, AVA transpiles your tests and helper files using the [`@ava/stage-4`](https://github.com/avajs/babel-preset-stage-4) Babel preset. This is a great option for small modules where you do not desire a build step to transpile your source before deploying to `npm`. | ||
| AVA by default provides some nifty JavaScript features, like [`async`](https://github.com/avajs/ava#async-function-support), to your test-environment. To make this possible AVA transpiles the tests and helper files using the [`@ava/stage-4`](https://github.com/avajs/babel-preset-stage-4) Babel preset. | ||
|
|
||
| This is a great feature for projects where you desire to not transpile your source before deploying but enjoy using ECMAScript for writing tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for changing this to JavaScript (though it says ECMAScript in the second paragraph). I still think this reads better though:
AVA lets you use some nifty JavaScript features in your tests, like async functions. To make this work on older Node.js versions AVA transpiles the tests and helper files using the
@ava/stage-4Babel preset. This is great for projects where you don't otherwise use Babel for your source, but do want to use the newest JavaScript features in your tests.
The latest Node.js version support most of ES2017, so it helps to explain why AVA still needs to do transpilation. I feel the sentences read a bit better as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it reads better. However, i rewrote "...where you don't otherwise use..." to be a little slighter, i hope you don't mind.
|
Thanks @florianb! |
|
Your are welcome @novemberborn - thanks for your help! |
babel-polyfill