[英]'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:我运行了您的测试脚本并且它有效,但请确保:
Enough permission is granted for the project directory, run chmod -R a+rwx /your/project/path
为项目目录授予足够的权限,运行
chmod -R a+rwx /your/project/path
File structure is correct文件结构正确
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
> 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.