mocha Error: No test files found: "test/" npm ERR! Test failed - javascript

I am trying to run mocha tests on linux >
# test C:\Users\wd.ssh\tel\qa_test\mocha-api-tests
Error: No test files found: "test/"
npm ERR! Test failed. See above for more details.
here is my package.json
{
"scripts": {
"test": "mocha --reporter mocha-junit-reporter --timeout 60000 --exit",
},
"dependencies": {
"cassandra-driver": "3.5.0",
"chai": "4.2.0",
"chai-http": "4.2.0",
"express": "4.16.4",
"mocha-junit-reporter": "1.18.0",
"request-promise": "4.2.2"
}
}
commands used:
npm install --global mocha
npm i
and to run the tests I'm using npm test
Project structure:

seeing your project structure, seems that you have one test.js so mocha should target this file.
"scripts": {
"test": "mocha test.js --reporter mocha-junit-reporter --timeout 60000 --exit",
},
If you want to add more test files, it is better to put them inside test directory e.g. /test and must change the target to test files inside the directory.
"scripts": {
"test": "mocha 'test/**/*.js' --recursive --reporter mocha-junit-reporter --timeout 60000 --exit",
},
Hope it helps

you need to provide the path to the test folder. try this:
"scripts": {
"test": "mocha qa_test/**/*.js --reporter mocha-junit-reporter --timeout 60000 --exit",
},
npm test

If there is no test file directly in the test folder, you will get that error.
Solution is add "--recursive" option to your test in the package.json.
"scripts": {
"test": "mocha --recursive --reporter mocha-junit-reporter --timeout 60000 --exit",
},
this will tell mocha that "look recursively for the test files"

Mocha automatically searches for folder called test and should be in root folder as package.json

I fixed the same problem ...
"test": "mocha -r ts-node/register 'tests/**/*.ts'"

One reason this happened to me with saving the test file without extension. Yep, I did it once and Mocha couldn't detect the file and run the tests. Make sure it has at least .js as extension. Notice that some IDEs may already show the file as JS (as it detects the file content), but you still need to have the extension of the file as JS.

Also had this problem and this worked for me:
./node_modules/mocha/bin/mocha -r esm -r ts-node/register "src/**/*Test.ts"

Related

Node.js install Python dependencies from within package.json

