cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.19k forks source link

Cypress crashing after adding code coverage and running all tests #8897

Closed craig-dae closed 1 year ago

craig-dae commented 4 years ago

Current behavior

After adding code coverage using the following walkthrough: https://dev.to/cssoldiervoif/code-coverage-with-cypress-angular-45pb

On the 39th test out of 53:

The following error was thrown by a plugin. We stopped running your tests because a plugin crashed. Please check your plugins file (`/home/craig/dev/Odin/frontend/cypress/plugins/index.js`)

 Error [ERR_IPC_CHANNEL_CLOSED] [ERR_IPC_CHANNEL_CLOSED]: Channel closed
    at ChildProcess.target.send (internal/child_process.js:679:16)
    at Object.send (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/lib/plugins/util.js:28:25)
    at /home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/lib/plugins/index.js:131:17
    at /home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/lib/plugins/util.js:80:14
    at Promise.cancellationExecute [as _execute] (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/debuggability.js:449:9)
    at Promise._resolveFromExecutor (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:103:10)
    at Object.wrapParentPromise (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/lib/plugins/util.js:58:12)
    at Object._get:task:body (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/lib/plugins/index.js:116:23)
    at Object.execute (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/lib/plugins/index.js:201:33)
    at /home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/lib/task.js:55:22
    at tryCatcher (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at /home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/catch_filter.js:17:41
    at tryCatcher (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/craig/.cache/Cypress/5.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:456:21)

    1) "after all" hook: generateReport for "Click Clone Button"

Desired behavior

I would like to be able to do an entire code coverage run.

Test code to reproduce

My plugins/index.js is:

/**
 * @type {Cypress.PluginConfig}
 */
const cypressTypeScriptPreprocessor = require('./cy-ts-preprocessor');
const registerCodeCoverageTasks = require('@cypress/code-coverage/task');
// const webpack = require('@cypress/webpack-preprocessor');

module.exports = (on, config) => {
  require('cypress-terminal-report/src/installLogsPrinter')(on);

  on('file:preprocessor', cypressTypeScriptPreprocessor);
  // on('task', {
  //   checkFixtureExistance: (fixtureName) => {
  //     const filePath = `cypress/fixtures/${fixtureName}.json`;
  //     return fs.existsSync(filePath);
  //   },
  // });
  on('before:browser:launch', (browser = {}, launchOptions) => {
    launchOptions.args.push('--max_old_space_size=1500');
    launchOptions.args.push('--disable-dev-shm-usage');
    return launchOptions;
  });

  return registerCodeCoverageTasks(on, config);
};

Versions

Cypress: 5.4.0 Angular: 10 @cypress/code-coverage": "^3.8.2", AWS Workspaces

It has been a real struggle to get code coverage working. Please help!

If I run a test directly, it works fine.

If, instead of using angular.json to do both the web frontendand cypress, I run the web frontend in one terminal and cypress in another, I get an out of memory error. Can't figure out how to give more memory to Cypress.

<--- Last few GCs --->

[27863:0xee600000000]   411401 ms: Scavenge (reduce) 3857.2 (3884.7) -> 3857.2 (3892.7) MB, 68.7 / 0.0 ms  (average mu = 0.853, current mu = 0.498) allocation failure 
[27863:0xee600000000]   411470 ms: Scavenge (reduce) 3857.2 (3884.7) -> 3857.2 (3892.7) MB, 68.1 / 0.0 ms  (average mu = 0.853, current mu = 0.498) allocation failure 
[27863:0xee600000000]   411536 ms: Scavenge (reduce) 3857.3 (3884.7) -> 3857.2 (3892.7) MB, 66.0 / 0.0 ms  (average mu = 0.853, current mu = 0.498) allocation failure 

<--- JS stacktrace --->

FATAL ERROR: Scavenger: semi-space copy Allocation failed - JavaScript heap out of memory
jennifer-shehane commented 4 years ago

@craig-dae You're setting up code coverage on the exact project mentioned in the tutorial right? Not your own project that you're adding code coverage to? Just wondering if the tests (or amount of tests run) may be having some effect on this.

craig-dae commented 4 years ago

No, I'm applying it to an existing project that is very large. I have over 300 tests across 53 spec files.

The amount of tests are probably having an affect. When I tell it to run all the tests, it takes a LONG time to load all of them into memory before it begins to run.

This is why I think I get different results if I 1) let Angular handle running the tests, via ng e2e vs 2) Running the app on its own and cypress on its own. When I do #1, I bump up the memory allocation to 8gb. When I do #2, I'm not sure how to bump memory allocation up on Cypress, and it fails before it runs the first test. Maybe I should try bumping it higher and doing #1 again to see what happens.

I've also added "numTestsKeptInMemory": 0, to my cypress.json file, as I've seen recommended in at least one other thread.

Update: I'm currently running tests with memory bumped up to 10gb. However, we'll have to figure out how to get this working in cicd with github actions, which is limited to 7gb.

craig-dae commented 4 years ago

I ran it with 10gb like: coverage": "node --max_old_space_size=10240 node_modules/@angular/cli/bin/ng run myapp:coverage",

It failed on the same test. Note that if I directly run the test where it starts failing, the test succeeds.

  1) An uncaught error was detected outside of a test:
     Error: The following error originated from your test code, not from Cypress.

  > Fetching resource at '/__cypress/tests?p=cypress/integration/outcomes/outcome-contributor.spec.ts' failed

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.
      at XMLHttpRequest.xhr.onerror (http://localhost.localdomain:8080/__cypress/runner/cypress_runner.js:174971:14)
craig-dae commented 4 years ago

WOOHOO!

Adding transpileOnly: true allowed me to successfully run everything.

I don't understand what that does or why it helped, but it got all the way through!

        use: [
          {
            loader: 'ts-loader',
            options: {
              transpileOnly: true,
            },
          },

If it continues to work, I'll close this ticket later today.

enykeev commented 3 years ago

While transpileOnly solution helps mitigate the problem when it first encountered, it seem to just hide the bigger problem.

During the initial load, cypress makes a lot of requests to url's such as http://127.0.0.1:8080/__cypress/tests?p=cypress/integration/qa/alerts.spec.ts. Some of them pass, but quite a few get cancelled. Then it repeats same song and dance over and over trying to load them and eventually getting more and more of them loaded. At some point it either loads them all or fails with ERR_IPC_CHANNEL_CLOSED.

It seems to me that Cypress does not account for the fact that code base can take a really long time to transpile or runs out of resources while doing it.

cypress-app-bot commented 1 year ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

cypress-app-bot commented 1 year ago

This issue has been closed due to inactivity.