【发布时间】:2022-01-03 19:34:49
【问题描述】:
目前 cypress 支持不使用 ssh 的 mysql 连接,如下链接所示
https://docs.cypress.io/api/commands/task#Allows-a-single-argument-only
但我正在尝试通过 ssh 隧道将 cypress 连接到 mysql。
我正在使用 npm 包mysql-ssh 建立连接。
我可以直接使用node.js 来实现这一点,但我在通过 cypress 实施时遇到了问题。这是我在node.js 中尝试的sn-p。
const mysqlssh = require('mysql-ssh');
const fs = require('fs');
mysqlssh.connect(
{
host: 'x.x.x.x',
user: 'xyz',
privateKey: fs.readFileSync('filePath') //this is the ssh filePath
},
{
host: 'HOST_NAME',
user: 'USER_NAME',
password: 'xxxx',
database: 'DB_NAME'
}
)
.then(client => {
client.query('select * from TABLE_NAME', function (err, results, fields) {
if (err)
{
console.log(err)
}
console.log(results);
mysqlssh.close()
})
})
.catch(err => {
console.log(err)
})
我想通过cypress/plugins/index.js 文件或直接在cypress/integration 中执行此操作。有没有简单的方法来做到这一点?
【问题讨论】:
标签: mysql node.js cypress ssh-tunnel