首页 > 解决方案 > 如何配置 cypress-sql-server 以在不同的环境 prod 和 dev 中使用

问题描述

我正在使用 cypress-sql-server 插件根据 production.json 和 development.json 的不同环境进行配置

{
"env": {
"userName":"sa",
"password": "",
"server": "localhost",
"port": "1433",
"options": {
"database": "TestDatabase",
"encrypt": true,
"rowCollectionOnRequestCompletion" : true
}
}
}

the index.js file in the plugins

const path = require("path");
const fs = require("fs-extra");
const sqlServer = require('cypress-sql-server');

function getConfigurationByFile(file) {
const pathToConfigFile = path.resolve("cypress/config", ${file}.json)
console.error('the server path',pathToConfigFile)
return fs.readJson(pathToConfigFile);
}

module.exports = async (on, config) => {
tasks = sqlServer.loadDBPlugin(config);
on('task', tasks);
const file = config.env.fileConfig
return getConfigurationByFile(file)
}

当我运行测试用例时,我收到如下失败消息

cy.task('sqlServer:execute') 失败并出现以下错误:

无效的服务器:未定义”

我用机器名替换了 localhost,但同样的错误。我认为sqlServer.loadDBPlugin(config)没有得到正确的数据。有什么想法吗?

请帮忙。谢谢。

标签: testingpluginscypress

解决方案


我遇到了同样的问题,直接用繁琐的替换了 cypress-sql-server。使用这些: https ://github.com/cypress-io/cypress/issues/6621

注意:安装固定版本:

“coffeescript”:“^2.5.1”,
“乏味”:“^8.3.0”


推荐阅读