Timeout running Cypress test
See original GitHub issueWhere 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
- Execute
npm test
- 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 runsserver
andwatch
, notbuild
- modify the scripts in
package.json
so that the test scripts run thebuild
task before running start-server-and-test and this in turn only starts the server without building the server contents
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
@MikeMcC399 Thanks for the PR and all the feedback!
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.