"Unexpected end of JSON input" while doing mochawesome-merge - javascript

I tried removing spaces in command as suggested in this post. I also tried to reencode mochawesome.json as suggested in this post. But non worked.
You can find my json files here on gdrive.
When I try to merge them, I get following error:
npx mochawesome-merge cypress/reports/test/test/*.json>cypress/reports/test/test/merged_report.json
Debugger attached.
Debugger attached.
ERROR: Failed to merge reports
SyntaxError: cypress/reports/test/test/merged_report.json: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at F:\myproj-testing\node_modules\mochawesome-merge\node_modules\jsonfile\index.js:33:18
at F:\myproj-testing\node_modules\graceful-fs\graceful-fs.js:123:16
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
Waiting for the debugger to disconnect...
Waiting for the debugger to disconnect...
I am on Windows 10. Following are node related version:
>node --version
v14.16.0
> npm --version
Debugger attached.
6.14.11
package.json
{
"name": "myproj-testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"merge":"mochawesome-merge cypress/reports/*.json>cypress/reports/merged_report.json",
"generate_mochawesome_report": "marge cypress/reports/merged_report.json --reportDir ./ --inline",
"final_report": "npm run merge && npm run generate_mochawesome_report",
"generate_report": "python cypress/utils/merge.py && npm run generate_mochawesome_report"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cypress": "^8.3.0",
"cypress-file-upload": "^5.0.8"
},
"devDependencies": {
"mocha": "^9.1.1",
"mochawesome": "^6.2.2",
"mochawesome-merge": "^4.2.0"
}
}
Update
I tried running just mochawesome-merge cypress/reports/*.json and it printed the merged json on the console. So I tried to first pipe merged json string to .txt file, then renaming .txt file to .json file and finally doing marge. Strangely it started working... So these are my updated package.json scripts:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"merge":"mochawesome-merge cypress/reports/*.json>cypress/reports/merged_report.json",
"mergetotxt":"mochawesome-merge cypress/reports/*.json > cypress/reports/merged_report.txt",
"generate_mochawesome_report": "marge cypress/reports/merged_report.json --reportDir ./ --inline",
"final_report": "npm run merge && npm run generate_mochawesome_report",
"final_report2": "npm run mergetotxt && rename cypress\\reports\\merged_report.txt merged_report.json && npm run generate_mochawesome_report",
"generate_report": "python cypress/utils/merge.py && npm run generate_mochawesome_report"
}
Notice following two new scripts:
"mergetotxt":"mochawesome-merge cypress/reports/*.json > cypress/reports/merged_report.txt",
"final_report2": "npm run mergetotxt && rename cypress\\reports\\merged_report.txt merged_report.json && npm run generate_mochawesome_report",
Running npm run final_report2 generates the desired report.

The problem is this line :
"merge":"mochawesome-merge cypress/reports/*.json>cypress/reports/merged_report.json"
You cant use an path for the result json.
"merge":"mochawesome-merge cypress/reports/*.json > merged_report.json"
should work

please try this "merge-report":"mochawesome-merge cypress/reports/*.json > merged_report.txt > merged_report.json",
This worked for me.

"merge":"mochawesome-merge cypress/reports/*.json>cypress/reports/output.json",
"generate_mochawesome_report": "marge cypress/reports/output.json --reportDir ./ --inline",
"final_report": "npm run merge && npm run generate_mochawesome_report"
Try it this way, this should work...

Correct command is
yarn run mochawesome-merge cypress/reports/*.json -o cypress/reports/report.json

Related

NPM npm_package_main variable is always empty

Problem
NPM $npm_package_main variable is always empty.
When I set the package.json file with "main": "index.js"
Set the "start" property from scripts to "start": "node $npm_package_main"
Then run npm start
Problem: the CLI executes the Node REPL mode, ignoring the "main" variable from package.json.
Expected behavior: execute the command as node index.js.
Environment
Linux Ubuntu 20.04.1
npm -v = 7.3.0
node -v = v15.5.0
npm run env | grep npm_package_name = npm_package_name=app
npm run env | grep npm_package_main = EMPTY
How to reproduce
Create an "app" directory and enter the new directory
Create an "index.js" file with the following content
console.log('HELLO');
Run npm init and hit ENTER for all questions
Edit the package.json file and add the following line to the "scripts" property:
"start": "node $npm_package_main",
now your package.json must look like this
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"devDependencies": {},
"scripts": {
"start": "node $npm_package_main",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Run "npm start"
File "index.js" is not executed and Node enters the REPL mode.
Attempts
Set "start" and running "npm start" for:
"echo $npm_package_main" prints nothing
"echo $npm_package_name" prints "app"
"echo $npm_package_version" prints "1.0.0"
References
NPM package.json variables: https://docs.npmjs.com/cli/v7/using-npm/scripts
NPM Github issue: https://github.com/npm/cli/issues/2585
The official answer from NPM: use "node .". There's no official reason for this behavior, until this post.
According to the documentation, the "main" property contains the entrypoint for your app when is used as a module in other projects: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#main
Solution
Use the "config" property instead:
{
"name": "app",
"version": "1.0.0",
"description": "",
"devDependencies": {},
"config": {
"main": "index.js"
},
"scripts": {
"start": "node $npm_package_config_main",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Run "npm start"
It works
References:
https://github.com/npm/cli/issues/2585
https://github.com/npm/cli/pull/2446

Lite-server not working

I had a project that was previously using lite-server. I can no longer get it to run using
npm run
I see the following from the console
PS C:\Users\XXX\Documents\Work\Repos\Homepage_Slider> npm run
Lifecycle scripts included in homepage_slider: test
echo "Error: no test specified" && exit 1 start
lite-server
I don't really understand why this isn't working anymore.
I've tried:
Updating NPM
Running lite-server globably
Make sure package.json is set up correctly
Here is my package.json file
{
"name": "homepage_slider",
"version": "1.0.0",
"description": "A simple slider for homepage",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lite-server"
},
"repository": {
"type": "git",
"url": "XXX"
},
"keywords": [
"Slider"
],
"author": "XXX",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.3.0"
},
"dependencies": {
"npm": "^6.0.1"
}
}
npm run is a reserved word for npm itself. Check the documentation
What you really need is npm start which is a shortcut for npm run start which is a shortcut for npm run-script start!

global cli npm package works on windows but not linux

I am wanting to create an npm cli tool, I dug around in bower's code and replicated their basic package.json along with the bin and lib/bin file.
On windows it works perfectly, but on linux I just get : No such file or directory
The npm package is: https://www.npmjs.com/package/quilk
Here is the code, package.json:
{
"name": "quilk",
"version": "0.1.3",
"description": "quilk.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "John Carmichael",
"keywords": [
"builder", "watcher", "fast", "quilk"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/johnc1984/quilk"
},
"main": "lib",
"bin": {
"quilk": "bin/quilk"
},
"files": [
"bin",
"lib"
],
"homepage": "https://github.com/johnc1984/quilk",
"engines": {
"node": ">=0.10.0"
},
"dependencies": {
"browserify" : "13.1.0",
"concat-files" : "0.1.0",
"chokidar" : "1.6.0",
"fs.extra" : "1.3.2",
"javascript-natural-sort" : "0.7.1",
"jdc-node-cliarg-reader" : "1.0.0",
"less" : "2.7.1",
"node-notifier" : "4.6.1",
"node-minify" : "1.3.9",
"q" : "1.4.1",
"recursive-readdir" : "2.0.0"
}
}
bin/quilk:
#!/usr/bin/env node
require('../lib/bin/quilk');
lib/bin/quilk
process.bin = process.title = 'quilk';
console.log('This is the quilk script.');
The end result of installing this globally on windows is the console.log is run on the output is This is the quilk script. after i simply type quilk.
On Ubuntu 14lts though, trying to run the freshly, globally installed npm module results in the output of : No such file or directory
What am I missing to get this run on linux?
(when i run the command to list the globally installed npm modules npm ls -g quilk is listed)
Further info:
I get the exact same issue on the following builds:
Ubuntu 14lts, node 6.4.0, npm 3.10.3
Debian 6.0.10, node 0.12.7, npm 2.11.3
I found the answer.
It turns out to be some kind of bug in npm on windows 10.
After publishing the same package from a linux box, the npm package now works on both linux and windows leading me to believe that npm publish on windows has some bug in it somewhere.
Issue reported: https://github.com/npm/npm/issues/13808

Node.js package start file not working

so I have my package.json file like this:
{
"name": "chat_app",
"version": "0.2.0",
"description": "The second iteration of the chat app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "index.js"
},
"author": "Tino",
"license": "MIT",
"dependencies": {
"express": "^4.14.0",
"jade": "^1.11.0"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-jade": "^1.1.0"
}
}
Here is my index.js file:
var app = require('express')(),
express = require('express'),
http = require('http').Server(app),
jade = require('gulp-jade');
app.use(express.static(path.join(__dirname, '/public')));
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
})
http.listen(3000, function() {
console.log('listening on localhost:3000');
})
When I type: node start it does not work. Why is this? Much help is appreciated.
Thanks
The scripts in your package.json should read:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
To run these scripts use the commands
npm test
or
npm start
Using npm scripts gives you the flexibility to chain commands and use build tools.
You can read more about this here.
Example
Install nodemon, a tool that automatically restarts your node application when you make changes.
Just use nodemon instead of node to run your code, and now your process will automatically restart when your code changes.
...from your terminal run: npm install -g nodemon
Now in your package.json add the following script:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},
And from your command line run this command:
npm run dev
This should give you a basic understanding of how npm scripts work.
The docs for nodemon are here if you are interested.
the scripts simply run the command you write in them in the shell/terminal. so if you want to run npm start and have node running index.js you need to write
"scripts": {
"start": "node index.js"
}

How to set npm run dev as starter for your app?

I am working with React and I am trying to figure out how to set npm run dev in order to compile and put my app to work. Right now, I need to do this in the terminal in order to see my app running
$ node server/index.js
here is the way I have my folders
and here is what I have in package.json
{
"name": "iOS.server2x.socket",
"version": "0.0.1",
"description": "iOS Live Socket.",
"author": "iOS Interactive",
"main": "server/index.js",
"port": 1101,
"scripts": {
"pretest": "eslint ./server",
"test": "echo \"Error: no test specified\" && exit 0",
"start": "rm -rf /home/git/.forever/chat.log; forever start --uid 'chat' ./server/index.js",
"stop": "forever stop chat"
},
"repository": {
"type": "xxxxxx",
"url": "http://url/url"
},
"dependencies": {
"async": "^1.4.2",
"babel": "5.8.3",
},
"devDependencies": {
"babel-eslint": "4.0.5",
}
}
And also, should I need webpack for this ?
I will answer my own question:
there is a way to set this actually, all I did is in the package.json in the scripts part
"scripts": {
"dev": "nodemon ./server/index.js",
"pretest": "eslint ./server",
"test": "echo \"Error: no test specified\" && exit 0",
"start": "rm -rf /home/git/.forever/chat.log; forever start --uid 'chat' ./server/index.js",
"stop": "forever stop chat"
}
so, npm run <here something in that json>, like
$ npm run dev in order to start the server
$ npm run pretest this is the task to run eslint
and so on . . .

Categories

Resources