Skip to content

Commit 7914f68

Browse files
committed
fix type_spec for chrome
1 parent 1525713 commit 7914f68

File tree

4 files changed

+89
-38
lines changed

4 files changed

+89
-38
lines changed

packages/driver/test/cypress/integration/commands/actions/type_spec.coffee

+60-29
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,44 @@ Keyboard = Cypress.Keyboard
44
Promise = Cypress.Promise
55
$selection = require("../../../../../src/dom/selection")
66

7+
## trim new lines at the end of innerText
8+
## due to changing browser versions implementing
9+
## this differently
10+
trimInnerText = ($el) ->
11+
_.trimEnd($el.get(0).innerText, "\n")
12+
713
describe "src/cy/commands/actions/type", ->
814
before ->
915
cy
1016
.visit("/fixtures/dom.html")
1117
.then (win) ->
1218
@body = win.document.body.outerHTML
1319

20+
el = cy.$$('[contenteditable]:first').get(0)
21+
22+
innerHtml = el.innerHTML
23+
24+
## by default... the last new line by itself
25+
## will only ever count as a single new line...
26+
## but new lines above it will count as 2 new lines...
27+
## so by adding "3" new lines, the last counts as 1
28+
## and the first 2 count as 2...
29+
el.innerHTML = '<div><br></div>'.repeat(3)
30+
31+
## browsers changed their implementation
32+
## of the number of newlines that <div><br></div>
33+
## create. newer versions of chrome set 2 new lines
34+
## per set - whereas older ones create only 1 new line.
35+
## so we grab the current sets for the assertion later
36+
## so this test is browser version agnostic
37+
newLines = el.innerText
38+
39+
## disregard the last new line, and divide by 2...
40+
## this tells us how many multiples of new lines
41+
## the browser inserts for new lines other than
42+
## the last new line
43+
@multiplierNumNewLines = (newLines.length - 1) / 2
44+
1445
beforeEach ->
1546
doc = cy.state("document")
1647

@@ -1038,29 +1069,29 @@ describe "src/cy/commands/actions/type", ->
10381069
cy.$$('[contenteditable]:first').get(0).innerHTML = '<div>foo</div>'
10391070
cy.get("[contenteditable]:first")
10401071
.type("bar").then ($div) ->
1041-
expect($div.get(0).innerText).to.eql("foobar\n")
1072+
expect(trimInnerText($div)).to.eql("foobar")
10421073
expect($div.get(0).textContent).to.eql("foobar")
10431074
expect($div.get(0).innerHTML).to.eql("<div>foobar</div>")
10441075

10451076
it "can type into [contenteditable] with existing <p>", ->
10461077
cy.$$('[contenteditable]:first').get(0).innerHTML = '<p>foo</p>'
10471078
cy.get("[contenteditable]:first")
10481079
.type("bar").then ($div) ->
1049-
expect($div.get(0).innerText).to.eql("foobar\n\n")
1080+
expect(trimInnerText($div)).to.eql("foobar")
10501081
expect($div.get(0).textContent).to.eql("foobar")
10511082
expect($div.get(0).innerHTML).to.eql("<p>foobar</p>")
10521083

10531084
it "collapses selection to start on {leftarrow}", ->
10541085
cy.$$('[contenteditable]:first').get(0).innerHTML = '<div>bar</div>'
10551086
cy.get("[contenteditable]:first")
10561087
.type("{selectall}{leftarrow}foo").then ($div) ->
1057-
expect($div.get(0).innerText).to.eql("foobar\n")
1088+
expect(trimInnerText($div)).to.eql("foobar")
10581089

10591090
it "collapses selection to end on {rightarrow}", ->
10601091
cy.$$('[contenteditable]:first').get(0).innerHTML = '<div>bar</div>'
10611092
cy.get("[contenteditable]:first")
10621093
.type("{selectall}{leftarrow}foo{selectall}{rightarrow}baz").then ($div) ->
1063-
expect($div.get(0).innerText).to.eql("foobarbaz\n")
1094+
expect(trimInnerText($div)).to.eql("foobarbaz")
10641095

