【发布时间】:2019-05-20 02:45:14
【问题描述】:
我在 cypress 中使用插件并引用了 https://docs.cypress.io/api/plugins/configuration-api.html#Usage。当我们将它们部署到詹金斯时,我得到了
`pluginsFile` is set to `/e2e/cypress/plugins/index.js`, but either the file is missing, it contains a syntax error, or threw an error when required. The `pluginsFile` must be a `.js` or `.coffee` file.
Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.[39m
Error: Cannot find module 'fs-extra'
我确实经历了一些手动要求您下载 node_module 中的 fs-extra 的线程。我这样做了,并且依赖项已自动添加到 package.json 文件中。但是,构建失败。当您在本地运行并且所有测试都通过时,代码可以完美运行。但是,当部署到詹金斯时,这会失败。
// promisified fs module
const fs = require('fs-extra')
const path = require('path')
function getConfigurationByFile (file) {
const pathToConfigFile = path.resolve('cypress', 'config', `${file}.json`)
return fs.readJson(pathToConfigFile)
}
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
// accept a configFile value or use development by default
const file = config.env.configFile || 'environment-2'
return getConfigurationByFile(file)
}
代码应该在 Jenkins 上成功部署,但是,晚上在 node_module 上本地安装它不起作用。有人可以帮我弄清楚我错过了什么吗?
【问题讨论】:
-
甚至尝试将 fs-extra 从 dev 依赖项移动到依赖项,但仍然无法正常工作。
-
看来 fs-extra 不是你的问题,但这是你的问题:
pluginsFile` is set to `/e2e/cypress/plugins/index.js你能验证/e2e/cypress/plugins/index.js存在吗?我猜是 cypress 配置的 pluginsFile 不正确,指向了一个不存在的文件。 -
你是对的。这与 fs-extra 无关。但是,我们从中部署到 Jenkins 的文件没有正确的入口点。所以不得不改变这一点。之后它工作得很好:)非常感谢
标签: javascript testing automated-tests cypress end-to-end