Command line way to generate HTML coverageReport in Jest - unit-testing

In Jest, is there a way from the command line to generate an HTML coverage report if it is not defined in the jest.config.js files?
I only want to generate the HTML report some of the time rather than every time I run Jest. The only way I've been able to generate the HTML report was by changing the config manually.

By default the collectCoverage option for jest is set to false. The easiest way to get an HTML coverage report is to configure jest in either package.json or jest.config.js. You will also need to set the coverageDirectory in the config as well.
There are several different configuration options for coverage reporting. See here for all config settings: https://jestjs.io/docs/en/configuration.html#collectcoverage-boolean
Here is an example of how to configure jest in package.json with a few options.
{
"name": "appname",
"version": "1.0.0",
"description": "description",
"main": "index.js",
"scripts": {
"test": "jest",
"postinstall": "jspm install"
},
"jest": {
"scriptPreprocessor": "./preprocessor.js",
"testPathIgnorePatterns": [
"/node_modules/",
],
"unmockedModulePathPatterns": [
"./node_modules/react"
],
"collectCoverage": true,
"coverageDirectory": "path/to/coverage/reports",
},
"author": "author",
"license": "ISC",
"dependencies": {
"del": "^1.1.1",
"gulp": "^3.8.11",
"gulp-filter": "^2.0.2",
"gulp-load-plugins": "^0.10.0",
"gulp-react": "^3.0.1",
"gulp-shell": "^0.4.1",
"harmonize": "^1.4.1",
"jest-cli": "^0.4.1",
"jspm": "^0.15.5",
"react": "^0.13.2",
"react-tools": "^0.13.2",
"run-sequence": "^1.1.0"
},
"devDependencies": {
"browser-sync": "^2.7.1",
"gulp": "^3.8.11"
},
"jspm": {
"directories": {},
"dependencies": {
"react": "npm:react#^0.13.2"
},
"devDependencies": {
"babel": "npm:babel-core#^5.1.13",
"babel-runtime": "npm:babel-runtime#^5.1.13",
"core-js": "npm:core-js#^0.9.4"
}
}
}
Now when you run your test with jest --coverage the HTML reports will be generated in the specified directory.

Have you tried to pass in a JSON config via the command line?
npx jest ./src/**/*.js --coverage --config='{ "coverageReporters": ["html"] }'

Here is a portion from my test scripts in package.json that may help you generate coverage reports:
"test": "react-scripts test --env=jsdom",
"test:coverage": "react-scripts test --coverage"
My setup uses jest#23.6.0 with enzyme#3.8.0 and jest-enzyme#7.0.1

Related

Dependencies aren't being included on the build output of electron forge

My electron app project uses create-react-app and my main process needed the electron-devtools-installer module. I'm using electron-forge for building the app. Now after running npm run make to package and built the app, I'm getting this error message
Error: Cannot find module 'electron-devtools-installer'
after opening the app. I'm not getting this error when I simply run electron ., thus I suspect the module is not being included on the packaging.
Now the said module is for development only, I could simply write a logic to ignore it when in production mode but what happens when I really need a 3rd party modules in my main process in the production, so how do I include the dependencies modules in the packaging?
I moved the electron-devtools-installer mode in dependencies key in package.json but it still doesn't work.
My package.json contains:
{
"name": "myapp",
"version": "0.1.0",
"private": true,
"homepage": ".",
"description": "some description",
"main": "main/init.js",
"author": "anonymouse",
"license": "MIT",
"dependencies": {
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^13.5.0",
"electron-devtools-installer": "^3.2.0",
"electron-squirrel-startup": "^1.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "electron-forge start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"dev": "concurrently -k \"react-scripts start\" \"npm:electron\"",
"electron": "wait-on tcp:3000 && electron .",
"package": "react-scripts build && electron-forge package",
"make": "react-scripts build && electron-forge make",
"clean:winbuild": "rmdir build /s /q & rmdir out /s /q"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.67",
"#electron-forge/maker-deb": "^6.0.0-beta.67",
"#electron-forge/maker-rpm": "^6.0.0-beta.67",
"#electron-forge/maker-squirrel": "^6.0.0-beta.67",
"#electron-forge/maker-zip": "^6.0.0-beta.67",
"concurrently": "^7.4.0",
"dotenv": "^16.0.3",
"electron": "^21.1.1",
"eslint": "^8.25.0",
"eslint-config-google": "^0.14.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.3.0",
"eslint-plugin-promise": "^6.1.0",
"eslint-plugin-react": "^7.31.10",
"wait-on": "^6.0.1"
},
"config": {
"forge": "./forge.config.js"
}
}
My forge.config.js:
module.exports = {
packagerConfig: {
ignore: [
/coverage.*/,
/node_modules.*/,
/public.*/,
/src.*/,
/\.env|\.gitignore|.*bak|eslint.*|package-lock.*|(?<!build.*)\.txt|(?<!build.*)\.md/
]
},
makers: [
{
name: '#electron-forge/maker-squirrel',
config: {
name: 'bkkgapp'
}
},
{
name: '#electron-forge/maker-zip'
}
]
}

