question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unit test code coverage is not exported

See original GitHub issue

Hi everyone, I’m trying to implement code coverage in my project react CRA + Typescript in e2e and unit tests and what is happening, is that when I run e2e tests, everything works fine but when I run unit testing, the files from the coverage folder and the .nyc_output folder are not being generated

I’m follow this tutorial: https://docs.cypress.io/guides/tooling/code-coverage.html#Introduction

package.json

{
  ...
  "devDependencies": {
    ...
    "@cypress/code-coverage": "^3.8.5",
    "babel-eslint": "^10.1.0",
    "babel-plugin-istanbul": "^6.0.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "cypress": "^6.1.0",
    "istanbul-lib-coverage": "^3.0.0",
    "nyc": "^15.1.0"
  },
  ...
}

.babelrc

{
    "presets": ["react-app", "@babel/preset-react"],
    "env": {
      "development": {
        "plugins": ["istanbul"]
      }
    },
    "plugins": ["transform-class-properties"]
}

cypress/plugins/index.ts

/// <reference types="cypress" />
const browserify = require("@cypress/browserify-preprocessor");

module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => {
	require("@cypress/code-coverage/task")(on, config);

	const options = browserify.defaultOptions;
	options.browserifyOptions.transform[1][1].babelrc = true;
	on("file:preprocessor", browserify({ ...options, typescript: require.resolve("typescript") }));

	return config;
};

cypress/support/index.ts

import "@cypress/code-coverage/support";
import "./commands";

To start testing, fisrt i start application with yarn start and after i run yarn cypress run --spec './cypress/integration/units/**/*'

I’m testing on my windows 10 computer with powershell but I need this to put in docker container to run on Drone CI. I’ll run the unit tests on each PR and when I open a PR for master/main I’ll run the unit tests and e2e tests

The console log shows:

Cannot find coverage file C:\Users\Paulo\Desktop\teste-eject\.nyc_output\out.json
Skipping coverage report

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
aslamjcommented, May 19, 2021

@bahmutov Can u please provide a solution to this issue? Of all the work we did to replace testing framework from Jest and Selenium to Cypress last year, this is the only limitation we are stuck now. Thanks.

4reactions
bahmutovcommented, Jan 19, 2021
const browserify = require('@cypress/browserify-preprocessor')
const options = browserify.defaultOptions
options.browserifyOptions.transform[1][1].babelrc = true
// instrumentation is not working if we set
options.typescript = require.resolve('typescript')
module.exports = browserify(options)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I unit test non-exported functions? - Stack Overflow
The following can be used in production code: import { exportedFn } from './myPackage';. And this can be used in unit tests:
Read more >
Testing Non-Exported Functions in JavaScript - Samantha Ming
To test exported function, you can simply import it. But what about non-exported functions? Well that's easy too, thanks to Rewire!
Read more >
Not Able To Export Unit Test Result to SonarQube
I want to export the test results to the SonarQube portal under my project. I was able to push the result of the...
Read more >
How to unit-test a private (non-exported) function in JavaScript
Writing unit-tests for a private function that is not exported from a module in JavaScript. Let us see how it can be done...
Read more >
Unit Testing Private (Non-Exported) Functions in JavaScript w
You can write 50 unit tests, but only cover 10-20% of your code base. This is why code coverage--and code coverage tools like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found