admin管理员组

文章数量:1332395

I have created a basic todo app which has package.json file as:

{
  "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+.git"
  },
  "keywords": [
    "todo",
    "app"
  ],
  "bugs": {
    "url": ""
  },
  "homepage": ""
}

Whenever I run npm test it fails by saying no tests specified, how can I solve this issue? also whenever I try to use TRAVIS CI it fails to detect build script how can I create one?

I have created a basic todo app which has package.json file as:

{
  "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./sahil9001/to-do-app.git"
  },
  "keywords": [
    "todo",
    "app"
  ],
  "bugs": {
    "url": "https://github./sahil9001/to-do-app/issues"
  },
  "homepage": "https://github./sahil9001/to-do-app#readme"
}

Whenever I run npm test it fails by saying no tests specified, how can I solve this issue? also whenever I try to use TRAVIS CI it fails to detect build script how can I create one?

Share Improve this question asked Oct 10, 2019 at 19:40 Sahil SilareSahil Silare 3332 gold badges3 silver badges16 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Specify all required script in scripts property in package.json as below

{
      "name": "to-do-app",
      "version": "1.0.0",
      "description": "A basic to-do app created using JavaScript.",
      "main": "index.js",
      "scripts": {
        "test": "put test mand here",  // example "test": "mocha test.js"
         "build" : "put build mand 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./sahil9001/to-do-app.git"
      },
      "keywords": [
        "todo",
        "app"
      ],
      "bugs": {
        "url": "https://github./sahil9001/to-do-app/issues"
      },
      "homepage": "https://github./sahil9001/to-do-app#readme"
    }

You don't have any scripts mand listed in scripts property and have only default. You have to create and place it as per the need. Refer below links for more details

https://www.freecodecamp/news/introduction-to-npm-scripts-1dbb2ae01633/

https://flaviocopes./package-json/

If you look under "scripts" you'll see your npm scripts such as the script you call when you run "npm test"

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },

The default value when you run NPM init is this simple echo saying no tests, you have to write your own test mand(s) here.

Travis is failing to detect a build script, because you don't have a value for "build" in your scripts section, add something like:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "my_script_to_build"
  },

本文标签: javascriptHow to add build script and tests in NodeJs projectStack Overflow