yarn add babel-preset-env babel-plugin-flow-runtime flow-runtime -D
しておく。
babel-preset-env でこんな設定を書いた
.babelrc
{
"presets": [
["env", { "targets": {
"Chrome": 56
}}]
],
"plugins": [
"flow-runtime"
],
"env": {
"test": {
"presets": [
["env", { "targets": {
"node": 6
}}]
],
"plugins": [
["flow-runtime", {"assert": true}],
"transform-async-to-generator"
],
},
"production": {
"presets": [
"flow",
["env", { "targets": {
"browsers": ["last 2 versions", "IE 11"]
}}]
]
}
}
}
本筋関係ないが、開発時は Chrome ターゲットだけで頑張る設定。
$ NODE_ENV=test ava
foo.js
/* @flow */
export default function foo (): number {
return ''
}
foo.test.js
/* @flow */
import foo from './foo'
import test from 'ava'
test(async t => {
t.is(foo(), 1)
})