cypress run doesn't return to command line

Created on 26 Oct 2017  Â·  20Comments  Â·  Source: cypress-io/cypress

Current behavior:

cypress run

does not return to command line, under some circumstances, irrespective of the test results.

Desired behavior:

to return to command line, as the exit code is relevant when creating a build.

How to reproduce:

I could not replicate it, but the sequence of events in GUI is:
VISIT url # containing a hash-bang
XHR GET 200
XHR POST 404
XHR GET 200 # removes part of the URL hash-bang
CONTAINS something
XHR POST 200
XHR POST 200 # that's when the DOM get's updated with something
XHR GET 200
NEW URL # restoring the hash-bang

It works fine in the GUI, on both Chrome and Electron, but it's stuck in CLI with default browser (Electron).

Additional Info (images, stack traces, etc)

  • Operating System: MacOS Sierra 10.12.6
  • Cypress Version: 1.0.2
  • Browser Version: Electron 53
cli

Most helpful comment

@brian-mann @bahmutov I am also facing this issue in GitLab CI. All the tests are running fine but the control is not returning back to CLI.

Is this an issue with Cypress or I am doing something wrong?

I have attached a screenshot of this issue.

cypress ci build

Any help or direction will be greatly appreciated. Thanks!

All 20 comments

We're trying to use Cypress for WordPress's Gutenberg editor and we're experiencing the same issue. (See the travis job here https://travis-ci.org/WordPress/gutenberg/jobs/293142523)

Hmm, interesting, can we have diagnostic log - if you run cypress with DEBUG=cypress:* environment variable it will show a lot more

Sure

screen shot 2017-10-26 at 15 03 08

@brian-mann could it be timer problem? Because what we usually see after reporting test results is this

  - Cypress Version: 1.0.2
  cypress:server:timers queuing timer id 25 after 30000 ms +83ms
  cypress:server:timers child received timer id 25 +79ms
  cypress:server:timers clearing timer id 25 from queue { '24': { args: [], ms: 85000, cb: [Function] }, '25': { args: [], ms: 30000, cb: [Function: bound cleanupWebsocketResources] } } +3ms
  cypress:server:timers clearing timer id 24 from queue { '24': { args: [], ms: 85000, cb: [Function] } } +2ms
  cypress:server:timers clearing timer id 24 from queue {} +0ms
  cypress:server:timers child sending timer id 9 +89ms


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /tmp/cypress-test-tiny/cypress/videos/d3tft.mp4 (0 seconds)
  cypress:server Should copy Circle Artifacts? undefined +927ms


  (All Done)

  cypress:server about to exit with code 0 +2ms

We're trying to use Cypress for WordPress's Gutenberg editor and we're experiencing the same issue. (See the travis job here https://travis-ci.org/WordPress/gutenberg/jobs/293142523)

I tried to run the same tests with Chrome using cypress run --browser chrome and it returns to the command line just after finishing all tests.

When I execute the tests with --headed flag I see the following list of requests in the Network tab:

screen shot 2017-10-27 at 09 18 35

I also see this error on the console:

screen shot 2017-10-27 at 09 22 29

I'm having the same issue, how did you guys solve this?

Use chrome instead of electron as the selected browser 😎

I've seen an issue in TravisCI before with it not killing background processes per command. Basically those will continue to keep it open.

I'd try splitting up booting + backgrounding your webserver from running the Cypress process to see if that fixes it.

@brian-mann I just want to precise than It happens locally as well. (MacOS 10.13)

I found the issue on my end.
If your test has a combined describe/context/it(s) string length larger or equal of 250chars, cypress run hangs on a failed test, never returning to cli, irrespective of the browser.

Sent from my iPhone

On 6 Nov 2017, at 21:26, Riad Benguella notifications@github.com wrote:

@brian-mann I just want to precise than It happens locally as well. (MacOS 10.13)

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Wait, can you put a code block that does this into the issue - so we can reproduce this unexpected bug

Sent from my iPhone

On Nov 7, 2017, at 09:01, Paul Dan Pruteanu notifications@github.com wrote:

I found the issue on my end.
If your test looks like describe -> describe or context of a description larger than 176chars, cypress run hangs on a failed test, never returning to cli, irrespective of the browser.

Sent from my iPhone

On 6 Nov 2017, at 21:26, Riad Benguella notifications@github.com wrote:

