【问题标题】:How to add environment variable to server, run by cypress testing?如何将环境变量添加到服务器,由赛普拉斯测试运行?
【发布时间】:2020-10-09 16:02:48
【问题描述】:

我的 package.json 文件是

"scripts": {
    "start": "concurrently \"nodemon index.js\" \"PORT=3000 react-scripts start\"",
    "build": "react-scripts build",
    "server": "NODE_ENV=production nodemon index.js",
    "dev": "NODE_ENV=development nodemon index.js",
    "test": "react-scripts test",
    "eslint": "eslint .",
    "cypress:open": "cypress open",
    "start:test": "NODE_ENV=test concurrently \"NODE_ENV=test nodemon index.js\" \"NODE_ENV=test PORT=3000 react-scripts start\""
  },

我在 node app.js 中创建的路由器是

if (process.env.NODE_ENV === 'test') {
  const testingRouter = require('./controllers/testing')
  app.use('/api/testing', testingRouter)
}

但是当我运行 cypress test 时,它抱怨说没有这样的路由器。如何在调用 npm run cypress:open 时使 NODE_ENV=test 命令?

我如何通过 console.log(process.env.NODE_ENV) 查看是否将其传递给 cypres 进程?

【问题讨论】:

    标签: node.js reactjs proxy cypress react-fullstack


    【解决方案1】:

    解决了

    "start:test": "cross-env NODE_ENV==test concurrently \"cross-env NODE_ENV=test nodemon index.js\" \"cross-env NODE_ENV=test PORT=3000 react-scripts start\""

    和 npm run start:test 命令在一个命令提示符下运行,cypress 在另一个命令提示符下运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-27
      • 2022-11-07
      • 1970-01-01
      • 2023-01-26
      • 1970-01-01
      • 2019-12-27
      • 2019-07-29
      • 2022-08-14
      相关资源
      最近更新 更多