Я хочу использовать Flow в приложении React, которое я тестирую с помощью Cypress. Я использую веб-препроцессор с предустановкой потока.Сначала я кодирую препроцессор в ./cypress/plugin/index.js:
const webpack = require('@cypress/webpack-preprocessor')
module.exports = (on) => {
const options = {
// send in the options from your webpack.config.js, so it works the same
// as your app's code
webpackOptions: require('../../webpack.config'),
watchOptions: {}
}
on('file:preprocessor', webpack((options)))
}
Затем я устанавливаю @ cypress / webpack-preprocessor 'и @ babel / preset-flow. Package.json выглядиткак это:
{
"name": "TimeLogging",
"version": "1.0.0",
"description": "React Time Logging",
"main": "index.js",
"engines": {
"node": "8.11.4",
"npm": "5.6.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"eslint": "eslint",
"flow": "flow"
},
"author": "CodeMix",
"license": "ISC",
"dependencies": {
"flow-bin": "^0.81.0",
"prop-types": "^15.6.2",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "^1.1.1"
},
"devDependencies": {
"@babel/preset-flow": "^7.0.0",
"@cypress/webpack-preprocessor": "^3.0.0",
"cypress": "^3.1.0",
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
"eslint": "^4.19.1",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-cypress": "^2.0.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-standard": "^4.0.0"
}
}
> And the webpack.config.js looks like this:
module: {
rules: [
{{
test: /\.(js|jsx?)$/,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader',
options: {
presets: [
'babel-preset-env',
'babel-preset-react',
'babel-preset-flow'
],
},
}],
},
]
}
}
Когда я запускаю тест в Cypress, я получаю эту ошибку:
/ cypress / интеграции / TogableTimerForm.spec.jsx Сборка модуля не удалась (с ./node_modules/@cypress/webpack-preprocessor/node_modules/babel-loader/lib/index.js): Ошибка: файлы плагинов / предустановок не могут экспортировать объекты, только функции.В /Users/stein/Development/TimeLogging/TimeLogging/node_modules/babel-preset-flow/lib/index.js
Как исправить эту ошибку?