【发布时间】:2021-07-16 15:31:54
【问题描述】:
我想我需要一点帮助来了解如何使用 nextJS 的 cypress 插件来运行 Cypress Components Test
package.json
"devDependencies": {
"@cypress/react": "^5.3.4",
"@cypress/webpack-dev-server": "^1.1.4",
"@cypress/webpack-preprocessor": "^5.7.0",
"@testing-library/cypress": "^7.0.6",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.36",
"@types/react": "^17.0.3",
"cypress": "^7.1.0",
"sass": "^1.32.8",
"typescript": "^4.2.3",
"webpack-dev-server": "^3.11.2"
}
cypress/plugins/index.ts
module.exports = (on, config) => {
require('@cypress/react/plugins/next')(on, config)
return config
}
尝试开始测试会引发options.rewrites.map is not a function 错误
$ yarn cypress open-ct
yarn run v1.22.5
$ /Users/norfeldt/Repos/LoCali/locali-web/node_modules/.bin/cypress open-ct
info - Loaded env from /Users/norfeldt/Repos/LoCali/locali-web/.env.local
Error [TypeError]: options.rewrites.map is not a function
at new BuildManifestPlugin (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/next/build/webpack/plugins/build-manifest-plugin.ts:94:38)
at getBaseWebpackConfig (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/next/build/webpack-config.ts:1133:9)
at getNextWebpackConfig (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/@cypress/react/plugins/next/findNextWebpackConfig.js:9:29)
at findNextWebpackConfig (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/@cypress/react/plugins/next/findNextWebpackConfig.js:36:24)
at Object.handler (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/@cypress/react/plugins/next/index.js:5:27)
TypeError: options.rewrites.map is not a function
at new BuildManifestPlugin (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/next/build/webpack/plugins/build-manifest-plugin.ts:94:38)
at getBaseWebpackConfig (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/next/build/webpack-config.ts:1133:9)
at getNextWebpackConfig (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/@cypress/react/plugins/next/findNextWebpackConfig.js:9:29)
at findNextWebpackConfig (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/@cypress/react/plugins/next/findNextWebpackConfig.js:36:24)
at Object.handler (/Users/norfeldt/Repos/LoCali/locali-web/node_modules/@cypress/react/plugins/next/index.js:5:27)
我错过了什么吗?
【问题讨论】:
-
在开发 Storybook 插件时遇到了同样的问题。重写不是使用对象,但我不明白为什么 BuildManifestPlugin 不检查它。
-
@EricBurel 我发布了一个答案。它对你有用,然后给 et 投票。
-
它似乎与一些不匹配的版本有关,通过更新 Next 它再次对我有用(我正在使用本地安装的 Canary 分支)
标签: reactjs typescript next.js cypress