Skip to content

Commit

Permalink
consolidated tests, fixed randomly breaking ended early tests when co…
Browse files Browse the repository at this point in the history
…nsole is closed (!?)
  • Loading branch information
brian-mann committed Apr 22, 2015
1 parent 459c61a commit a81f00d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/js/api/cypress/cy/commands/navigation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $Cypress.register "Navigation", (Cypress, _, $) ->
command = Cypress.command()

_.defaults options,
timeout: 15000
timeout: 20000
onBeforeLoad: ->
onLoad: ->

Expand Down
10 changes: 0 additions & 10 deletions spec/client/api/cy/navigation_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ describe "$Cypress.Cy Navigation Commands", ->
enterCommandTestingMode()

context "#visit", ->
it "returns a promise", ->
promise = @cy.command("visit", "/foo")
expect(promise).to.be.instanceOf(Promise)

it "triggers visit:start on the remote iframe", (done) ->
$("iframe").one "visit:start", (e, url) ->
expect(url).to.eq "foo/"
Expand Down Expand Up @@ -60,12 +56,6 @@ describe "$Cypress.Cy Navigation Commands", ->
prev = @cy.prop("current").prev
expect(prev.args).to.have.length(1)

it "can change the timeout", ->
timeout = @sandbox.spy @cy.prop("runnable"), "timeout"

@cy.visit("fixtures/html/sinon.html", {timeout: 30000}).then ->
expect(timeout).to.be.calledWith 30000

describe "visit:start", ->
beforeEach ->
trigger = @sandbox.stub $.fn, "trigger"
Expand Down
28 changes: 0 additions & 28 deletions spec/client/api/integration/done_spec.coffee

This file was deleted.

29 changes: 27 additions & 2 deletions spec/client/api/integration/ended_early_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
describe "Timeout Integration Tests", ->
describe "Ended Early Integration Tests", ->
## dont console.error errors else it makes it look
## like our tests are failing!
enterIntegrationTestingMode("html/ended_early", {silent: true})

context "ended early", ->
it "correct associates runnable which ended early", (done) ->
beforeEach ->
## we need to restore the assertion
## else it will continue to patch
## and log out to Cypress!
@Cypress.chai.restoreAssert()

it "does not emit a command log", (done) ->
logs = []

@Cypress.on "log", (@log) =>
logs.push @log

@Cypress.on "fail", (err) =>
## two tests and 1 before each for visiting
## means we should only receive 2 logs both
## should be visits
expect(logs.length).to.eq(2)

names = _(logs).invoke "get", "name"
expect(names).to.deep.eq ["visit", "visit"]

done()

@Cypress.run ->

it "correctly associates runnable which ended early", (done) ->
runner = @Cypress.runner

@Cypress.run (failures) ->
Expand Down
13 changes: 2 additions & 11 deletions spec/client/api/integration/timeout_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe "Timeout Integration Tests", ->
enterIntegrationTestingMode("html/timeout")
enterIntegrationTestingMode("html/timeout", {silent: true})

context "timeouts", ->
it "has disabled all runnable timeouts", ->
Expand All @@ -14,13 +14,4 @@ describe "Timeout Integration Tests", ->

@Cypress.run (failures) ->
expect(failures).to.eq 0
done()

it "can time out", (done) ->
## only run one test
@Cypress.runner.grep(/can fail visiting/)

@Cypress.run (failures) =>
test = @Cypress.runner.getTestByTitle("can fail visiting")
expect(test.err.message).to.eq "Cypress command timeout of '500ms' exceeded."
done()
done()
12 changes: 10 additions & 2 deletions spec/fixtures/html/ended_early.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@
<script type="text/javascript">
describe("ending early [001]", function(){
beforeEach(function(){
cy.visit("fixtures/html/generic.html")
cy.inspect().visit("fixtures/html/generic.html", {timeout: 2000})
})

it("does not end early [002]", function(){

})

it("does end early [003]", function(done){
cy.then(function(){})
// for some bizarre reason, when the console in chrome
// is closed our commands are being processed BEFORE
// the done() callback (which makes no sense)
// so we are just returning an actual promise in the
// then function which prevents the noop functions
// from being called thus ensuring our test ends early
cy
.then(function(){ cy.Promise.delay(1000) })
.noop({}).noop({})

done()
})
Expand Down

0 comments on commit a81f00d

Please sign in to comment.