10651096
it "can remove a placeholder <br>", ->
10661097
cy.$$('[contenteditable]:first').get(0).innerHTML = '<div><br></div>'
@@ -1451,7 +1482,7 @@ describe "src/cy/commands/actions/type", ->
14511482

14521483
cy.get("[contenteditable]:first")
14531484
.type("{home}11{uparrow}{home}22{uparrow}{home}33").then ($div) ->
1454-
expect($div.get(0).innerText).to.eql("33foo\n22bar\n11baz\n")
1485+
expect(trimInnerText($div)).to.eql("33foo\n22bar\n11baz")
14551486

14561487
context "{end}", ->
14571488
it "sets which and keyCode to 35 and does not fire keypress events", (done) ->
@@ -1501,7 +1532,7 @@ describe "src/cy/commands/actions/type", ->
15011532

15021533
cy.get("[contenteditable]:first")
15031534
.type("{end}11{uparrow}{end}22{uparrow}{end}33").then ($div) ->
1504-
expect($div.get(0).innerText).to.eql("foo33\nbar22\nbaz11\n")
1535+
expect(trimInnerText($div)).to.eql("foo33\nbar22\nbaz11")
15051536

15061537
context "{uparrow}", ->
15071538
beforeEach ->
@@ -1540,7 +1571,7 @@ describe "src/cy/commands/actions/type", ->
15401571

15411572
cy.get("[contenteditable]:first")
15421573
.type("{leftarrow}{leftarrow}{uparrow}11{uparrow}22{downarrow}{downarrow}33").then ($div) ->
1543-
expect($div.get(0).innerText).to.eql("foo22\nb11ar\nbaz33\n")
1574+
expect(trimInnerText($div)).to.eql("foo22\nb11ar\nbaz33")
15441575

15451576
it "uparrow ignores current selection", ->
15461577
ce = cy.$$('[contenteditable]:first').get(0)
@@ -1556,7 +1587,7 @@ describe "src/cy/commands/actions/type", ->
15561587

15571588
cy.get("[contenteditable]:first")
15581589
.type("{uparrow}11").then ($div) ->
1559-
expect($div.get(0).innerText).to.eql("11foo\nbar\nbaz\n")
1590+
expect(trimInnerText($div)).to.eql("11foo\nbar\nbaz")
15601591

15611592
it "up and down arrow on textarea", ->
15621593
cy.$$('textarea:first').get(0).value = 'foo\nbar\nbaz'
@@ -1570,7 +1601,6 @@ describe "src/cy/commands/actions/type", ->
15701601
.type('{uparrow}{uparrow}')
15711602
.should('have.value', '14')
15721603

1573-
15741604
context "{downarrow}", ->
15751605
beforeEach ->
15761606
cy.$$("#comments").val("foo\nbar\nbaz")
@@ -1626,7 +1656,7 @@ describe "src/cy/commands/actions/type", ->
16261656

16271657
cy.get("[contenteditable]:first")
16281658
.type("{downarrow}22").then ($div) ->
1629-
expect($div.get(0).innerText).to.eql("foo\n22bar\nbaz\n")
1659+
expect(trimInnerText($div)).to.eql("foo\n22bar\nbaz")
16301660

16311661
context "{selectall}{del}", ->
16321662
it "can select all the text and delete", ->
@@ -1688,14 +1718,16 @@ describe "src/cy/commands/actions/type", ->
16881718
it "inserts new line into [contenteditable] ", ->
16891719
cy.get("#input-types [contenteditable]:first").invoke("text", "foo")
16901720
.type("bar{enter}baz{enter}{enter}{enter}quux").then ($div) ->
1691-
expect($div.get(0).innerText).to.eql("foobar\nbaz\n\n\nquux\n")
1721+
conditionalNewLines = "\n\n".repeat(@multiplierNumNewLines)
1722+
1723+
expect(trimInnerText($div)).to.eql("foobar\nbaz#{conditionalNewLines}\nquux")
16921724
expect($div.get(0).textContent).to.eql("foobarbazquux")
16931725
expect($div.get(0).innerHTML).to.eql("foobar<div>baz</div><div><br></div><div><br></div><div>quux</div>")
16941726