Netlify deploy issue on build

site link - https://react-chat-page.netlify.app/
github - https://github.com/mrshawnhum/chat-app
I have recently added a redirect file to fix a bug when you refresh the site and I added automatic deploys with netlify-cli to my project. The first time I added Yarn Run Build and received an exit code 127 when attempting to deploy. I manually changed it on netlify to Yarn Build and still receive the same message. I also attempted to clear the cache and manually deploy the site and still receive the same message.
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"font-awesome": "^4.7.0",
"netlify-cli": "^2.58.0",
"query-string": "^6.13.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-emoji": "^0.5.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"react-scroll-to-bottom": "^3.0.0",
"socket.io-client": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"postbuild": "cp_redirects ./build/",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Netlify will start the build from the root folder of your git repo by default, which doesn't have your package.json file in it, and so Netlify doesn't know how to run yarn.
You can change that in the UI settings, see here.

Module not found: Error: Can't resolve 'hello.bundle.js' in 'D:\webpackDemo'

I am new to webpack.my situation is that: i try to use webpack for managing hello.js file.
hello.js
function hello(str){
alert(str);
}
package.json
{
"name": "webpackdemo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.1.1"
}
}
when i used
webpack hello.js hello.bundle.js
I get error in webstorm terminal
ERROR in multi ./hello.js hello.bundle.js
Module not found: Error: Can't resolve 'hello.bundle.js' in 'D:\webpackDemo'
# multi ./hello.js hello.bundle.js
It seems like, that the documentation is outdated, but try it like this using the -o flag (output.filename):
webpack ./hello.js -o hello.bundle.js --mode development
Use --mode production for production.

parse server deploying to aws

