2017-04-13 10 views
0

私はCustomer.js.flowタイプのファイルを持っています。私は明示的に追加場合でも非js | .jsx拡張子を変換するためのbabel-jest

Customer.js.flow:1 
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export type Customer = { 
                         ^^^^^^ 
SyntaxError: Unexpected token export 

    at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:320:12) 

私は冗談を実行すると、このエラーで失敗し

"transform": { 
    "^.+\\.js.flow$": "babel-jest", 
    "^.+\\.jsx?$": "babel-jest" 
}, 

を、私はCustomer.jsCustomer.js.flowを変更したときに、私はもう問題はありません

答えて

0

問題は、あなたのジョブ設定でtransformを使用すると、デフォルトを上書きするという問題があります。 From the docs

Note: if you are using the babel-jest transformer and want to use an additional code preprocessor, keep in mind that when "transform" is overwritten in any way the babel-jest is not loaded automatically anymore. If you want to use it to compile JavaScript code it has to be explicitly defined. See babel-jest plugin

だから、あなたにも.jsファイル用のマッチャーようにする必要があります。

"transform": { 
    "^.+\\.js\\.flow$": "babel-jest", 
    "^.+\\.jsx?$": "babel-jest" 
}, 

私は正規表現としてはあまり良くありませんが、これは1つのステートメントに単純化することができます。

+0

私の質問が更新されました。私は解決策はここにあります:https://github.com/facebook/jest/issues/2152#issuecomment-262485964 私は自分のカスタムトランスフォーマーをここに書いています:https://github.com/MayasHaddad/flow-jest -トランス – Mayas

関連する問題