16951727
it "inserts new line into [contenteditable] from midline", ->
16961728
cy.get("#input-types [contenteditable]:first").invoke("text", "foo")
16971729
.type("bar{leftarrow}{enter}baz{leftarrow}{enter}quux").then ($div) ->
1698-
expect($div.get(0).innerText).to.eql("fooba\nba\nquuxzr\n")
1730+
expect(trimInnerText($div)).to.eql("fooba\nba\nquuxzr")
16991731
expect($div.get(0).textContent).to.eql("foobabaquuxzr")
17001732
expect($div.get(0).innerHTML).to.eql("fooba<div>ba</div><div>quuxzr</div>")
17011733

@@ -2312,7 +2344,6 @@ describe "src/cy/commands/actions/type", ->
23122344
.then ->
23132345
expect(changed).to.eql 0
23142346

2315-
23162347
describe "caret position", ->
23172348

23182349
it "respects being formatted by input event handlers"
@@ -2380,32 +2411,35 @@ describe "src/cy/commands/actions/type", ->
23802411
el.innerHTML = 'start'+
23812412
'<div>middle</div>'+
23822413
'<div>end</div>'
2414+
23832415
cy.get('[contenteditable]:first')
23842416
## move cursor to beginning of div
23852417
.type('{selectall}{leftarrow}')
2386-
.type('{rightarrow}'.repeat(14)+'[_I_]').then ->
2387-
expect(cy.$$('[contenteditable]:first').get(0).innerText).to.eql('start\nmiddle\ne[_I_]nd\n')
2418+
.type('{rightarrow}'.repeat(14)+'[_I_]').then ($el) ->
2419+
expect(trimInnerText($el)).to.eql('start\nmiddle\ne[_I_]nd')
23882420

23892421
it "can wrap cursor to prev line in [contenteditable] with {leftarrow}", ->
23902422
$el = cy.$$('[contenteditable]:first')
23912423
el = $el.get(0)
2424+
23922425
el.innerHTML = 'start'+
23932426
'<div>middle</div>'+
23942427
'<div>end</div>'
2395-
cy.get('[contenteditable]:first').type('{leftarrow}'.repeat(12)+'[_I_]').then ->
2396-
expect(cy.$$('[contenteditable]:first').get(0).innerText).to.eql('star[_I_]t\nmiddle\nend\n')
23972428

2429+
cy.get('[contenteditable]:first').type('{leftarrow}'.repeat(12)+'[_I_]').then ($el) ->
2430+
expect(trimInnerText($el)).to.eql('star[_I_]t\nmiddle\nend')
23982431

23992432
it "can wrap cursor to next line in [contenteditable] with {rightarrow} and empty lines", ->
24002433
$el = cy.$$('[contenteditable]:first')
24012434
el = $el.get(0)
2402-
el.innerHTML = '<div><br></div>'.repeat(4)+
2403-
'<div>end</div>'
2435+
el.innerHTML = '<div><br></div>'.repeat(4) + '<div>end</div>'
2436+
2437+
newLines = "\n\n\n".repeat(@multiplierNumNewLines)
24042438

24052439
cy.get('[contenteditable]:first')
24062440
.type('{selectall}{leftarrow}')
2407-
# .type('foobar'+'{rightarrow}'.repeat(6)+'[_I_]').then ->
2408-
# expect(cy.$$('[contenteditable]:first').get(0).innerText).to.eql('foobar\n\n\n\nen[_I_]d\n')
2441+
.type('foobar'+'{rightarrow}'.repeat(6)+'[_I_]').then ->
2442+
expect(trimInnerText($el)).to.eql("foobar#{newLines}\nen[_I_]d")
24092443