I am trying to deploy deploy my parse server, parse server dashboard, etc to aws. I am sure that the problem that I am experiencing is quite simple and it has to do with how I am packaging my ab node apps. I am downloading the git repo and then uploading the zip to my eb instance. It is in turn giving me this error.
After downloading a repository, such as parse server, what do I need to do to put it on elastic bean stalk? I already have the parse server example running on aws. I am just trying to upgrade versions.
here is my package.JSON file
{
"name": "parse-server",
"version": "2.2.16",
"description": "An express module providing a Parse-compatible API server",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/ParsePlatform/parse-server"
},
"files": [
"bin/",
"src/",
"public_html/",
"views/",
"LICENSE",
"PATENTS",
"README.md"
],
"license": "BSD-3-Clause",
"dependencies": {
"babel-polyfill": "6.8.0",
"babel-runtime": "6.6.1",
"bcrypt-nodejs": "0.0.3",
"body-parser": "1.15.2",
"colors": "1.1.2",
"commander": "2.9.0",
"deepcopy": "0.6.3",
"express": "4.14.0",
"intersect": "1.0.1",
"lodash": "4.12.0",
"lru-cache": "4.0.1",
"mailgun-js": "0.7.10",
"mime": "1.3.4",
"mongodb": "2.1.18",
"multer": "1.1.0",
"parse": "1.9.0",
"parse-server-fs-adapter": "1.0.0",
"parse-server-push-adapter": "1.0.4",
"parse-server-s3-adapter": "1.0.4",
"parse-server-simple-mailgun-adapter": "1.0.0",
"pg-promise": "5.2.0",
"redis": "2.6.2",
"request": "2.73.0",
"request-promise": "4.0.1",
"semver": "^5.2.0",
"tv4": "1.2.7",
"winston": "2.2.0",
"winston-daily-rotate-file": "1.1.5",
"ws": "1.1.1"
},
"devDependencies": {
"babel-cli": "6.8.0",
"babel-core": "6.10.4",
"babel-istanbul": "0.11.0",
"babel-plugin-syntax-flow": "6.8.0",
"babel-plugin-transform-flow-strip-types": "6.8.0",
"babel-preset-es2015": "6.6.0",
"babel-preset-stage-0": "6.5.0",
"babel-register": "6.8.0",
"codecov": "1.0.1",
"cross-env": "2.0.0",
"deep-diff": "0.3.4",
"gaze": "1.1.0",
"jasmine": "2.4.1",
"mongodb-runner": "3.3.2",
"nodemon": "1.9.2"
},
"scripts": {
"dev": "npm run build && node bin/dev",
"build": "./node_modules/.bin/babel src/ -d lib/",
"pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 ./node_modules/.bin/mongodb-runner start",
"test": "cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js",
"test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/** ./node_modules/jasmine/bin/jasmine.js && npm run posttest",
"posttest": "./node_modules/.bin/mongodb-runner stop",
"coverage": "cross-env COVERAGE_OPTION='./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**' npm test",
"start": "node ./bin/parse-server",
"prepublish": "npm run build"
},
"engines": {
"node": ">=4.3"
},
"bin": {
"parse-server": "./bin/parse-server"
}
}
You have to physically go into the repository and compress it into a new zip file. For some reason it would not accept zip files that I downloaded off of github.

Nested addon CSS not merged into vendor.css

I have an addon, my-addon-parent, that depends on a nested addon, my-addon-nested, that specified via the the dependencies property in my-addon-parent's package.json.
When I run the dummy app for my-addon-parent, the nested addon's CSS is imported correctly (I use the included hook to specify the import) and added to the vendor.css file.
However, when including my-addon-parent in an Ember app, the nested addons CSS is not added to the vendor.css file. Is there a hook/setting that I am missing? Below are the package.json for the app and the respective index.js files for the parent and nested addons.
Ember App package.json
{
"name": "my-app",
"version": "0.0.0",
"description": "My App.",
"private": true,
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"start": "ember server",
"build": "ember build",
"test": "ember test"
},
"repository": "",
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.0",
"connect-restreamer": "^1.0.1",
"ember-cli": "0.2.0",
"ember-cli-app-version": "0.3.2",
"ember-cli-babel": "^4.0.0",
"ember-cli-content-security-policy": "0.3.0",
"ember-cli-dependency-checker": "0.0.8",
"ember-cli-htmlbars": "0.7.4",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.9",
"ember-cli-uglify": "1.0.1",
"ember-data": "1.0.0-beta.15",
"ember-export-application-global": "^1.0.2",
"express": "^4.12.3",
"glob": "^4.5.3",
"morgan": "^1.5.2",
"my-addon-parent": "some/location"
}
}
my-addon-parent index.js
/* jshint node: true */
'use strict';
module.exports = {
name: 'my-addon-parent',
included: function (app) {
this._super.included(app);
app.import('vendor/my-addon-parent/my-addon-parent.css');
}
};
my-addon-nested index.js
/* jshint node: true */
'use strict';
module.exports = {
name: 'my-addon-nested',
included: function (app) {
this._super.included(app);
app.import('vendor/my-addon-nested/my-addon-nested.css');
}
};
This is currently not possible. Details here.