目前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
中尝试的片段。
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
中实现此操作。有简单的方法吗?