@brian-mann I just want to precise than It happens locally as well. (MacOS 10.13)

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

// cypress/integration/test.js
describe(`my feature file`, () => {
    context(`that has a describe/ context/ it clause(s) which altogether contains
a combined description string length of 250 characters, when your test fails for
some reason or another`, () => {
        it(`halts, without showing the error, or returning to the CLI prompt`, () => {
            cy.visit('https://www.cypress.io/')
            cy.contains('Finally').should('not.exist')
        })
    })
})
/* `my feature filethat has a describe/ context/ it clause(s) which altogether contains
a combined description string length of 250 characters, when your test fails for
some reason or anotherhalts, without showing the error, or returning to the CLI prompt`
.length == 251. try remove 2 characters from any of the describe/ context/ it, and
the error will appear, alongside with the return to the command prompt.*/
./node_modules/.bin/cypress run --spec cypress/integration/test.js

It worths mentioning that if the test passes, the feedback is given, and it successfully returns to the prompt, irrespective of the combined string length.

For me it happens with Electron headless and

describe('Log Viewer', () => {
  beforeEach(() => {
    cy.visit(Cypress.env('HOST'));
  });

  it('should open the Log Viewer', () => {
    cy.getElementByTestId('log-viewer-tab').click();
    cy.getElementByTestId('log-viewer-notice').should('be.visible');
  });
});

Both locally on Mac and on Travis.
getElementByTestId is mine :)

Another issue I'm facing is related to beforeunload (#796).

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.pageRefreshConfirmation = (e) => {
            (e||window.event).returnValue = "Are you sure?";
        }
        window.addEventListener("beforeunload", window.pageRefreshConfirmation)
    </script>
</head>
<body>
    foo bar
</body>
</html>
// cypress/integration/test.js
describe(`beforeunload issue`, () => {

    context(`electron browser fails to return to CLI on a page with beforeunload,
even when removing the listener`, () => {
        it(`checks foo`, () => {
            cy.visit('http://127.0.0.1:8080/')
                .then(() => {
                    cy.window().then(win => win.removeEventListener(
                        'beforeunload',
                        win.pageRefreshConfirmation)
                    )
                })
            cy.contains('foo').should('be.visible')
        })
        it(`checks bar`, () => {
            cy.visit('http://127.0.0.1:8080/')
            cy.contains('bar').should('be.visible')
        })
    })
})

when running

./node_modules/.bin/cypress run --spec cypress/integration/test.js

you hang up, not getting returned to command prompt:
screen shot 2017-11-07 at 11 44 06

If I remove the event listener from index.html:

<script>
    window.pageRefreshConfirmation = (e) => {
        (e||window.event).returnValue = "If you continue, any information you have entered will not be saved.";
    }
    //window.addEventListener("beforeunload", window.pageRefreshConfirmation)
</script>

then I am returned to the command prompt
screen shot 2017-11-07 at 11 52 13

Thanks for your detailed report @paulpruteanu, it allowed me to solve this issue with a small workaround:

I simply clear the onbeforeunload function from the window. I am running it beforeEach although I suspect this is an overkill.

beforeEach(function () {
    cy.window().then(win => win.onbeforeunload = undefined);
});

@brian-mann @bahmutov I am also facing this issue in GitLab CI. All the tests are running fine but the control is not returning back to CLI.

Is this an issue with Cypress or I am doing something wrong?

I have attached a screenshot of this issue.

cypress ci build

Any help or direction will be greatly appreciated. Thanks!

I am experiencing the same issue running locally in OS X

I've had the same issue when running my tests with Electron.
In my case it was caused by a browser warning message that shows up when you're trying to close the page.
Like this one:
leave_site_prompt
I had to add some steps to navigate to another page that doesn't trigger this warning. Then the process could exit properly.
Hope this can help.

@igor-starostenko-ag Is funny that you posted that screenshot exactly when I was dealing with an issue in electron cause by that prompt

Unfortunately we have to close this issue due to inactivity. Please open a new issue if there is new information to provide concerning the original issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brian-mann picture brian-mann  Â·  3Comments

carloscheddar picture carloscheddar  Â·  3Comments

verheyenkoen picture verheyenkoen  Â·  3Comments

jennifer-shehane picture jennifer-shehane  Â·  3Comments

jennifer-shehane picture jennifer-shehane  Â·  3Comments