24102444
it "can use {rightarrow} and nested elements", ->
24112445
$el = cy.$$('[contenteditable]:first')
@@ -2415,19 +2449,19 @@ describe "src/cy/commands/actions/type", ->
24152449
cy.get('[contenteditable]:first')
24162450
.type('{selectall}{leftarrow}')
24172451
.type('{rightarrow}'.repeat(3)+'[_I_]').then ->
2418-
expect(cy.$$('[contenteditable]:first').get(0).innerText).to.eql('sta[_I_]rt\n')
2452+
expect(trimInnerText($el)).to.eql('sta[_I_]rt')
24192453

24202454
it "enter and \\n should act the same for [contenteditable]", ->
2421-
24222455
cleanseText = (text) ->
2423-
text.replace(/ /g, ' ')
2456+
## non breaking white space
2457+
text.split('\u00a0').join(' ')
24242458

24252459
expectMatchInnerText = ($el , innerText) ->
2426-
expect(cleanseText($el.get(0).innerText)).to.eql(innerText)
2460+
expect(cleanseText(trimInnerText($el))).to.eql(innerText)
24272461

24282462
## NOTE: this may only pass in Chrome since the whitespace may be different in other browsers
24292463
## even if actual and expected appear the same.
2430-
expected = "{\n foo: 1\n bar: 2\n baz: 3\n}\n"
2464+
expected = "{\n foo: 1\n bar: 2\n baz: 3\n}"
24312465
cy.get('[contenteditable]:first')
24322466
.invoke('html', '<div><br></div>')
24332467
.type('{{}{enter} foo: 1{enter} bar: 2{enter} baz: 3{enter}}')
@@ -2438,7 +2472,6 @@ describe "src/cy/commands/actions/type", ->
24382472
.should ($el) ->
24392473
expectMatchInnerText($el, expected)
24402474

2441-
24422475
it "enter and \\n should act the same for textarea", ->
24432476
expected = "{\n foo: 1\n bar: 2\n baz: 3\n}"
24442477
cy.get('textarea:first')
@@ -2449,8 +2482,6 @@ describe "src/cy/commands/actions/type", ->
24492482
.type('{{}\n foo: 1\n bar: 2\n baz: 3\n}')
24502483
.should('have.prop', 'value', expected)
24512484

2452-
2453-
24542485
describe "{enter}", ->
24552486
beforeEach ->
24562487
@$forms = cy.$$("#form-submits")

packages/driver/test/cypress/integration/commands/navigation_spec.coffee

+26-7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ describe "src/cy/commands/navigation", ->
9191
expect(stub2).to.be.calledOnce
9292
expect(stub3).to.be.calledOnce
9393

94+
# Array(100).fill().map ->
9495
it "removes listeners", ->
9596
win = cy.state("window")
9697

@@ -100,6 +101,14 @@ describe "src/cy/commands/navigation", ->
100101
expect(rel).to.be.calledWith("beforeunload")
101102
expect(rel).to.be.calledWith("unload")
102103

104+
105+
# cy.reload().then ->
106+
# cy.wrap(null).should ->
107+
# expect(rel).to.be.calledWith("beforeunload")
108+
# expect(rel).to.be.calledWith("unload")
109+
110+
111+
103112
describe "errors", ->
104113
beforeEach ->
105114
Cypress.config("defaultCommandTimeout", 50)
@@ -149,6 +158,7 @@ describe "src/cy/commands/navigation", ->
149158
expect(win.foo).to.be.undefined
150159

151160
it "throws when reload times out", (done) ->
161+
console.time('foo')
152162
locReload = cy.spy(Cypress.utils, "locReload")
153163

154164
cy
@@ -167,6 +177,8 @@ describe "src/cy/commands/navigation", ->
167177
cy.on "fail", (err) ->
168178
expected = true
169179

180+
console.timeEnd('foo')
181+
170182
expect(err.message).to.include "Your page did not fire its 'load' event within '1ms'."
171183

172184
.reload({timeout: 1})
@@ -232,17 +244,18 @@ describe "src/cy/commands/navigation", ->
232244
$(doc.body).empty().html(@body)
233245

