javascript - 如何在 NodeJs 项目中添加构建脚本和测试
问题描述
我创建了一个基本的待办事项应用程序,其package.json
文件为:
{
"name": "to-do-app",
"version": "1.0.0",
"description": "A basic to-do app created using JavaScript.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Sahil Silare",
"license": "MIT",
"dependencies": {
"body-parser": "^1.19.0",
"build": "^0.1.4",
"ejs": "^2.7.1",
"express": "^4.17.1",
"npm-build": "0.0.1"
},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/sahil9001/to-do-app.git"
},
"keywords": [
"todo",
"app"
],
"bugs": {
"url": "https://github.com/sahil9001/to-do-app/issues"
},
"homepage": "https://github.com/sahil9001/to-do-app#readme"
}
每当我运行npm test
它时说没有指定测试失败,我该如何解决这个问题?同样,每当我尝试使用TRAVIS CI
它时,它都无法检测到build
脚本,我该如何创建一个?
解决方案
在 package.json 的 scripts 属性中指定所有必需的脚本,如下所示
{
"name": "to-do-app",
"version": "1.0.0",
"description": "A basic to-do app created using JavaScript.",
"main": "index.js",
"scripts": {
"test": "put test command here", // example "test": "mocha test.js"
"build" : "put build command here"
},
"author": "Sahil Silare",
"license": "MIT",
"dependencies": {
"body-parser": "^1.19.0",
"build": "^0.1.4",
"ejs": "^2.7.1",
"express": "^4.17.1",
"npm-build": "0.0.1"
},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/sahil9001/to-do-app.git"
},
"keywords": [
"todo",
"app"
],
"bugs": {
"url": "https://github.com/sahil9001/to-do-app/issues"
},
"homepage": "https://github.com/sahil9001/to-do-app#readme"
}
您没有在 scripts 属性中列出任何脚本命令,并且只有默认值。您必须根据需要创建和放置它。有关更多详细信息,请参阅以下链接
https://www.freecodecamp.org/news/introduction-to-npm-scripts-1dbb2ae01633/
推荐阅读
- node.js - 如何将我的 npm 版本升级到 8.11.1?
- mysql - 对桥接实体和多属性实体感到困惑
- javascript - THREE.js 中单个网格的多个 UV/纹理
- java - 错误重复条目:com/google/android/gms/internal/measurement/zzxd.class android studio
- android - React Native 文本输入更新很慢
- scala - 可选择在数据帧 spark/scala 上应用过滤器
- mysql - 反向MySql LIKE?
- python - 如何概括变量 m 而不是在 Python 中使用多个条件语句?
- ubuntu - 在没有 IDE 的 Ubuntu 上安装单声道
- json - 如何将终端中的json文件存储到csv文件中