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

Tweak Cypress to avoid unfinished resource waiting #2037

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Internal

- Tweak Cypress command `waitForResourceToLoad` to timeout after 50 tries. @tiberiuichim

## 10.1.0 (2020-11-30)

### Feature
Expand Down
9 changes: 9 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ Cypress.Commands.add(

Cypress.Commands.add('waitForResourceToLoad', (fileName, type) => {
const resourceCheckInterval = 40;
const maxChecks = 50;
const count = [0];

return new Cypress.Promise((resolve) => {
const checkIfResourceHasBeenLoaded = () => {
Expand All @@ -195,7 +197,14 @@ Cypress.Commands.add('waitForResourceToLoad', (fileName, type) => {
return;
}

count[0] += 1;
setTimeout(checkIfResourceHasBeenLoaded, resourceCheckInterval);

if (count[0] > maxChecks) {
throw new Error(
`Timeout resolving resource: ${fileName} (type ${type})`,
);
}
};

checkIfResourceHasBeenLoaded();
Expand Down