Webstorm,nodejs, npm test, '.' is not recognized as an internal or external command, - node.js

I'm new to nodejs, working on Webstorm 9.0.1, i'm trying to use Lab module for tests using this tutorial https://medium.com/the-spumko-suite/testing-hapi-services-with-lab-96ac463c490a
My package.json file contains the following :
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "./node_modules/lab/bin/lab -c"
},
"author": "",
"license": "ISC",
"devDependencies": {
"hapi": "^8.0.0",
"joi": "^5.0.2",
"lab": "^5.1.0"
}
}
The local node_modules directory is created in the directory C:\Users\DT002\WebstormProjects\hapiB\test>
the problem is that when i try to test, i got the following error :
> C:\Users\DT002\WebstormProjects\hapiB\test>npm test
>
> test#1.0.0 test C:\Users\DT002\WebstormProjects\hapiB\test
> ./node_modules/lab/bin/lab -c
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
Thank you for any suggestions.

The instructions in your scripts runs as a commands in the terminal. You have in your npm test: "./node_modules/lab/bin/lab -c".
What the system is complaining is the first dot that you have there. You can remove the ./ and the error will go away.
{ "test": "node_modules/lab/bin/lab -c" }

Related

node-sass not compiling with npm scripts

So, I am reading this article and following each of the steps described but when I am trying to run npm run scss I get the following error:
This is my .json file :
{
"name": "new-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"scss": "node-sass --output-style compressed -o dist/css src/scss",
"serve": "browser-sync start --server --files 'dist/css/*.css, **/*.html'"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
"node-sass": "^4.13.0"
}
}
It does not create the dist file it's supposed to or doesn't do anything else.
Here is what I got.
node -v v12.13.0
npm -v 6.12.0
Please let me know if you need any further information from my setup but it should be the exact same from the article.

sh: 1: cucumber.js: not found

Trying to use this tutorial here:
https://github.com/lykmapipo/nodejs-cucumber-sample
The output to nvm current is: v10.12.0.
The output to npm --version is: 6.4.1>
I get the error below once I invoke npm test:
> nodejs-cucumber-sample#0.0.1 test /home/gnuc/code/nodejs-cucumber-sample
> cucumber.js
sh: 1: cucumber.js: not found
I am not sure as to why this is the case. The $PATH includes /home/gnuc/.nvm/versions/node/v10.12.0/bin. And I have already used npm install cucumber -g and npm install cucumber
Make sure that your package.json file includes this: "test": "cucumber-js"
So that it looks something like this:
{
"name": "hellocucumber",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": **"cucumber-js"**
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"cucumber": "^5.1.0"
}
}
So, you need to actually call the npm package/library. I have the following defined in my package.json:
"scripts": {
"test": "node ./node_modules/.bin/cucumber-js"
},
you can also add some ---tags in this call.
"scripts": {
"test": "node ./node_modules/.bin/cucumber-js --tags #RegressionTestSuite"
},
this will run any feature files that have #RegressionTestSuite at the top
Also, I have an output/results file created with a time stamp.
"scripts": {
"test": "node ./node_modules/.bin/cucumber-js --tags #RegressionTestSuite --format json:./results/log_new_`date +%Y-%m-%m__%H-%M`.json""
},
I hope this helped.
node ./node_modules/cucumber/bin/cucumber-js
This command is working fine.
And you got sh:1: cucumber.js: not found error means first things please look out the path of cucumber.js

Package published to npm not running properly

I published a simple package to npm and it's not working properly when installed. The package.json is as follows
{
"name": "test-package-hello",
"version": "1.0.4",
"description": "This is a test package",
"main": "index.js",
"bin": {
"hello": "index.js"
},
"scripts": {
"test": "exit 0"
},
"author": "Jeril Sebastian",
"license": "MIT",
"dependencies": {
"chalk": "^2.1.0"
}
}
I published the package using npm publish and it gets published successfully. Then I install it using npm install -g test-package-hello and it gets installed successfully.
But when I try to run the program using hello, it gives the error
/home/jeril/.nvm/versions/node/v6.11.3/bin/hello: line 1: syntax error near unexpected token `('
Apparently it's trying to run index.js as a bash script. When I examined other files in /home/jeril/.nvm/versions/node/v6.11.3/bin/, all of them have the this line on top
#!/usr/bin/env node
Where as my package's index.js doesn't have it on top.
What am i missing?
Find the source here and the published package here

running a command after install dependencies using npm install

I have a package.json file like this
{
"name": "E2E",
"version": "1.0.0",
"description": "AngularJS E2E testing",
"main": "conf.js",
"scripts": {
"postinstall": "node_modules/protractor/bin/webdriver-manager update",
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"devDependencies": {
"protractor": "^2.2.0"
}
}
when running command npm install after protractor is installed its throwing error
node_modules/protractor/bin/webdriver-manager update
'node_modules' is not recognized as an internal or external command, operable program or batch file
Ok found the fix, I need to run it as node command like this
"postinstall": "node node_modules/protractor/bin/webdriver-manager update",
Try prepending the path to executable with a dot followed by a slash:
./node_modules/protractor/bin/webdriver-manager update
The problem is that you need to be in the folder where that command is installed before you call it. Assuming you are using Windows, this can be solved by running a simple batch file:
#echo off
call npm install -g protractor
call npm install
cd C:/Users/%USERNAME%/AppData/Roaming/npm/node_modules/protractor/selenium/
call webdriver-manage update
You should be able to run a batch file from anywhere. In fact, the entire Protractor testing process can be automated with a batch file. You just need to add Grunt, load-grunt-tasks, grunt-protractor-runner, jasime, and protractor-jasmine2-html-reporter to your package.json:
{
"name": "yourproject",
"version": "0.0.1",
"dependencies": { },
"devDependencies": {
"grunt": "~0.4.1",
"load-grunt-tasks": "~1.0.0",
"grunt-protractor-runner": "~2.1.0",
"jasmine": "~2.3",
"protractor-jasmine2-html-reporter": "~0.0.5"
},
"engines": {
"node": ">=0.12.0"
}
}
After you configure Protractor and writing some tests, you can then call the whole process with one simple batch file:
#echo off
cd %CD%
#echo running tests
call grunt
#echo Opening test results in browser
start "" %CD%\tests\reports\index.html

Watcher automation in Mocha

I would like to achieve automation of motcha --watcher feature using package.json file without globally installing mocha.
One of npm features is to allow add custom scripts into npm command. Previously I configured test runner successfully and I can type in bash now:
npm test
Everything works fine, so I would like also do something similar because
./node_modules/mocha/bin/mocha --watch app.js test.js"
is not too efective.
My goal is to run mocha watcher by typing in bash:
npm watch
Unfortunately watcher doesn't run - instead I see standard output of npm command without parameters. It looks like my custom script wasn't registered by npm.
Here is my actual package.json file
{
"name": "screencast",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha test.js", // works properly after typing 'npm test'
"watch": "mocha --watch app.js test.js" // Syntax looks ok, but command 'npm watch' d
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.10.6"
},
"devDependencies": {
"mocha": "^2.0.1",
"supertest": "^0.15.0"
}
}
Anyone had this issue before?
For a 'custom' script like watch, you have to do npm run watch instead of npm watch

Resources