When i run jest coverage it do the coverage successfully but i dont get coverage folder with all details. I get only coverage folder with coverage-final.json file inside it. and i get this error
Failed to write coverage reports:
ERROR: Error: EPERM: operation not permitted, open
'D:\Programing\Wep\Development\Node Js\coverage\lcov.info'
my scripts
"scripts": {
"test": "jest --config jestconfig.json",
"test:coverage": "npm run test -- --coverage"
}
and jest config is
{
"transform": {
"^.+\\.(t|j)s?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/) (test|spec))\\.(js?|ts?)$",
"moduleFileExtensions": ["ts", "js"]
}
I expext to get coverage folder with all detailes inside it.
You just need to add theses properties into your jest config file
"collectCoverage": true,
"coverageReporters": ["json", "html"]
Related
I just started using nyc and Istanbul to generate a code coverage report. The fist thing I notest was that the coverage report only shows the coverage for files that are addressed in the tests. It does not show any coverage for files that are not tested at all.
If I have all my files in a directory called "src", is it possible to generate a report that includes all files in that directory (including those that have 0 tests so far)?
Currently my NPM scripts are (I am using Mocha and Chai).
"test": "mocha test/**/*.spec.js",
"nyc": "nyc --reporter=html npm test"
Try update package.json like:
"test": "mocha test/**/*.spec.js",
"coverage": "nyc --reporter=html npm test",
"nyc": {
"all": true
}
I'm going to write unit tests in my Symfony project that uses Vuejs for the front-end. I want to use Mocha framework as test runner for my components' tests. So I have configured and installed all things, following this guide: testing vuejs apps
But there's a problem, in my project I'm using Encore, and now I have some troubles to run tests.
I created the setup.js file in this directory of my root's project:
- assets
- js
- components
- test
- setup.js
So I have added in my package.json this config:
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production",
"compile-translations": "php bin/console bazinga:js-translation:dump public --format=js --merge-domains",
"compile-routes": "php bin/console fos:js-routing:dump --target=public/js/fos_js_routes.js",
"assets-install": "php bin/console assets:install --symlink --relative public",
"test": "cross-env NODE_ENV=test nyc mocha-webpack --webpack-config webpack.config.js --require assets/js/test/setup.js assets/js/test/**/*.spec.js"
},
"nyc": {
"include": [
"assets/js/**/*.(js|vue)"
],
"instrument": false,
"sourceMap": false
},
Now I have a problem, I should add this config in my webpack.config.js file
if (process.env.NODE_ENV === 'test'){
module.exports.externals = [require('webpack-node-externals')()]
module.exports.devtool = 'inline-cheap-module-source-map'
}
But I'm using Encore, so how can I do it?
I resolve the problem using Karma. For anyone that have the same problem, you should following this guide: https://vue-test-utils.vuejs.org/guides/testing-single-file-components-with-karma.html
and then in your karma.conf.js file add these lines at the top:
const Encore = require('#symfony/webpack-encore');
// Initialize Encore before requiring the .config file
Encore.configureRuntimeEnvironment('dev-server');
// Retrieve webpack config
const webpackConfig = require('./webpack.config.js');
I have create an app with create-react-app.
I have set in .env my NODE_PATH=src/
All works fine when I launch react-script start but when I launch react-script test I have an error: import is not found.
In my package.json :
"test": "jest --colors --coverage test"
Edit
It work fine with:
"jest": {
"modulePaths": ["src/"],
"testURL": "http://localhost",
"jest": "^22.4.4"
}
You should execute your tests with
npm test
instead of directly using react-scripts here. Jest is automatically configured while using project created by create-react-app.
If you want to directly call jest instead using the bundling set in react-scripts, you have to call:
"test": "./node_modules/jest/bin/jest.js --colors --coverage test"
I have setup jest and jest-junit as the reporter and followed the simple instructions given by jest-junit.
This includes npm install jest --save-dev and npm install jest-junit --save-dev
My package.json looks like this (excerpt):
"devDependencies": {
"jest": "^22.4.4",
"jest-junit": "^4.0.0",
},
"scripts": {
"test": "jest --ci --testResultsProcessor='jest-junit'"
},
"jest": {
"verbose": true,
"testResultsProcessor": "jest-junit"
},
"jest-junit": {
"suiteName": "Test Suite",
"output": "./junit.xml"
}
When running npm run test on my machine (OSX), it works well. When running it as part of the CI build process or on another Windows machine, I am getting the following error:
Module 'jest-junit' in the testResultsProcessor option was not found.
Maybe you just need to install the missing module to the other machine:
npm install jest-junit
Found the solution and it was the removal of inverted commas.
"test": "jest --ci --testResultsProcessor='jest-junit'"
should become
"test": "jest --ci --testResultsProcessor=jest-junit"
Following this writeup I am trying to write a script to compile my sass into css using node-sass.
This is my package.json scripts part:
"scripts" : {
"prestart" : "babel-node tools/startMessage.js",
"start" : "npm-run-all --parallel open:src lint:watch sass:watch test:watch",
"open:src": "babel-node tools/srcServer.js",
"lint": "node_modules/.bin/esw webpack.config.* src tools",
"lint:watch": "npm run lint -- --watch",
"sass": "node-sass src/assets/**/*.scss src/assets/css",
"sass:watch": "npm run sass -- --watch",
"test:watch": "npm run test -- --watch",
"test": "mocha --reporter progress tools/testSetup.js \"src/**/*.test.js\""
},
now when I run npm run sass trough the terminal I get the following message:
Introduction#1.0.0 sass /Users/shooshte/PersonalProjects/introductionReact
node-sass src/assets/**/*.scss src/assets/css
Rendering Complete, saving .css file... Error: EISDIR: illegal
operation on a directory, open
'/Users/shooshte/PersonalProjects/introductionReact/src/assets/css'
Both of the directories are created. What am I doing wrong?
If you need more info, just comment or you can also view the GitHub repo.
Thanks for the help.
EISDIR means you are trying to run an operation on a file, but you gave a directory (folder).
"sass": "node-sass src/assets/**/*.scss src/assets/css/*.css"
update the code to target a .css file instead of a folder.