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.

Timeout running Cypress test

See original GitHub issue

Where to find the issue

https://github.com/corona-warn-app/cwa-website

Describe the issue

Executing npm test will sometimes time out.

Error: Timed out waiting for: http://localhost:8000
at ...\cwa-website\node_modules\wait-on\lib\wait-on.js:132:31````

According to https://github.com/bahmutov/start-server-and-test#readme

"Timeout

This utility will wait for maximum of 5 minutes while checking for the server to respond (default). Setting an environment variable WAIT_ON_TIMEOUT=600000 (milliseconds) sets the timeout for example to 10 minutes."

Steps to reproduce

In terminal of clone of cwa-website

  1. Execute npm test
  2. Note that sometimes the following error message appears:
Error: Timed out waiting for: http://localhost:8000
at ...\cwa-website\node_modules\wait-on\lib\wait-on.js:132:31

This seems to happen more often on the first run of npm test and on the second attempt it succeeds. This is sure to be dependent of the performance abilities of the host system (CPU, memory, etc.).

Current solution

Currently the script npm test invokes npm start which causes:

// Build the site, run the server, and watch for file changes
gulp.task('default', gulp.series('build', server, watch)); 

to run. The default timeout starts at the beginning of the build session, not at the beginning of the server start function call in gulp. As cwa-website has grown in size and complexity, the time to build the web has increased, so that the likelihood of timing out has now also increased.

Workarounds

There are two immediate workarounds:

  • increasing the timeout through an environment variable WAIT_ON_TIMEOUT
  • separating build and Cypress start in two different terminal windows

See below for further details:

Increase timeout through parameter

Create or edit .bash_profile in the user’s home directory to increase the timeout from the default 5 minutes to 10 minutes.

Add

export WAIT_ON_TIMEOUT
WAIT_ON_TIMEOUT=600000

This sets an environment variable which will be used by start-server-and-test and its use will show up in the log.

Split build and test start

This is equivalent to npm test.

Execute: npm start in a terminal window and wait for a browser window with http://localhost:8000/en/ to open.

In a separate terminal window execute: npx cypress run -b chrome

Suggested change

Restructure the scripts so that the default timeout for start-server-and-test starts running after the build has completed.

For instance:

  • add a new task in gulp.js which only runs server and watch, not build
  • modify the scripts in package.json so that the test scripts run the build task before running start-server-and-test and this in turn only starts the server without building the server contents

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
dsarkarcommented, Nov 29, 2021

@MikeMcC399 Thanks for the PR and all the feedback!

1reaction
MikeMcC399commented, Nov 10, 2021

Unfortunately PR #1997 did not work on all Windows systems, although it was fine on Ubuntu, Mac and Windows 10 Home.

I am working on a replacement PR which is (hopefully!) platform independent.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress and Flaky Tests: How to Handle Timeout Errors
In general, a “timeout” can occur when a program does not receive a response within a specified amount of time, resulting in an...
Read more >
Increase Timeout for specific its-Method of cypress.io
I'd prefer to set timeout for a specific test instead of modifying global config. it('should do something', { defaultCommandTimeout: 10000 } ...
Read more >
How To Stop Your Cypress Tests Timing Out
Increasing the timeout size is a bit of a hack and it's not the approach I would recommend to fix the test, but...
Read more >
Cypress timeout – uncovering website performance issues
All the commands in Cypress have a default timeout that means Cypress will wait for a definite time for the command to get...
Read more >
Configuration
See Test Retries for more information. watchForFileChanges, true, Whether Cypress will watch and restart tests on test file changes. Timeouts.
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