10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

flow-runtime でテスト時にランタイムの型エラーでテストを落とす

Last updated at Posted at 2017-02-18

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)
})

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?