234246
## TODO: fix this
235-
it.skip "(FLAKY) sets timeout to Cypress.config(pageLoadTimeout)", ->
236-
timeout = cy.spy Promise.prototype, "timeout"
237-
Cypress.config("pageLoadTimeout", 4567)
247+
# it.skip "(FLAKY) sets timeout to Cypress.config(pageLoadTimeout)", ->
248+
# timeout = cy.spy Promise.prototype, "timeout"
249+
# Cypress.config("pageLoadTimeout", 4567)
238250

239-
cy
240-
.visit("/fixtures/jquery.html")
241-
.go("back").then ->
242-
expect(timeout).to.be.calledWith(4567, "go")
251+
# cy
252+
# .visit("/fixtures/jquery.html")
253+
# .go("back").then ->
254+
# expect(timeout).to.be.calledWith(4567, "go")
243255

244256
it "removes listeners", ->
245257
cy
258+
.visit("/fixtures/generic.html")
246259
.visit("/fixtures/jquery.html")
247260
.then ->
248261
winLoadListeners = cy.listeners("window:load")
@@ -266,6 +279,7 @@ describe "src/cy/commands/navigation", ->
266279
stub3 = cy.stub()
267280

268281
cy
282+
.visit("/fixtures/generic.html")
269283
.visit("/fixtures/jquery.html")
270284
.then ->
271285
cy.on("stability:changed", stub1)
@@ -279,6 +293,7 @@ describe "src/cy/commands/navigation", ->
279293

280294
it "removes listeners from window", ->
281295
cy
296+
.visit("/fixtures/generic.html")
282297
.visit("/fixtures/jquery.html")
283298
.then (win) ->
284299
rel = cy.stub(win, "removeEventListener")
@@ -369,6 +384,7 @@ describe "src/cy/commands/navigation", ->
369384

370385
it "logs go", ->
371386
cy
387+
.visit("/fixtures/generic.html")
372388
.visit("/fixtures/jquery.html")
373389
.go("back").then ->
374390
lastLog = @lastLog
@@ -378,12 +394,14 @@ describe "src/cy/commands/navigation", ->
378394

379395
it "can turn off logging", ->
380396
cy
397+
.visit("/fixtures/generic.html")
381398
.visit("/fixtures/jquery.html")
382399
.go("back", {log: false}).then ->
383400
expect(@lastLog).to.be.undefined
384401

385402
it "does not log 'Page Load' events", ->
386403
cy
404+
.visit("/fixtures/generic.html")
387405
.visit("/fixtures/jquery.html")
388406
.go("back").then ->
389407
@logs.slice(0).forEach (log) ->
@@ -393,6 +411,7 @@ describe "src/cy/commands/navigation", ->
393411
beforeunload = false
394412

395413
cy
414+
.visit("/fixtures/generic.html")
396415
.visit("/fixtures/jquery.html")
397416
.window().then (win) ->
398417
cy.on "window:before:unload", =>

packages/driver/test/cypress/integration/e2e/return_value_spec.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe "return values", ->
2929

3030
it "stringifies function bodies", (done) ->
3131
cy.on "fail", (err) ->
32-
expect(err.message).to.include("> function () {")
32+
expect(err.message).to.include("> function")
3333
expect(err.message).to.include("return \"foo\";")
3434
expect(err.message).to.include("Cypress detected that you invoked one or more cy commands but returned a different value.")
3535

@@ -78,7 +78,7 @@ describe "return values", ->
7878
expect(lastLog.get("name")).to.eq("foo")
7979
expect(lastLog.get("error")).to.eq(err)
8080
expect(err.message).to.include("> cy.foo()")
81-
expect(err.message).to.include("> function () {")
81+
expect(err.message).to.include("> function")
8282
expect(err.message).to.include("return \"bar\";")
8383
expect(err.message).to.include("Cypress detected that you invoked one or more cy commands in a custom command but returned a different value.")
8484

packages/runner/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"lib"
2525
],
2626
"devDependencies": {
27+
"@babel/plugin-proposal-decorators": "7.4.0",
2728
"@babel/plugin-proposal-object-rest-spread": "7.4.0",
2829
"@cypress/react-tooltip": "0.4.0",
2930
"bin-up": "1.1.0",

0 commit comments

Comments
 (0)