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

fix flakey tests #3227

Merged
merged 16 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions packages/driver/test/cypress/integration/commands/xhr_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1915,13 +1915,16 @@ describe "src/cy/commands/xhr", ->
xhr.foo = "bar"
resolve(xhr)
xhr.send()
.should (xhr) ->
## ensure this is set to prevent accidental
## race conditions down the road if something
## goes wrong
expect(xhr.foo).to.eq("bar")
expect(xhr.aborted).not.to.be.true
expect(log.get("state")).to.eq("passed")
.then (xhr) ->
cy
.wrap(null)
.should ->
## ensure this is set to prevent accidental
## race conditions down the road if something
## goes wrong
expect(xhr.foo).to.eq("bar")
expect(xhr.aborted).not.to.be.true
expect(log.get("state")).to.eq("passed")

context "Cypress.on(window:unload)", ->
it "aborts all open XHR's", ->
Expand Down
9 changes: 7 additions & 2 deletions packages/driver/test/cypress/integration/cy/timers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,17 @@ describe('driver/src/cy/timers', () => {
.then((win) => {
const stub1 = cy.stub()

win.setTimeout(stub1, 200)
// we're setting setTimeout to 500ms because
// there were times where the driver's webserver
// was sending bytes after 200ms (TTFB) that caused
// this test to be flaky.
win.setTimeout(stub1, 500)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just thought of a better approach here...

Instead of hoping the webserver sends us back the response in 500ms, we could instead use cypress events to wait for the window:unload event, gauranteeing this has happened.

At that point we could then set the setTimeout and then assert its not called after waiting.


// force the window to sync reload
win.location.reload()

cy
.wait(400)
.wait(800)
.then(() => {
expect(stub1).not.to.be.called
})
Expand Down