Skip to content

test: make use of async/await #1996

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

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"presets": ["@babel/preset-env"]
"presets": ["@babel/preset-env"],
"env": {
"test": {
"plugins": ["@babel/plugin-transform-runtime"]
Copy link
Member Author

@hiroppy hiroppy Jun 8, 2019

Choose a reason for hiding this comment

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

jest uses babel as the default, so we need regeneratorruntime to use async/await. If we want to use the native async/await, we have to set current using @babel/env or reset transform.

Note: babel-jest is automatically installed when installing Jest and will automatically transform files if a babel configuration exists in your project. To avoid this behavior, you can explicitly reset the transform configuration option:

https://jestjs.io/docs/en/getting-started

Copy link
Member

Choose a reason for hiding this comment

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

We don't need this plugin for async/await:

  1. It is inside @babel/preset-env
  2. We use next branch, in node@8 it is built-in

Copy link
Member

@alexander-akait alexander-akait Jun 8, 2019

Choose a reason for hiding this comment

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

Jest doesn't use babel as the default, we need babel-jest package for this

Copy link
Member Author

@hiroppy hiroppy Jun 8, 2019

Choose a reason for hiding this comment

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

no, if we have .babelrc, jest uses babel-jest. See the documentation.
The section is Making your Babel config jest-aware.
In fact, we can use for-await-of with our current configuration. This is the feature that is only originally supported for v10 and higher.

We can set transform: {} for stopping to use babel, but we've already used ESM in client-src, so we should use babel in jest.

Copy link
Member

Choose a reason for hiding this comment

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

👍

}
}
}
26 changes: 25 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@commitlint/cli": "^7.6.1",
"@commitlint/config-conventional": "^7.6.0",
Expand Down
Loading