Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into simulated-type-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kuceb committed Sep 5, 2019
2 parents 733dad6 + 9f5c639 commit 9dda4ce
Show file tree
Hide file tree
Showing 22 changed files with 410 additions and 241 deletions.
2 changes: 1 addition & 1 deletion cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4364,7 +4364,7 @@ declare namespace Cypress {

type Encodings = 'ascii' | 'base64' | 'binary' | 'hex' | 'latin1' | 'utf8' | 'utf-8' | 'ucs2' | 'ucs-2' | 'utf16le' | 'utf-16le'
type PositionType = "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight"
type ViewportPreset = 'macbook-15' | 'macbook-13' | 'macbook-11' | 'ipad-2' | 'ipad-mini' | 'iphone-6+' | 'iphone-6' | 'iphone-5' | 'iphone-4' | 'iphone-3'
type ViewportPreset = 'macbook-15' | 'macbook-13' | 'macbook-11' | 'ipad-2' | 'ipad-mini' | 'iphone-xr' | 'iphone-x' | 'iphone-6+' | 'iphone-6' | 'iphone-5' | 'iphone-4' | 'iphone-3' | 'samsung-s10' | 'samsung-note9'
interface Offset {
top: number,
left: number
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"eslint": "6.1.0",
"eslint-plugin-cypress": "2.6.0",
"eslint-plugin-json-format": "2.0.0",
"eslint-plugin-mocha": "5.3.0",
"eslint-plugin-mocha": "6.1.0",
"eslint-plugin-react": "7.14.2",
"execa": "1.0.0",
"execa-wrap": "1.4.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/driver/src/cy/commands/navigation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ cannotVisit2ndDomain = (origin, previousDomainVisited, log) ->
}
})

specifyFileByRelativePath = (url, log) ->
$utils.throwErrByPath("visit.specify_file_by_relative_path", {
onFail: log
args: {
attemptedUrl: url
}
})

aboutBlank = (win) ->
new Promise (resolve) ->
cy.once("window:load", resolve)
Expand Down Expand Up @@ -602,6 +610,9 @@ module.exports = (Commands, Cypress, cy, state, config) ->
existing = $utils.locExisting()

## TODO: $Location.resolve(existing.origin, url)

if $Location.isLocalFileUrl(url)
return specifyFileByRelativePath(url, options._log)

## in the case we are visiting a relative url
## then prepend the existing origin to it
Expand Down
4 changes: 4 additions & 0 deletions packages/driver/src/cy/commands/window.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ viewports = {
"macbook-11" : "1366x768"
"ipad-2" : "768x1024"
"ipad-mini" : "768x1024"
"iphone-xr" : "414x896"
"iphone-x" : "375x812"
"iphone-6+" : "414x736"
"iphone-6" : "375x667"
"iphone-5" : "320x568"
"iphone-4" : "320x480"
"iphone-3" : "320x480"
"samsung-s10" : "360x760"
"samsung-note9" : "414x846"
}

