I have installed vite in my vue.js app. I start the app by typing npm run dev in the main project directory. In the package.json this is defined as:
"dev": "vite"
but if I try do run this command (or eg. vite build) 'manually' from main directory, I get an error:
bash: vite: command not found
I also figured out that when I set a new script:
"build": "vite build"
I can run this command also, although, again, running it manually will result in error as above.
This seems quite illogical to me. Can anybody explain how is it possible?
If you didn't install vite globally (using npm install -g), then the vite command will be in node_modules/.bin in your main directory. The npm run command temporarily adds that folder to your PATH so it can execute that command. Try running ./node_modules/.bin/vite to run it without npm.
I have to add jest locally to every single project folder I create in order to use it. I can't use the "jest" command on Terminal, but I can do "npm run test".
zsh: command not found: jest
Jest Error is installed, but it's in my ./node_modules directory. People have said in a previous discussion post that I should run the command
./node_modules/jest –updateSnapshot
However, this leads to the error:
zsh: permission denied: ./jest
I would like to run jest on Terminal. Please give some advice.
You could try to run it this way :
./node_modules/.bin/jest
If that doesn't work, try installing jest globally.
npm install -g jest
if you don't want to install jest globally,
(there are a couple of reasons why you do not want to install npm things globally - for example this one),
you can do:
npx jest <all your jest flags or files>
node v6.10.2, npm v3.10.3, mocha v3.1.2
my package.json has this in the scripts section:
"test": "mocha ./test/unit/* --recursive"
When I run npm test I get
> #hc/pos-onlineordering#0.1.0 test C:\_dev\pos-onlineordering\server
> mocha ./test/unit/* --recursive "--reporter" "dot"
module.js:471
throw err;
^
Error: Cannot find module 'C:\_dev\app\server\test\unit\deploy'
it just so happens that C:_dev\app\server\test\unit\deploy is a directory holding several test files in it.
Here's where it gets really fun though. If I enter mocha ./test/unit/* --recursive at the command prompt, it runs all the tests like I would expect. I need it to run as a package script because the running the unit tests are a part of the build and deploy scripts.
More weird: It works for every other team member, some on Macs, some on Windows. I've tried it in Windows Power Shell and in Git-Bash, running as an administrator.
I have deleted the node_modules folder and re-run npm install. I have also run
npm uninstall -D mocha && npm i -D mocha and nothing changes. I have even deleted the entire repository and re-cloned it.
So my assumption is that I clearly have something wrong with my computer or environment, but I don't even know where to look for what it could be at this point. How can I get mocha to run out of the package scripts?
For my nodejs build. Travis automatically runs npm run test This produces a very large output, so for the CI build I want to run npm run test | faucet. I do not want to add this to my package.json as we want the log files and it is very helpful for new developers.
How can we get travis to run a custom npm test command?
I'm having trouble getting Mocha to work as expected, and I'd love to say as documented, but there (appears) to not be much documentation on actually getting the thing running.
I've installed it using npm (both globally and locally), and each time when I run it I get:
$ mocha
mocha: command not found
Ok, so I figured it's not in my PATH, so I tried running it directly,
$ ./node_modules/mocha/bin/mocha
execvp(): No such file or directory
Finally, I tried hitting the other bin file, and got,
$ ./node_modules/mocha/bin/_mocha
path.existsSync is deprecated. It is now called `fs.existsSync`.
.
✔ 1 tests complete (1ms)
How can I just execute my tests with a single command? Vows seems to let you, but I've heard Mocha is the better choice, I just can't seem to get it working correctly.
And any thoughts on the error I got above in my third attempt?
Edit:
I'm running,
Ubuntu 11.10 64-bit
Node.js 0.7.5
npm 1.1.8
mocha 0.14.1
should 0.6.0
since npm 5.2.0, there's a new command "npx" included with npm that makes this much simpler, if you run:
npx mocha <args>
Note: the optional args are forwarded to the command being executed (mocha in this case)
this will automatically pick the executable "mocha" command from your locally installed mocha (always add it as a dev dependency to ensure the correct one is always used by you and everyone else).
Be careful though that if you didn't install mocha, this command will automatically fetch and use latest version, which is great for some tools (like scaffolders for example), but might not be the most recommendable for certain dependencies where you might want to pin to a specific version.
You can read more on npx here
Now, if instead of invoking mocha directly, you want to define a custom npm script, an alias that might invoke other npm binaries...
you don't want your library tests to fail depending on the machine setup (mocha as global, global mocha version, etc), the way to use the local mocha that works cross-platform is:
node node_modules/.bin/mocha
npm puts aliases to all the binaries in your dependencies on that special folder.
Finally, npm will add node_modules/.bin to the PATH automatically when running an npm script, so in your package.json you can do just:
"scripts": {
"test": "mocha"
}
and invoke it with
npm test
After further reading, and confirmation from Linus G Thiel above, I found I simply had to,
Downgrade to Node.js 0.6.12
And either,
Install Mocha as global
Add ./node_modules/.bin to my PATH
To run Mocha with mocha command from your terminal you need to install mocha globally on this machine:
npm install --global mocha
Then cd to your projectFolder/test and run mocha yourTestFileName.js
If you want to make mocha available inside your package.json as a development dependency:
npm install --save-dev mocha
Then add mocha to your scripts inside package.json.
"scripts": {
"test": "mocha"
},
Then run npm test inside your terminal.
While installing the node modules for mocha I had tried the below commands
npm install
npm install mocha
npm install --save-dev mocha
npm install mocha -g # to install it globally also
and on running or executing the mocha test I was trying
mocha test
npm run test
mocha test test\index.test.js
npm test
but I was getting the below error as:
'Mocha' is not recognized as internal or external command
So , after trying everything it came out to be just set the path to environment variables under the System Variables as:
C:\Program Files\nodejs\
and it worked :)
For windows :
Package.json
"scripts": {
"start": "nodemon app.js",
"test": "mocha"
},
then run the command
npm run test
Late answer but I think will work.
Install mocha globally
npm install --global mocha
If you have already installed mocha then set the path to bin