运行测试并查询数据库中的表后出现Webpack编译错误[重复]

moiiocjp  于 11个月前  发布在  Webpack
关注(0)|答案(1)|浏览(159)

此问题在此处已有答案

Can't connect to MySQL database when testing in Cypress (mysql2)(3个答案)
上个月关门了。
我需要运行一个自动测试(Cypress),连接到我的数据库(mysql)并执行一个选择(lib mysql 2)。我无法成功运行我的测试。

我得到以下错误:

Error: Webpack Compilation Error
./node_modules/lru-cache/dist/mjs/index.js 48:8
Module parse failed: Unexpected token (48:8)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| }
| class Stack {
>     heap;
|     length;
|     // private constructor
 @ ./node_modules/mysql2/lib/parsers/parser_cache.js 3:12-32
 @ ./node_modules/mysql2/promise.js

字符串
我以为这是与node_modules相关的东西。我删除并重新安装了所有内容。然而,错误仍然存在。
有人能帮我吗?

>我的文件db.js如下:

var mysql = require('mysql2/promise');

var pool = mysql.createPool({
    host: "for-qa-dblibsmetricsinformation.clmii4vy3haa.us-east-1.rds.amazonaws.com",
    user: "usr_test",
    password: "usr-test",
    database: "db_test",
    connectionLimit: 10 // maximum number of connections in the pool
});

module.exports = pool;

>下面我的文件.spec.js

const pool = require('../../../../../../../../db.js');

describe('Test DB', () => {
  it('should consult a new user', () => {
    const result = pool.execute('select user_name from table_test');
    cy.log(result);
  });
});


提前感谢!!

gywdnpxw

gywdnpxw1#

尝试使用npm i cypress-sql-server
const sqlServer = require('cypress-sql-server')
module.exports = (on, config) => { tasks = sqlServer.loadDBPlugin(config.db); on('task', tasks); }
在您的规范中:
import sqlServer from 'cypress-sql-server';
cy.sqlServer('SELECT 'test').should('eq', 'test');
https://www.npmjs.com/package/cypress-sql-server?activeTab=readme

相关问题