How resolve "Error: invalid reporter "html-cov"" in nodejs - javascript

package.json
{
"name": "learningmocha",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha && mocha test --require blanket --reporter html-cov > coverage.html"
},
"author": "",
"license": "ISC",
"devDependencies": {
"blanket": "^1.2.3",
"chai": "^3.5.0",
"mocha": "^3.2.0"
},
"config": {
"blanket": {
"pattern": [ "index.js" ],
"data-cover-never": "node-module"
}
}
}
I am using Mocha for testing in nodejs. when i run npm test after adding html-cov in the test script of my package.json as show above then it give me error
"Error: invalid reporter "html-cov"
You can see more in this image

html-cov was dropped in 3.0.0 [1]
[1] https://github.com/mochajs/mocha/issues/2356

Related

“react doesn't exist” in Node.js terminal

I got that error “react doesn't exist” when I'm trying to compile jsx using babel using this command :
npx babel src/index.js --out-file=public/main.js --presets=env,react
both dependencies env and react are configured.
{"name": "React",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"},
"keywords": [],
"author": "",
"license": "ISC"}
any ideas?
Do you add React?
yarn add react
or
npm install react
maybe try add this to script in package.json
{"name": "React",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "babel src/index.js --out-file=public/main.js --presets=env,react"
},
"keywords": [],
"author": "",
"license": "ISC"}
And run command:
yarn dev
or
npm run dev

Netlify: Failed to upload file: &{Name:submission-created during build

I'm trying to use netlify and its lambda function feature to run a node function. Based on https://css-tricks.com/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget/.
I'm having trouble getting node modules to work (see ImportModuleError","errorMessage":"Error: Cannot find module while using Netlify lambda functions with dependencies)
Currently my netlify.toml has only the following:
[build]
functions = "./functions"
command = "npm run-script build"
and my package.json:
{
"name": "test2",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npm install && npm build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kc1/test2.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/kc1/test2/issues"
},
"homepage": "https://github.com/kc1/test2#readme",
"dependencies": {
"dotenv": "^8.2.0",
"node-fetch": "^2.6.1"
}
}
You can see the deploy log here: https://app.netlify.com/sites/inspiring-ardinghelli-4a4da5/deploys/5fd180d4db83b400073f8694. What am I doing wrong?

Why do I have SyntaxError: Cannot use import statement outside a module?

I am trying to run mockingoose example
> alonjest#1.0.0 test /home/milenko/pract/alonjest
> jest __tests__
FAIL .history/__tests__/user.test_20201028132815.js
● Test suite failed to run
Details:
/home/milenko/pract/alonjest/.history/__tests__/user.test_20201028132815.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import mockingoose from 'mockingoose';
Package.json
"name": "alonjest",
"version": "1.0.0",
"description": "",
"main": "user.js",
"type": "module",
"scripts": {
"test": "jest __tests__"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mongoose": "^5.10.11"
},
"devDependencies": {
"jest": "^26.6.1",
"mockingoose": "^2.13.2"
}
}
Dir structure
node_modules
package.json
package-lock.json
__tests__
user.mjs
What is wrong with my configuration?

Git-related Issues uploading to Heroku

I have exactly the same issue as User daffodils. When uploaded to heroku the app fails with a message "npm ERR! missing script: start" But I don't have a start command in my package.json and I do have "web : node app.js" in my Procfile
I don't have a start in my package.json file and the same file worked ok for another similar app on heroku:
{
"name": "tBlogv3withdb",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"engines": {
"node": "13.12.0"
},
"dependencies": {
"body-parser": "^1.18.3",
"ejs": "^2.6.1",
"express": "^4.16.3",
"lodash": "^4.17.15",
"mongoose": "^5.9.10"
}
}
User Daffodils said "I dropped the repo and re-init solved it." - what does this mean exactly?

How to add build script and tests in NodeJs project

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.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"
}
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?
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 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"
}
You don't have any scripts command 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.org/news/introduction-to-npm-scripts-1dbb2ae01633/
https://flaviocopes.com/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 command(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"
},

Categories