I'm building a Node.JS project that uses both Python and NPM dependency modules.
The Node.JS modules are located within package.json and the python dependencies are inside a file requirements.txt.
I would like to install all the dependency modules (Python and Node.JS) from within package.json by running npm install.
Is this possible and how?
Thanks in advance!
The files look like below.
package.json:
{
"name": "app",
"version": "1.0.0",
"description": "Trial app",
"main": "bin/index.js",
"scripts": {
"dev": "npm install",
"start": "node app.js",
"test": "jest --forceExit "
},
"keywords": [
"AI",
"Blockchain",
"Decentralized"
],
"dependencies": {
"peerjs": "^1.3.2",
"redis": "^3.1.2",
"socket.io": "^4.1.2",
"socket.io-client": "^4.1.2",
"wrtc": "^0.4.7"
},
"devDependencies": {
"#babel/core": "^7.16.7",
"supertest": "^6.1.6"
}
}
requirements.txt:
Django==2.2.21
djangorestframework==3.7.7
django-rest-swagger
coreapi
You can define Commands to run within the "scripts" section of your package.json. Every script in there can be run with npm run [scriptname].
So you could do (&& runs another command after the first one)
"scripts": {
"install": "npm install && pip -r requirements.txt",
"dev": "npm install",
"start": "node app.js",
"test": "jest --forceExit "
}
And run npm run install
Replace "dev": "npm install" with "dev": "npm install & pip install"
Add "preinstall" entry to scripts.
npm, yarn and pnpm will automatically execute preinstall script before installing dependencies and 'devDependencies`:
package.json:
{
"scripts": {
"preinstall": "echo 'Installing Python Dependencies...' && pip install -r requirements.txt && pip install -r subproject/requirements.txt"
},
...
}
To install both npm and python dependencies, just run:
$> npm install
Installing Python Dependencies...
Also, there are other hook scripts in npm process, like "prepare", which might be useful. And scripts can be chained with ... && npm run <script>, so the "scripts" section can be organized into small atomic ones and built up by chaining them. I use "scripts" as a project's build and deploy active knowledgebase, replacing make file functionality not only in JS, but even in pure Python projects.
It is also possible to hook "package.json" into python script, i.e. create something like "build_project.py" script (or whatever name that works for you, I've used "make.py" and "build.py" for less typing) specific to the project, add all python-related stuff there, and run the npm commands from it. It may be more coding than using "scripts" section in "package.json".

PKG Failed to make Bytecode

I am getting this warning when I try and run .. pkg index.js -t macOS
node v17.3.1
pkg#5.5.2
Warning Failed to make bytecode node17-arm64 for file /snapshot/______/index.js
was hoping anyone could help,
I have also tried to use -b and got
Error: ENOENT: no such file or directory, open '/var/folders/fy/c5tgsjcj63q73kfvg_dd53fh0000gn/T/pkg.d5ef9dd92b18360a4ff95824/node/out/Release/node
thank you
My Script was written in ES6, I ran it threw Babel and then tried again and it worked perfectly!!
I used #vercel/ncc to generate one index.js file and then use pkg on the generated index.js file.
My package.json scripts is like this:
"scripts": {
"test": "jest",
"start": "node src/index.js",
"dev": "nodemon src/index.js",
"build": "ncc build -o build/lib ./src/index.js && pkg --target node16-win-x64 -o build/MY-API.exe ./build/lib/index.js"
},

nodemon not loading environment variables

The following is in my gulpfile.js:
const nodemon = require('nodemon')
const server = nodemon({
script: './src/index.js',
ext: 'hbs json js css',
require: 'dotenv/config',
dotenv_config_path: './config/.env',
stdout: false // without this line the stdout event won't fire
})
I am looking to duplicate the exact same behavior as the dev script in the package.json file:
"scripts": {
"test": "jest --watch",
"dev": "nodemon -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css",
"debug": "nodemon --inspect -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css"
},
For one reason or another it seems that gulp is not registering the environment variables defined in the .env file. Although the line below works just fine when ran with npm run dev:
nodemon -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css
You may need to add export to your environment vars and load them before running nodemon:
vars.env
export ENV_FIRST="J"
export ENV_LAST="Doe"
package.json
"scripts": {
"dev": "source vars.env; nodemon ..."
...
}

How do I implement a nfc reader (ACR122) to an Electron project?

I have downloaded this library (https://github.com/pokusew/nfc-pcsc) and now i'm trying to run an Electron project in it, but is giving me everytime problems when i try to run it as an Electron project.
So my question is: How can I implement this library on my Electron project and make it work not as node.js
I tried to npm install --save electron#latest in the library and change on the json the script "example": "node -r #babel/register examples/read-write.js" to "example": "electron -r #babel/register examples/read-write.js" also i have tried to uninstall and install, i have done electron-rebuild
"rebuild": "electron-rebuild -f -w yourmodule",
"build": "babel src --out-dir dist",
"example": "electron -r #babel/register examples/read-write.js",
"example-basic": "node -r #babel/register examples/basic.js",
"example-from-readme-3": "node -r #babel/register examples/from-readme-3.js",
"example-led": "node -r #babel/register examples/led.js",
"example-mifare-classic": "node -r #babel/register examples/mifare-classic.js",
"example-mifare-desfire": "node -r #babel/register examples/mifare-desfire.js",
"example-mifare-ultralight-ntag": "node -r #babel/register examples/mifare-ultralight-ntag.js",
"example-ndef": "node -r #babel/register examples/ndef.js",
"example-uid-logger": "node -r #babel/register examples/uid-logger.js",
"example-without-auto": "node -r #babel/register examples/without-auto.js",
"prepack": "yarn build && yarn test",
"test": "cross-env NODE_ENV=test ava test/tests.js --verbose"
}
I'm getting this error when i'm trying to run the app as Electron app (https://i.imgur.com/UhSjlo6.png) and when i do the rebuild i have this error: × Rebuild Failed An unhandled error occurred inside electron-rebuild
Electron as of v5.0.0 is using Node.js v12.0.0. This native module (nfc-pcsc) is not building correctly for that version.
Downgrade Electron to v4, rebuild via "electron-rebuild" and it should build properly.
npm install --save-dev electron#4
then
electron-rebuild

Npm scripts always gives an error as "is not recognized as an internal or external command"

I have a lerna repo. There is devDependency to concurrently package from my root package.json. When I type "lerna bootstrap" to command line, it works properly and install all root and subPackages` dependencies to root node_modules folder. But when i type "npm start" it says: 'concurrently' is not recognized as an internal or external command. When i check node_modules/concurrently folder it exists without problem.
My start script is concurrently --kill-others "npm run start-client" "npm run start-server".
This situation same with webpack-dev-server. How can i fix this problem except reinstalling everything.
package.json:
{
"name": "x-workspace",
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"concurrently": "3.5.0",
"lerna": "^2.11.0"
},
"scripts": {
"start": "concurrently --kill-others \"npm run start-client\" \"npm run start-server\"",
"build": "webpack --hot",
"start-client": "npm --prefix ./packages/client-app start",
"start-server": "cd ./packages/server-app && dotnet run",
"clean": "rimraf node_modules package-lock.json ./packages/client-app/package-lock.json"
}
}
I found problem. There is no .bin folder in root node_modules folder. This is result of updating yarn to 1.8.0. When i return back to yarn 1.6.0, it works perfectly.
Thanks to David R. and other users.
I believe you don't have the concurrently package installed globally, To confirm try executing the below command and check if it returns anything,
npm list -g concurrently
If you've received an --(empty) response, then you'll have to install it globally.
npm install -g concurrently
Hope this helps!.

Categories