You can use async/await
in your Ember testing suite, today! This blog post explains the situation pretty thoroughly. Also check out this blog post.
It's great in tests, but not quite useful for app code yet.
There are three ways we can get it to work. If you try async/await
without any of these changes, you will get the error regeneratorRuntime is not defined
.
Method | Size ※ | app code | test code |
---|---|---|---|
includePolyfill: true | 30kb | yes | yes |
ember-maybe-import-regenerator | 2kb | yes | yes |
targets.js (see below) | 0kb | no | yes |
※ size in prod (gzipped). Determined by doing ember build -p
before and after making the change.
This method adds nothing to the production payload. You can configure just the test environment browser target to use the latest chrome. Add the targets.js
(below) to your app ✨
Since this does not let you use async/await
in your app code, you may want to restrict usage in app code somehow. Is there an eslint rule that would work for this? If so we could enable in tests/eslintrc.js
but not ./eslintrc.js
.
Although maybe 2kb is small enough you'd rather use ember-maybe-import-regenerator :)
- https://github.com/rwjblue/rfcs/blob/42/text/0000-grand-testing-unification.md#async--await (~"what the future should look like")
- https://github.com/babel/ember-cli-babel
- https://github.com/babel/babel-preset-env
- http://rwjblue.com/2017/04/21/ember-cli-targets/
- https://guides.emberjs.com/v2.14.0/configuring-ember/build-targets/
@chuckcarpenter suggested that maybe the
testem.js
config could accomplish the same thing astargets.js
. That seems plausible!