validOrientations = ["landscape", "portrait"]
Expand Down
10 changes: 10 additions & 0 deletions packages/driver/src/cypress/error_messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,16 @@ module.exports = {
#{cmd('request')} will automatically get and set cookies and enable you to parse responses.
"""

specify_file_by_relative_path: """
#{cmd('visit')} failed because the 'file://...' protocol is not supported by Cypress.
To visit a local file, you can pass in the relative path to the file from the `projectRoot` (Note: if the configuration value `baseUrl` is set, the supplied path will be resolved from the `baseUrl` instead of `projectRoot`)
https://docs.cypress.io/api/commands/visit.html
https://docs.cypress.io/api/cypress-api/config.html
"""

wait:
alias_invalid: "'{{prop}}' is not a valid alias property. Are you trying to ask for the first request? If so write @{{str}}.request"
Expand Down
5 changes: 4 additions & 1 deletion packages/driver/src/cypress/location.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ipAddressRe = /^[\d\.]+$/

reHttp = /^https?:\/\//
reWww = /^www/

reFile = /^file:\/\//
reLocalHost = /^(localhost|0\.0\.0\.0|127\.0\.0\.1)/

class $Location
Expand Down Expand Up @@ -130,6 +130,9 @@ class $Location
toString: _.bind(@getToString, @)
}

@isLocalFileUrl = (url) ->
reFile.test(url)

@isFullyQualifiedUrl = (url) ->
reHttp.test(url)

Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/dom/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ const getContainsSelector = (text, filter = '') => {
const filters = filter.trim().split(',')

const selectors = _.map(filters, (filter) => {
return `${filter}:not(script):contains('${escapedText}'), ${filter}[type='submit'][value~='${escapedText}']`
return `${filter}:not(script,style):contains('${escapedText}'), ${filter}[type='submit'][value~='${escapedText}']`
})

return selectors.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,15 @@ describe "src/cy/commands/navigation", ->
.then ->
expect(backend).to.be.calledWithMatch("resolve:url", "http://localhost:3500/timeout", { auth })

it "does not support file:// protocol", (done) ->
Cypress.config("baseUrl", "")

cy.on "fail", (err) ->
expect(err.message).to.contain("cy.visit() failed because the 'file://...' protocol is not supported by Cypress.")
done()

cy.visit("file:///cypress/fixtures/generic.html")

## https://github.com/cypress-io/cypress/issues/1727
it "can visit a page with undefined content type and html-shaped body", ->
cy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,14 @@ describe "src/cy/commands/querying", ->
cy.contains("DOM Fixture").then ($el) ->
expect($el).not.to.match("title")

it 'will not find script elements', ->
cy.$$('<script>// some-script-content </script>').appendTo(cy.$$('body'))
cy.contains('some-script-content').should('not.match', 'script')

it 'will not find style elements', ->
cy.$$('<style> some-style-content {} </style>').appendTo(cy.$$('body'))
cy.contains('some-style-content').should('not.match', 'style')

it "finds the nearest element by :contains selector", ->
cy.contains("li 0").then ($el) ->
expect($el.length).to.eq(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,20 @@ describe "src/cy/commands/window", ->

cy.viewport("ipad-mini")

it "iphone-xr", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 414, viewportHeight: 896}
done()

cy.viewport("iphone-xr")

it "iphone-x", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 375, viewportHeight: 812}
done()

cy.viewport("iphone-x")

it "iphone-6+", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 414, viewportHeight: 736}
Expand Down Expand Up @@ -581,6 +595,20 @@ describe "src/cy/commands/window", ->

cy.viewport("iphone-5", "portrait")

it "samsung-s10", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 360, viewportHeight: 760}
done()

cy.viewport("samsung-s10")

it "samsung-note9", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 414, viewportHeight: 846}
done()

cy.viewport("samsung-note9")

context "errors", ->
beforeEach ->
Cypress.config("defaultCommandTimeout", 50)
Expand All @@ -596,7 +624,7 @@ describe "src/cy/commands/window", ->
it "throws with passed invalid preset", (done) ->
cy.on "fail", (err) =>
expect(@logs.length).to.eq(1)
expect(err.message).to.eq "cy.viewport() could not find a preset for: 'foo'. Available presets are: macbook-15, macbook-13, macbook-11, ipad-2, ipad-mini, iphone-6+, iphone-6, iphone-5, iphone-4, iphone-3"
expect(err.message).to.match /^cy.viewport\(\) could not find a preset for: 'foo'. Available presets are: /
done()

cy.viewport("foo")
Expand Down
186 changes: 1 addition & 185 deletions packages/server/__snapshots__/6_visit_spec.coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,188 +818,4 @@ Error: ESOCKETTIMEDOUT
1 of 1 failed (100%) XX:XX 3 - 3 - -
`

exports['e2e visit resolves visits quickly in chrome (headed) 1'] = `
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (fast_visit_spec.coffee) │
│ Searched: cypress/integration/fast_visit_spec.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: fast_visit_spec.coffee... (1 of 1)
Warning: Cypress can only record videos when using the built in 'electron' browser.
You have set the browser to: 'chrome'
A video will not be recorded when using this browser.
on localhost 95% of visits are faster than XX:XX, 80% are faster than XX:XX
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
✓ with connection: close
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
✓ with connection: keep-alive
2 passing
(Results)
┌──────────────────────────────────────┐
│ Tests: 2 │
│ Passing: 2 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: false │
│ Duration: X seconds │
│ Spec Ran: fast_visit_spec.coffee │
└──────────────────────────────────────┘
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ fast_visit_spec.coffee XX:XX 2 2 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
All specs passed! XX:XX 2 2 - - -
`

exports['e2e visit resolves visits quickly in electron (headless) 1'] = `
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (fast_visit_spec.coffee) │
│ Searched: cypress/integration/fast_visit_spec.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: fast_visit_spec.coffee... (1 of 1)
on localhost 95% of visits are faster than XX:XX, 80% are faster than XX:XX
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
✓ with connection: close
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
histogram line
✓ with connection: keep-alive
2 passing
(Results)
┌──────────────────────────────────────┐
│ Tests: 2 │
│ Passing: 2 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: fast_visit_spec.coffee │
└──────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /foo/bar/.projects/e2e/cypress/videos/abc123.mp4 (X seconds)
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ fast_visit_spec.coffee XX:XX 2 2 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
All specs passed! XX:XX 2 2 - - -
`
`
Loading

0 comments on commit 9dda4ce

Please sign in to comment.