I'm trying to get test results and code coverage data after running jest tests. The resulting file contains the results of the tests, but no coverage data. I'm using jest-junit as my reporter. Here's what's in my package.json:
"scripts": {
"test": "jest --verbose --silent --coverage --coverageDirectory=./",
"start": "node server.js",
"dev": "nodemon server.js"
},
"jest": {
"testEnvironment": "node",
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"text",
"jest-junit"
],
"reporters": [
"default",
"jest-junit"
]
},
"jest-junit": {
"suiteName": "jest tests",
"outputDirectory": ".",
"outputName": "junit.xml",
"uniqueOutputName": "false",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
}
Related
For some reason I can't seem to split out "cypress, puppeteer and jest unit tests" into separate commands:
package.json:
"test:jest": "jest ./src",
"e2e:pptr": "npm run dev & jest ./tests",
"e2e:cypress": "npm run dev & cypress run",
"e2e:cypress:browser": "npm run dev & cypress open",
...
"jest": {
"verbose": true,
"testEnvironment": "jsdom",
"transform": {
"^.+\\.svelte$": [
"svelte-jester",
{
"preprocess": true
}
],
"^.+\\.js$": "babel-jest",
"^.+\\.ts$": "ts-jest"
},
"moduleFileExtensions": [
"js",
"ts",
"svelte"
],
"setupFilesAfterEnv": [
"#testing-library/jest-dom/extend-expect"
]
}
WHen I run npm run test:jest it still runs all tests. including cypress and ./tests/*.spec.js files. Its suppposed to just run tests under ./src which are my unit tests.
puppeteer tests are in ./tests/*.spec.js and cypresss are under ./cypress/*
So I needed to add --rootDir <path> to limit it.
"test:jest": "jest --rootDir ./src",
I have a Nodejs project which uses ESLint to keep consistency.
On my Mac machine, I have no troubles all works bur on Windows I got this error
No files matching the pattern "'./*'" were found.
Please check for typing mistakes in the pattern.
My setup for ESLint is
{
"env": {
"es6": true,
"node": true
},
"extends": [
"plugin:prettier/recommended",
"airbnb-base"
],
"plugins": [
"prettier"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"linebreak-style": "off"
}
}
Package.json
{
"name": "new-architecture-solution",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prod": "node -r esm server.js",
"dev": "nodemon -r esm server.js",
"debug": "ndb nodemon -r esm server.js",
"lint": "eslint . --ext .js,.jsx --quiet",
"fix": "eslint './*' --fix",
"prettier": "prettier --write src/**/*.{js,css}"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"eslintIgnore": [
"package.json",
"package-lock.json",
"combined.log",
"swagger.json",
"README.md"
],
"lint-staged": {
"./**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"npm run prettier",
"npm run lint --color",
"npm run fix",
"git add"
]
},
I'm unable to find asolution and I would like to have it work in both my machines
I haven't tried it yet on Windows, but according to this post replacing the single quotes with \" might do the trick. I've tried it on my Mac and it seems to work properly.
Edit: confirmed to work on Windows machines as well.
I have a node js gradle application. I am not sure how to run the application locally.
I have done gradle build (./gradlew) and npm run build(compile). All my dependencies are in the node_modules.
I have a server.ts file having server code apart from the routing.
My package.json-
{
"name": "app",
"version": "..",
"description": "",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"prepublish": "npm run build",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async-child-process": "^1.1.1",
..
},
"devDependencies": {
"#types/handlebars": "^4.0.36",
"#types/node": "^8.10.45",
"#types/pg-types": "^1.11.4"
}
}
How to run the project on the server.
tsconfig.json
{
"compilerOptions": {
"outDir": "./build/js/",
"sourceMap": false,
"noImplicitAny": false,
"module": "commonjs",
"declaration":true,
"target": "es2015"
},
"include": [
"src/main/ts/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
Node.js will not run ts code. after build it'll js code in dist directory(depends on tsconf.json).
In package.json add below code, run npm run serve to start server.
or go to dist dir and run node server.js.
I have created a sample on GitHub check here
"scripts": {
"serve": "npm run build && npm run start",
"start": "node dist/server.js",
"build": "tsc"
}
I need something like this:
nodemon.json:
[{
"watch": ["src/api-gateway"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/api-gateway/main.ts"
},
{
"watch": ["src/services/ping-service"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/services/ping-service/ping-service.ts"
}]
Is that possible, or if there is some alternative way to do it?
Use the array for watch option
"watch": [
"folder1",
"folder2",
]
You can look at the sample here https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md
I was following tutorial that I have found here. Previously the command was running fine, but after some changes when I runnpm run nodemon it gives me error
Here is my package.json
{
"name": "smashing-react-i18n",
"version": "1.0.0",
"description": "",
"main": "dist/bundle.js",
"betterScripts": {
"build": {
"command": "webpack -p",
"env": {
"NODE_ENV": "production"
}
},
"nodemon": {
"command": "nodemon server.js",
"env": {
"NODE_PATH": "src"
}
}
},