Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find coverage file .nyc_output/out.json in the automated build. #528

Open
Muthu2190 opened this issue Nov 23, 2021 · 8 comments
Open

Comments

@Muthu2190
Copy link

Muthu2190 commented Nov 23, 2021

I have followed this example for my project https://github.com/bahmutov/next-and-cypress-example and i can get the output in the .nyc_output folder while running in local env, but not in the automated build.

package.json:
"devDependencies": {
"cy-verify-downloads": "0.0.5",
"cypress": "8.6.0",
"cypress-file-upload": "^5.0.8",
"typescript": "^4.4.3",
"@cypress/browserify-preprocessor": "^3.0.1",
"@cypress/code-coverage": "^3.8.1",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@testing-library/cypress": "^7.0.1",
"@types/testing-library__cypress": "^5.0.8",
"babel-plugin-istanbul": "^6.0.0",
"nyc": "^15.1.0"
},"nyc": {
"extends": "./.nycrc.json",
"report-dir": "cypress-coverage",
"reporter": [
"json",
"lcov"
]
}

.babelrc:
{
"presets": [
"next/babel"
],
"plugins": ["istanbul"]
}

.nycrc.json:
{
"extension": [".js", ".jsx", ".ts", ".tsx"],
"extends": "@istanbuljs/nyc-config-typescript",
"include": ["src/**/*"],
"all": true,
"sourceMap": true,
"instrument": true
}

cypress/support/index.js:
import '@cypress/code-coverage/support';

cypress/plugins/index.ts:

import browserify from '@cypress/browserify-preprocessor';

const pluginConfig: Cypress.PluginConfig = (on, config) => {
on('task', {
isFileExist
})
const options = browserify.defaultOptions;
options.browserifyOptions.transform[1][1].babelrc = true;
options.typescript = require.resolve('typescript');

require('@cypress/code-coverage/task')(on, config);
on('file:preprocessor', browserify(options));

return config;
};
module.exports = pluginConfig;

Error message from automated build:

Cannot find coverage file /tmp/build/515f5098/project_root_folder/.nyc_output/out.json
Skipping coverage report

@thednp
Copy link

thednp commented Apr 23, 2022

Any update or information on this?

@shirleyzhoufc
Copy link

is there any update? I came across same issue

@arberosmani
Copy link

arberosmani commented Oct 28, 2022

Same issue here. Locally it's working fine but on the gitlab-ci pipeline some tests are not passing:

...
    Test suite foo
      ✓ should ...
      ✓ should foo1
      ✓ should foo2
      ✓ should foo3
      1) "before each" hook for "should foo4"
Cannot find coverage file /appl/grp/gitlab-runner/builds/frhxYBZs/0/myapp/.nyc_output/out.json
Skipping coverage report
  10 passing (25s)
...

Any idea?

@thednp
Copy link

thednp commented Oct 28, 2022

@arberosmani you can have a look at my repo relatively recent update. The github cli doesn't fail.

Note: the repo is typescript!

@wuwei3
Copy link

wuwei3 commented May 29, 2023

no update on this issue?

@Baluditor
Copy link

I'm facing the same issue, any update on this one please?

@MKhasib
Copy link

MKhasib commented Sep 24, 2024

Hello @Baluditor @Muthu2190
I faced the issue with "vite-plugin-istanbul": "^5.0.0"
downgrading to "vite-plugin-istanbul": "^2.9.0" fixed it for me

You might have a different setup and need to see how code is instrumented using yoursetup

@Baluditor
Copy link

Hi @MKhasib, thank for the tip.
After a lot of trial and error I was able to come up with the following in my vite.config.ts:

import react from '@vitejs/plugin-react';
import { defineConfig, loadEnv } from 'vite';
import istanbul from 'vite-plugin-istanbul';
import svgr from 'vite-plugin-svgr';

export default ({ mode }) => {
  process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
  const shouldInstrument =
    process.env.VITE_APP_ENV === 'local' ||
    process.env.VITE_APP_ENV === 'testing' ||
    process.env.VITE_APP_ENV === 'qa';

  return defineConfig({
    base: '/',
    build: {
      sourcemap: true,
      rollupOptions: {
        // Silence warnings https://github.com/vitejs/vite/issues/15012
        onLog(level, log, handler) {
          if (
            log.cause &&
            log.cause['message'] === `Can't resolve original location of error.`
          ) {
            return;
          }
          handler(level, log);
        },
        output: {
          // Disable source maps for dependencies
          sourcemap: false,
        },
      },
    },
    plugins: [
      react(),
      svgr(),
      istanbul({
        extension: ['.js', '.jsx', '.ts', '.tsx'],
        exclude: ['node_modules', 'cypress', '**/*.cy.ts', '**/*.cy.tsx'],
        cypress: true,
        // By default it will always instrument the code.
        // We only want to instrument the code when we are running it locally or in the testing or QA environment.
        requireEnv: !shouldInstrument,
        forceBuildInstrument: shouldInstrument,
      }),
    ],
    server: {
      open: true,
      port: 3000,
    },
  });
};

It's not the pretties solution but it gets the job done. Will try to downgrade the package as well to see if it solves it, will report back (but it might take a while).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants