简体   繁体   English

当我尝试实现时,在 express 中的“npm test”之后“找不到命令”(参见 jest、supertest、env)

[英]'command not found' after 'npm test' in express, when i try to implement (cf. jest, supertest, env)

I am trying to implement TESTCODE by jest and supertest in express.我正在尝试通过 jest 和 supertest 在 express 中实现 TESTCODE。

but when i type npm test in vsc terminal, it made the following issue:但是当我在 vsc 终端中输入npm test时,出现以下问题:

'.env' file already has private data. '.env' 文件已经有私有数据。 So it works when I try to signup and signin, but when i do npm test it made the issue.因此,当我尝试注册和登录时它可以工作,但是当我进行npm test时,它就出现了问题。

I think it might because because jest(?) can't read .env.我认为这可能是因为 jest(?) 无法读取.env. file properly.正确归档。

vsc terminal vsc 终端

env-cmd ./.env jest --watch

./.env: line 1: DATABASE_USERNAME: command not found
./.env: line 2: DATABASE_PASSWORD: command not found
./.env: line 3: DATABASE_NAME: command not found
./.env: line 4: DATABASE_HOST: command not found
./.env: line 5: DATABASE_PORT: command not found
npm ERR! Test failed.  See above for more details.

package.json package.json

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "nodemon index.js",
    "test": "env-cmd ./.env jest --watch"
  },
  "jest": {
    "testEnvironment": "node"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.21.0",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "~4.16.1",
    "express-validator": "^6.9.2",
    "i18n": "^0.13.2",
    "i18n-express": "^1.1.3",
    "jsonwebtoken": "^8.5.1",
    "morgan": "^1.10.0",
    "mysql2": "^2.1.0",
    "sequelize": "^6.3.5"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "dotenv": "^8.2.0",
    "jest": "^26.6.3",
    "nodemon": "^2.0.6",
    "sequelize-cli": "^6.2.0",
    "superagent": "^6.1.0",
    "supertest": "^6.1.1",
    "env-cmd": "^10.1.0"
  }
}

I ran your test script and it worked but make sure:我运行了您的测试脚本并且它有效,但请确保:

  1. Enough permission is granted for the project directory, run chmod -R a+rwx /your/project/path为项目目录授予足够的权限,运行chmod -R a+rwx /your/project/path

  2. File structure is correct文件结构正确

  • project项目
    • .env .env
    • package.json package.json

Thank you for your advice.感谢您的意见。

My file structure is我的文件结构是

project
    server
        .env
        package.json

First time when I type 'npm test' it made this result => spawn./.env EACCES当我第一次输入“npm test”时,它得到了这个结果=> spawn./.env EACCES

So I typed 'chmod -R 777 server/ ', and 'npm test' Then it made this result所以我输入了'chmod -R 777 server/'和'npm test'然后它得到了这个结果

 > env-cmd ./.env jest --watch

./.env: line 1: DATABASE_USERNAME: command not found
./.env: line 2: DATABASE_PASSWORD: command not found
./.env: line 3: DATABASE_NAME: command not found
./.env: line 4: DATABASE_HOST: command not found
./.env: line 5: DATABASE_PORT: command not found
npm ERR! Test failed.  See above for more details.

Then I typed what you said 'chmod -R a+rwx server/', and 'npm test' Then it made same result like up thing……….然后我输入了你说的'chmod -R a+rwx server/'和'npm test'然后它得到了和up一样的结果…………。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NodeJS-Supertest throw错误:当我使用应用程序进行测试时,无法在发送标头后设置标头,例如supertest.agent(express()) - NodeJS - Supertest throw Error: Can't set headers after they are sent when I use app to test, such as supertest.agent(express()) 当应用程序在端口 3000 上侦听(快速和超级测试)时,Jest 测试失败并显示“连接 ECONNREFUSED 127.0.0.1:80” - Jest test failing with 'connect ECONNREFUSED 127.0.0.1:80' when app is listening on port 3000 (express and supertest) 无论我尝试什么,npm'找不到命令' - npm 'command not found' no matter what I try 用 npm 安装后,在 bash 中找不到 express 命令 - express command not found in bash after installing it with npm 无法在 Jest 中使用 supertest(用于测试 express 应用程序)测试删除 - Cannot test delete with supertest (for testing the express app) in Jest 当我使用应用程序时,使用 supertest 和 Jest 测试 Express、MongoDB 和 TypeScript 失败 - Testing Express, MongoDB & TypeScript with supertest and Jest fails when I use app 使用 Jest、Supertest、MongoDB 和 Express 进行测试时出现的拆卸错误 - Teardown Errors when testing with Jest, Supertest, MongoDB, and Express 使用 supertest 和 mongoose 时,Jest 在测试运行完成后一秒没有退出 - Jest did not exit one second after the test run has completed when using supertest and mongoose 与 express-session 开玩笑的超级测试 - jest supertest with express-session 超级测试测试快速中间件 - supertest test express middleware
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM