mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-05 06:20:44 -05:00
decaffeinate: Convert assertions_failing_outside_of_test_spec.coffee and 18 other files to JS
This commit is contained in:
committed by
Jennifer Shehane
parent
828d856bee
commit
b5af00ff5f
+1
-1
@@ -1 +1 @@
|
||||
expect(true).to.be.false
|
||||
expect(true).to.be.false;
|
||||
+1
-1
@@ -1 +1 @@
|
||||
expect(true).to.be.true
|
||||
expect(true).to.be.true;
|
||||
+17
-9
@@ -1,13 +1,21 @@
|
||||
describe "async", ->
|
||||
it "bar fails", (done) ->
|
||||
@timeout(100)
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("async", function() {
|
||||
it("bar fails", function(done) {
|
||||
this.timeout(100);
|
||||
|
||||
cy.on "fail", ->
|
||||
cy.on("fail", function() {});
|
||||
|
||||
## async caught fail
|
||||
foo.bar()
|
||||
//# async caught fail
|
||||
return foo.bar();
|
||||
});
|
||||
|
||||
it "fails async after cypress command", (done) ->
|
||||
@timeout(100)
|
||||
return it("fails async after cypress command", function(done) {
|
||||
this.timeout(100);
|
||||
|
||||
cy.wait(0)
|
||||
return cy.wait(0);
|
||||
});
|
||||
});
|
||||
|
||||
+8
-5
@@ -1,5 +1,8 @@
|
||||
describe "base url", ->
|
||||
it "can visit", ->
|
||||
cy
|
||||
.visit("/html")
|
||||
.contains("Herman Melville")
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("base url", () => it("can visit", () => cy
|
||||
.visit("/html")
|
||||
.contains("Herman Melville")));
|
||||
|
||||
+23
-24
@@ -1,26 +1,25 @@
|
||||
describe "block hosts", ->
|
||||
it "forces blocked hosts to return 503", ->
|
||||
cy
|
||||
.visit("http://localhost:3232")
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("block hosts", () => it("forces blocked hosts to return 503", () => cy
|
||||
.visit("http://localhost:3232")
|
||||
|
||||
.window().then (win) ->
|
||||
new Promise (resolve) ->
|
||||
xhr = new win.XMLHttpRequest
|
||||
xhr.open("GET", "http://localhost:3232/req")
|
||||
xhr.setRequestHeader('Content-Type', 'text/plain')
|
||||
xhr.send()
|
||||
xhr.onload = ->
|
||||
resolve(xhr)
|
||||
.its("status").should("eq", 200)
|
||||
.window().then(win => new Promise(function(resolve) {
|
||||
const xhr = new win.XMLHttpRequest;
|
||||
xhr.open("GET", "http://localhost:3232/req");
|
||||
xhr.setRequestHeader('Content-Type', 'text/plain');
|
||||
xhr.send();
|
||||
return xhr.onload = () => resolve(xhr);
|
||||
})).its("status").should("eq", 200)
|
||||
|
||||
.window().then (win) ->
|
||||
new Promise (resolve) ->
|
||||
xhr = new win.XMLHttpRequest
|
||||
xhr.open("GET", "http://localhost:3131/req")
|
||||
xhr.setRequestHeader('Content-Type', 'text/plain')
|
||||
xhr.send()
|
||||
xhr.onerror = ->
|
||||
## cross origin requests which return 503
|
||||
## result in a zero status code
|
||||
resolve(xhr)
|
||||
.its("status").should("eq", 0)
|
||||
.window().then(win => new Promise(function(resolve) {
|
||||
const xhr = new win.XMLHttpRequest;
|
||||
xhr.open("GET", "http://localhost:3131/req");
|
||||
xhr.setRequestHeader('Content-Type', 'text/plain');
|
||||
xhr.send();
|
||||
return xhr.onerror = () => //# cross origin requests which return 503
|
||||
//# result in a zero status code
|
||||
resolve(xhr);
|
||||
})).its("status").should("eq", 0)));
|
||||
|
||||
+17
-13
@@ -1,15 +1,19 @@
|
||||
req = (win) ->
|
||||
new Promise (resolve, reject) ->
|
||||
rand = Math.random()
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const req = win => new Promise(function(resolve, reject) {
|
||||
const rand = Math.random();
|
||||
|
||||
xhr = new win.XMLHttpRequest()
|
||||
xhr.open("GET", "http://localhost:1515/cached/")
|
||||
xhr.onload = -> resolve(win)
|
||||
xhr.onerror = reject
|
||||
xhr.send()
|
||||
const xhr = new win.XMLHttpRequest();
|
||||
xhr.open("GET", "http://localhost:1515/cached/");
|
||||
xhr.onload = () => resolve(win);
|
||||
xhr.onerror = reject;
|
||||
return xhr.send();
|
||||
});
|
||||
|
||||
it "makes cached request", ->
|
||||
cy
|
||||
.visit("http://localhost:1515")
|
||||
.then(req) ## this creates the disk cache
|
||||
.then(req) ## this should not hit our server
|
||||
it("makes cached request", () => cy
|
||||
.visit("http://localhost:1515")
|
||||
.then(req) //# this creates the disk cache
|
||||
.then(req)); //# this should not hit our server
|
||||
|
||||
+82
-89
@@ -1,100 +1,93 @@
|
||||
## the goal of what we want to achieve in regards to caching is this
|
||||
## 1. for internal file server requests, do not cache but do set etags
|
||||
## 2. for http server requests, respect whatever the 3rd party server sends
|
||||
## 3. for any kind of cy.visit always force cache-control: no-cache headers
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
//# the goal of what we want to achieve in regards to caching is this
|
||||
//# 1. for internal file server requests, do not cache but do set etags
|
||||
//# 2. for http server requests, respect whatever the 3rd party server sends
|
||||
//# 3. for any kind of cy.visit always force cache-control: no-cache headers
|
||||
|
||||
send = (win) ->
|
||||
new Cypress.Promise (resolve) ->
|
||||
xhr = new win.XMLHttpRequest
|
||||
xhr.open("GET", "/static/foo.js")
|
||||
xhr.send()
|
||||
xhr.onload = ->
|
||||
resolve({
|
||||
body: xhr.response
|
||||
etag: xhr.getResponseHeader("etag")
|
||||
cacheControl: xhr.getResponseHeader("cache-control")
|
||||
})
|
||||
const send = win => new Cypress.Promise(function(resolve) {
|
||||
const xhr = new win.XMLHttpRequest;
|
||||
xhr.open("GET", "/static/foo.js");
|
||||
xhr.send();
|
||||
return xhr.onload = () => resolve({
|
||||
body: xhr.response,
|
||||
etag: xhr.getResponseHeader("etag"),
|
||||
cacheControl: xhr.getResponseHeader("cache-control")
|
||||
});
|
||||
});
|
||||
|
||||
describe "caching", ->
|
||||
it "does not cache cy.visit file server requests", ->
|
||||
cy
|
||||
.request("POST", "http://localhost:1515/write/hi")
|
||||
.visit("/index.html?local")
|
||||
.get("h1").should("contain", "hi")
|
||||
.request("POST", "http://localhost:1515/write/hello")
|
||||
.visit("/index.html?local")
|
||||
.get("h1").should("contain", "hello")
|
||||
describe("caching", function() {
|
||||
it("does not cache cy.visit file server requests", () => cy
|
||||
.request("POST", "http://localhost:1515/write/hi")
|
||||
.visit("/index.html?local")
|
||||
.get("h1").should("contain", "hi")
|
||||
.request("POST", "http://localhost:1515/write/hello")
|
||||
.visit("/index.html?local")
|
||||
.get("h1").should("contain", "hello"));
|
||||
|
||||
it "sets etags on file assets, but no cache-control", ->
|
||||
cy
|
||||
.writeFile("static/foo.js", "alert('hi')")
|
||||
.visit("/index.html?local")
|
||||
.window().then (win) ->
|
||||
send(win)
|
||||
.then (resp1) ->
|
||||
## make sure our file server is not telling the browser
|
||||
## to cache anything
|
||||
expect(resp1.cacheControl).to.eq("public, max-age=0")
|
||||
it("sets etags on file assets, but no cache-control", () => cy
|
||||
.writeFile("static/foo.js", "alert('hi')")
|
||||
.visit("/index.html?local")
|
||||
.window().then(win => send(win)).then(function(resp1) {
|
||||
//# make sure our file server is not telling the browser
|
||||
//# to cache anything
|
||||
expect(resp1.cacheControl).to.eq("public, max-age=0");
|
||||
|
||||
cy
|
||||
.window().then (win) ->
|
||||
send(win)
|
||||
.then (resp2) ->
|
||||
## these responses should be identical
|
||||
expect(resp1).to.deep.eq(resp2)
|
||||
return cy
|
||||
.window().then(win => send(win)).then(function(resp2) {
|
||||
//# these responses should be identical
|
||||
expect(resp1).to.deep.eq(resp2);
|
||||
|
||||
cy
|
||||
## now change our static files' content
|
||||
.writeFile("static/foo.js", "console.log('bar')")
|
||||
.window().then (win) ->
|
||||
send(win)
|
||||
.then (resp3) ->
|
||||
## etags should now no longer match!
|
||||
expect(resp1.etag).not.to.eq(resp3.etag)
|
||||
return cy
|
||||
//# now change our static files' content
|
||||
.writeFile("static/foo.js", "console.log('bar')")
|
||||
.window().then(win => send(win)).then(function(resp3) {
|
||||
//# etags should now no longer match!
|
||||
expect(resp1.etag).not.to.eq(resp3.etag);
|
||||
|
||||
## nor should bodies match
|
||||
expect(resp1.body).not.to.eq(resp3.body)
|
||||
//# nor should bodies match
|
||||
expect(resp1.body).not.to.eq(resp3.body);
|
||||
|
||||
## but cache control should
|
||||
expect(resp1.cacheControl).to.eq(resp3.cacheControl)
|
||||
//# but cache control should
|
||||
return expect(resp1.cacheControl).to.eq(resp3.cacheControl);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it "does not cache cy.visit http server requests", ->
|
||||
## even though our server sends down cache headers
|
||||
## we are explicitly turning them off in the proxy
|
||||
## whenever we have to inject new content into the page
|
||||
cy
|
||||
.request("POST", "http://localhost:1515/write/hi")
|
||||
.visit("http://localhost:1515/index.html?http")
|
||||
.get("h1").should("contain", "hi")
|
||||
.request("POST", "http://localhost:1515/write/foo")
|
||||
.visit("http://localhost:1515/index.html?http")
|
||||
.get("h1").should("contain", "foo")
|
||||
it("does not cache cy.visit http server requests", () => //# even though our server sends down cache headers
|
||||
//# we are explicitly turning them off in the proxy
|
||||
//# whenever we have to inject new content into the page
|
||||
cy
|
||||
.request("POST", "http://localhost:1515/write/hi")
|
||||
.visit("http://localhost:1515/index.html?http")
|
||||
.get("h1").should("contain", "hi")
|
||||
.request("POST", "http://localhost:1515/write/foo")
|
||||
.visit("http://localhost:1515/index.html?http")
|
||||
.get("h1").should("contain", "foo"));
|
||||
|
||||
it "respects cache control headers from 3rd party http servers", ->
|
||||
cy
|
||||
.writeFile("static/foo.js", "alert('hi')")
|
||||
.visit("http://localhost:1515/index.html?http")
|
||||
.window().then (win) ->
|
||||
send(win)
|
||||
.then (resp1) ->
|
||||
## we've set express.static to cache assets
|
||||
expect(resp1.cacheControl).to.eq("public, max-age=3600")
|
||||
return it("respects cache control headers from 3rd party http servers", () => cy
|
||||
.writeFile("static/foo.js", "alert('hi')")
|
||||
.visit("http://localhost:1515/index.html?http")
|
||||
.window().then(win => send(win)).then(function(resp1) {
|
||||
//# we've set express.static to cache assets
|
||||
expect(resp1.cacheControl).to.eq("public, max-age=3600");
|
||||
|
||||
cy
|
||||
.window().then (win) ->
|
||||
send(win)
|
||||
.then (resp2) ->
|
||||
## these responses should be identical
|
||||
expect(resp1).to.deep.eq(resp2)
|
||||
return cy
|
||||
.window().then(win => send(win)).then(function(resp2) {
|
||||
//# these responses should be identical
|
||||
expect(resp1).to.deep.eq(resp2);
|
||||
|
||||
cy
|
||||
## now change our static files' content
|
||||
.writeFile("static/foo.js", "console.log('bar')")
|
||||
.window().then (win) ->
|
||||
send(win)
|
||||
.then (resp3) ->
|
||||
## but because of the cache-control headers
|
||||
## our browser should NOT have made a
|
||||
## new http request and therefore all of
|
||||
## these should still match
|
||||
expect(resp1).to.deep.eq(resp3)
|
||||
return cy
|
||||
//# now change our static files' content
|
||||
.writeFile("static/foo.js", "console.log('bar')")
|
||||
.window().then(win => send(win)).then(resp3 => //# but because of the cache-control headers
|
||||
//# our browser should NOT have made a
|
||||
//# new http request and therefore all of
|
||||
//# these should still match
|
||||
expect(resp1).to.deep.eq(resp3));
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
+43
-42
@@ -1,54 +1,55 @@
|
||||
describe "foo", ->
|
||||
it "baz fails", ->
|
||||
## synchronous caught fail
|
||||
foo.bar()
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("foo", function() {
|
||||
it("baz fails", () => //# synchronous caught fail
|
||||
foo.bar());
|
||||
|
||||
it "bar fails", (done) ->
|
||||
## async caught fail
|
||||
foo.bar()
|
||||
it("bar fails", done => //# async caught fail
|
||||
foo.bar());
|
||||
|
||||
it "quux fails", (done) ->
|
||||
## commands caught never calling done
|
||||
## with no fail handler should immediately die
|
||||
cy.wrap(null).then ->
|
||||
foo.bar()
|
||||
it("quux fails", done => //# commands caught never calling done
|
||||
//# with no fail handler should immediately die
|
||||
cy.wrap(null).then(() => foo.bar()));
|
||||
|
||||
it "quux2 fails", (done) ->
|
||||
cy.on "fail", ->
|
||||
foo.bar()
|
||||
it("quux2 fails", function(done) {
|
||||
cy.on("fail", () => foo.bar());
|
||||
|
||||
## commands caught never calling done
|
||||
## but have a failing handler should die
|
||||
cy.wrap(null).then ->
|
||||
foo.bar()
|
||||
//# commands caught never calling done
|
||||
//# but have a failing handler should die
|
||||
return cy.wrap(null).then(() => foo.bar());
|
||||
});
|
||||
|
||||
it "quux3 passes", (done) ->
|
||||
cy.on "fail", ->
|
||||
done()
|
||||
it("quux3 passes", function(done) {
|
||||
cy.on("fail", () => done());
|
||||
|
||||
## commands caught with a fail handler
|
||||
## and call done should pass
|
||||
cy.wrap(null).then ->
|
||||
foo.bar()
|
||||
//# commands caught with a fail handler
|
||||
//# and call done should pass
|
||||
return cy.wrap(null).then(() => foo.bar());
|
||||
});
|
||||
|
||||
it "quux4 passes", ->
|
||||
cy.on "fail", ->
|
||||
it("quux4 passes", function() {
|
||||
cy.on("fail", function() {});
|
||||
|
||||
## commands caught with a fail handler
|
||||
## and no done callback will pass if
|
||||
## nothing throws in the fail callback
|
||||
cy.wrap(null).then ->
|
||||
foo.bar()
|
||||
//# commands caught with a fail handler
|
||||
//# and no done callback will pass if
|
||||
//# nothing throws in the fail callback
|
||||
return cy.wrap(null).then(() => foo.bar());
|
||||
});
|
||||
|
||||
it "quux5 passes", ->
|
||||
cy.on "fail", ->
|
||||
it("quux5 passes", function() {
|
||||
cy.on("fail", function() {});
|
||||
|
||||
## no commands fail handler should pass
|
||||
foo.bar()
|
||||
//# no commands fail handler should pass
|
||||
return foo.bar();
|
||||
});
|
||||
|
||||
it "quux6 passes", (done) ->
|
||||
cy.on "fail", ->
|
||||
done()
|
||||
return it("quux6 passes", function(done) {
|
||||
cy.on("fail", () => done());
|
||||
|
||||
## no commands fail async handler should pass
|
||||
foo.bar()
|
||||
//# no commands fail async handler should pass
|
||||
return foo.bar();
|
||||
});
|
||||
});
|
||||
|
||||
+13
-7
@@ -1,9 +1,15 @@
|
||||
describe "No Running Test", ->
|
||||
it "foo", ->
|
||||
cy.noop()
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("No Running Test", function() {
|
||||
it("foo", () => cy.noop());
|
||||
|
||||
it "bar", ->
|
||||
it("bar", function() {});
|
||||
|
||||
context "nested suite", ->
|
||||
cy.viewport("iphone-6")
|
||||
cy.get("h1")
|
||||
return context("nested suite", function() {
|
||||
cy.viewport("iphone-6");
|
||||
return cy.get("h1");
|
||||
});
|
||||
});
|
||||
|
||||
+43
-34
@@ -1,42 +1,51 @@
|
||||
describe "Cypress static methods + props", ->
|
||||
it ".version", ->
|
||||
expect(Cypress.version).to.be.a("string")
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("Cypress static methods + props", function() {
|
||||
it(".version", () => expect(Cypress.version).to.be.a("string"));
|
||||
|
||||
it ".platform", ->
|
||||
expect(Cypress.platform).to.be.a("string")
|
||||
expect(Cypress.platform).to.be.oneOf(["darwin", "linux", "win32"])
|
||||
it(".platform", function() {
|
||||
expect(Cypress.platform).to.be.a("string");
|
||||
return expect(Cypress.platform).to.be.oneOf(["darwin", "linux", "win32"]);
|
||||
});
|
||||
|
||||
it ".arch", ->
|
||||
expect(Cypress.arch).to.be.a("string")
|
||||
it(".arch", () => expect(Cypress.arch).to.be.a("string"));
|
||||
|
||||
it ".browser", ->
|
||||
{ browser } = Cypress
|
||||
it(".browser", function() {
|
||||
const { browser } = Cypress;
|
||||
|
||||
expect(browser).to.be.an("object")
|
||||
expect(browser.name).to.be.oneOf(["electron", "chrome", "chromium"])
|
||||
expect(browser.displayName).to.be.oneOf(["Electron", "Chrome", "Canary", "Chromium"])
|
||||
expect(browser.version).to.be.a("string")
|
||||
# we are parsing major version, so it should be a number
|
||||
expect(browser.majorVersion).to.be.a("number")
|
||||
expect(browser.path).to.be.a("string")
|
||||
expect(browser).to.be.an("object");
|
||||
expect(browser.name).to.be.oneOf(["electron", "chrome", "chromium"]);
|
||||
expect(browser.displayName).to.be.oneOf(["Electron", "Chrome", "Canary", "Chromium"]);
|
||||
expect(browser.version).to.be.a("string");
|
||||
// we are parsing major version, so it should be a number
|
||||
expect(browser.majorVersion).to.be.a("number");
|
||||
expect(browser.path).to.be.a("string");
|
||||
|
||||
switch browser.isHeadless
|
||||
when true
|
||||
expect(browser.isHeaded).to.be.false
|
||||
when false
|
||||
expect(browser.isHeaded).to.be.true
|
||||
else
|
||||
expect(browser.isHeadless, "browser.isHeadless").not.to.be.undefined
|
||||
switch (browser.isHeadless) {
|
||||
case true:
|
||||
return expect(browser.isHeaded).to.be.false;
|
||||
case false:
|
||||
return expect(browser.isHeaded).to.be.true;
|
||||
default:
|
||||
return expect(browser.isHeadless, "browser.isHeadless").not.to.be.undefined;
|
||||
}
|
||||
});
|
||||
|
||||
it ".spec", ->
|
||||
{ spec } = Cypress
|
||||
it(".spec", function() {
|
||||
const { spec } = Cypress;
|
||||
|
||||
expect(spec).to.be.an("object")
|
||||
expect(spec.name).to.eq("config_passing_spec.coffee")
|
||||
expect(spec.relative).to.eq("cypress/integration/config_passing_spec.coffee")
|
||||
expect(spec.absolute.indexOf("cypress/integration/config_passing_spec.coffee")).to.be.gt(0)
|
||||
expect(spec).to.be.an("object");
|
||||
expect(spec.name).to.eq("config_passing_spec.coffee");
|
||||
expect(spec.relative).to.eq("cypress/integration/config_passing_spec.coffee");
|
||||
return expect(spec.absolute.indexOf("cypress/integration/config_passing_spec.coffee")).to.be.gt(0);
|
||||
});
|
||||
|
||||
context ".env", ->
|
||||
## https://github.com/cypress-io/cypress/issues/4952
|
||||
it "doesn't die on <script> tags", ->
|
||||
expect(Cypress.env('scriptlet')).to.eq("<script>alert('this should not break')</script>")
|
||||
return context(".env", () => //# https://github.com/cypress-io/cypress/issues/4952
|
||||
it(
|
||||
"doesn't die on <script> tags",
|
||||
() => expect(Cypress.env('scriptlet')).to.eq("<script>alert('this should not break')</script>")
|
||||
));
|
||||
});
|
||||
|
||||
+256
-250
@@ -1,325 +1,331 @@
|
||||
{ _ } = Cypress
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const { _ } = Cypress;
|
||||
|
||||
expectedDomain = Cypress.env('expectedDomain')
|
||||
httpUrl = Cypress.env('httpUrl')
|
||||
httpsUrl = Cypress.env('httpsUrl')
|
||||
otherUrl = Cypress.env('otherUrl')
|
||||
otherHttpsUrl = Cypress.env('otherHttpsUrl')
|
||||
const expectedDomain = Cypress.env('expectedDomain');
|
||||
const httpUrl = Cypress.env('httpUrl');
|
||||
const httpsUrl = Cypress.env('httpsUrl');
|
||||
const otherUrl = Cypress.env('otherUrl');
|
||||
const otherHttpsUrl = Cypress.env('otherHttpsUrl');
|
||||
|
||||
baseUrlLocation = new Cypress.Location(Cypress.config('baseUrl'))
|
||||
const baseUrlLocation = new Cypress.Location(Cypress.config('baseUrl'));
|
||||
|
||||
## setcookie sets on the superdomain by default
|
||||
setCookieDomain = ".#{baseUrlLocation.getSuperDomain()}"
|
||||
//# setcookie sets on the superdomain by default
|
||||
let setCookieDomain = `.${baseUrlLocation.getSuperDomain()}`;
|
||||
|
||||
if ['localhost', '127.0.0.1'].includes(expectedDomain)
|
||||
setCookieDomain = expectedDomain
|
||||
if (['localhost', '127.0.0.1'].includes(expectedDomain)) {
|
||||
setCookieDomain = expectedDomain;
|
||||
}
|
||||
|
||||
## chrome defaults to "unspecified"
|
||||
defaultSameSite = undefined
|
||||
//# chrome defaults to "unspecified"
|
||||
let defaultSameSite = undefined;
|
||||
|
||||
if Cypress.isBrowser('firefox')
|
||||
## firefox will default to "no_restriction"
|
||||
## @see https://bugzilla.mozilla.org/show_bug.cgi?id=1624668
|
||||
defaultSameSite = 'no_restriction'
|
||||
if (Cypress.isBrowser('firefox')) {
|
||||
//# firefox will default to "no_restriction"
|
||||
//# @see https://bugzilla.mozilla.org/show_bug.cgi?id=1624668
|
||||
defaultSameSite = 'no_restriction';
|
||||
}
|
||||
|
||||
describe "cookies", ->
|
||||
before ->
|
||||
if Cypress.env('noBaseUrl')
|
||||
return
|
||||
describe("cookies", function() {
|
||||
before(function() {
|
||||
if (Cypress.env('noBaseUrl')) {
|
||||
return;
|
||||
}
|
||||
|
||||
## assert we're running on expected baseurl
|
||||
expect(Cypress.env('baseUrl')).to.be.a('string')
|
||||
//# assert we're running on expected baseurl
|
||||
return expect(Cypress.env('baseUrl')).to.be.a('string')
|
||||
.and.have.length.gt(0)
|
||||
.and.eq(Cypress.config('baseUrl'))
|
||||
.and.eq(Cypress.config('baseUrl'));
|
||||
});
|
||||
|
||||
beforeEach ->
|
||||
cy.wrap({foo: "bar"})
|
||||
beforeEach(() => cy.wrap({foo: "bar"}));
|
||||
|
||||
context "with preserve", ->
|
||||
before ->
|
||||
Cypress.Cookies.defaults({
|
||||
preserve: "foo1"
|
||||
})
|
||||
context("with preserve", function() {
|
||||
before(() => Cypress.Cookies.defaults({
|
||||
preserve: "foo1"
|
||||
}));
|
||||
|
||||
it "can get all cookies", ->
|
||||
expectedCookieKeys = ["domain", "name", "value", "path", "secure", "httpOnly", "expiry"]
|
||||
it("can get all cookies", function() {
|
||||
const expectedCookieKeys = ["domain", "name", "value", "path", "secure", "httpOnly", "expiry"];
|
||||
|
||||
if defaultSameSite
|
||||
## samesite will only be present if it is defined
|
||||
expectedCookieKeys.push('sameSite')
|
||||
if (defaultSameSite) {
|
||||
//# samesite will only be present if it is defined
|
||||
expectedCookieKeys.push('sameSite');
|
||||
}
|
||||
|
||||
assertFirstCookie = (c) ->
|
||||
expect(c.domain).to.eq(setCookieDomain)
|
||||
expect(c.httpOnly).to.eq(false)
|
||||
expect(c.name).to.eq("foo")
|
||||
expect(c.value).to.eq("bar")
|
||||
expect(c.path).to.eq("/")
|
||||
expect(c.secure).to.eq(false)
|
||||
expect(c.expiry).to.be.a("number")
|
||||
expect(c.sameSite).to.eq(defaultSameSite)
|
||||
const assertFirstCookie = function(c) {
|
||||
expect(c.domain).to.eq(setCookieDomain);
|
||||
expect(c.httpOnly).to.eq(false);
|
||||
expect(c.name).to.eq("foo");
|
||||
expect(c.value).to.eq("bar");
|
||||
expect(c.path).to.eq("/");
|
||||
expect(c.secure).to.eq(false);
|
||||
expect(c.expiry).to.be.a("number");
|
||||
expect(c.sameSite).to.eq(defaultSameSite);
|
||||
|
||||
expect(c).to.have.keys(expectedCookieKeys)
|
||||
return expect(c).to.have.keys(expectedCookieKeys);
|
||||
};
|
||||
|
||||
cy
|
||||
return cy
|
||||
.clearCookie("foo1")
|
||||
.setCookie("foo", "bar").then assertFirstCookie
|
||||
.setCookie("foo", "bar").then(assertFirstCookie)
|
||||
.getCookies()
|
||||
.should("have.length", 1)
|
||||
.its(0)
|
||||
.then assertFirstCookie
|
||||
.then(assertFirstCookie)
|
||||
.clearCookies()
|
||||
.should("be.null")
|
||||
.setCookie("wtf", "bob", {httpOnly: true, path: "/foo", secure: true})
|
||||
.getCookie("wtf").then (c) ->
|
||||
expect(c.domain).to.eq(setCookieDomain)
|
||||
expect(c.httpOnly).to.eq(true)
|
||||
expect(c.name).to.eq("wtf")
|
||||
expect(c.value).to.eq("bob")
|
||||
expect(c.path).to.eq("/foo")
|
||||
expect(c.secure).to.eq(true)
|
||||
expect(c.expiry).to.be.a("number")
|
||||
expect(c.sameSite).to.eq(defaultSameSite)
|
||||
.getCookie("wtf").then(function(c) {
|
||||
expect(c.domain).to.eq(setCookieDomain);
|
||||
expect(c.httpOnly).to.eq(true);
|
||||
expect(c.name).to.eq("wtf");
|
||||
expect(c.value).to.eq("bob");
|
||||
expect(c.path).to.eq("/foo");
|
||||
expect(c.secure).to.eq(true);
|
||||
expect(c.expiry).to.be.a("number");
|
||||
expect(c.sameSite).to.eq(defaultSameSite);
|
||||
|
||||
expect(c).to.have.keys(expectedCookieKeys)
|
||||
.clearCookie("wtf")
|
||||
return expect(c).to.have.keys(expectedCookieKeys);}).clearCookie("wtf")
|
||||
.should("be.null")
|
||||
.getCookie("doesNotExist")
|
||||
.should("be.null")
|
||||
.document()
|
||||
.its("cookie")
|
||||
.should("be.empty")
|
||||
.should("be.empty");
|
||||
});
|
||||
|
||||
it "resets cookies between tests correctly", ->
|
||||
Cypress.Cookies.preserveOnce("foo2")
|
||||
it("resets cookies between tests correctly", function() {
|
||||
Cypress.Cookies.preserveOnce("foo2");
|
||||
|
||||
for i in [1..100]
|
||||
do (i) ->
|
||||
cy.setCookie("foo" + i, "#{i}")
|
||||
for (let i = 1; i <= 100; i++) {
|
||||
((i => cy.setCookie("foo" + i, `${i}`)))(i);
|
||||
}
|
||||
|
||||
cy.getCookies().should("have.length", 100)
|
||||
return cy.getCookies().should("have.length", 100);
|
||||
});
|
||||
|
||||
it "should be only two left now", ->
|
||||
cy.getCookies().should("have.length", 2)
|
||||
it("should be only two left now", () => cy.getCookies().should("have.length", 2));
|
||||
|
||||
it "handles undefined cookies", ->
|
||||
cy.visit("/cookieWithNoName")
|
||||
return it("handles undefined cookies", () => cy.visit("/cookieWithNoName"));
|
||||
});
|
||||
|
||||
context "without preserve", ->
|
||||
before ->
|
||||
Cypress.Cookies.defaults({
|
||||
preserve: []
|
||||
})
|
||||
return context("without preserve", function() {
|
||||
before(() => Cypress.Cookies.defaults({
|
||||
preserve: []
|
||||
}));
|
||||
|
||||
it "sends set cookies to path", ->
|
||||
cy
|
||||
.clearCookies()
|
||||
.setCookie("asdf", "jkl")
|
||||
.request("/requestCookies")
|
||||
.its("body").should("deep.eq", { asdf: "jkl" })
|
||||
it("sends set cookies to path", () => cy
|
||||
.clearCookies()
|
||||
.setCookie("asdf", "jkl")
|
||||
.request("/requestCookies")
|
||||
.its("body").should("deep.eq", { asdf: "jkl" }));
|
||||
|
||||
it "handles expired cookies secure", ->
|
||||
cy
|
||||
.visit("/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("/expirationMaxAge")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
.visit("/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("/expirationExpires")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
it("handles expired cookies secure", () => cy
|
||||
.visit("/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("/expirationMaxAge")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
.visit("/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("/expirationExpires")
|
||||
.getCookie("shouldExpire").should("not.exist"));
|
||||
|
||||
it "issue: #224 sets expired cookies between redirects", ->
|
||||
cy
|
||||
.visit("/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("/expirationRedirect")
|
||||
.url().should("include", "/logout")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
it("issue: #224 sets expired cookies between redirects", () => cy
|
||||
.visit("/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("/expirationRedirect")
|
||||
.url().should("include", "/logout")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
|
||||
.visit("/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.request("/expirationRedirect")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
.visit("/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.request("/expirationRedirect")
|
||||
.getCookie("shouldExpire").should("not.exist"));
|
||||
|
||||
it "issue: #1321 failing to set or parse cookie", ->
|
||||
## this is happening because the original cookie was set
|
||||
## with a secure flag, and then expired without the secure
|
||||
## flag.
|
||||
cy
|
||||
.visit("#{httpsUrl}/setOneHourFromNowAndSecure")
|
||||
.getCookies().should("have.length", 1)
|
||||
it("issue: #1321 failing to set or parse cookie", () => //# this is happening because the original cookie was set
|
||||
//# with a secure flag, and then expired without the secure
|
||||
//# flag.
|
||||
cy
|
||||
.visit(`${httpsUrl}/setOneHourFromNowAndSecure`)
|
||||
.getCookies().should("have.length", 1)
|
||||
|
||||
## secure cookies should have been attached
|
||||
.request("#{httpsUrl}/requestCookies")
|
||||
.its("body").should("deep.eq", { shouldExpire: "oneHour" })
|
||||
//# secure cookies should have been attached
|
||||
.request(`${httpsUrl}/requestCookies`)
|
||||
.its("body").should("deep.eq", { shouldExpire: "oneHour" })
|
||||
|
||||
## secure cookies should not have been attached
|
||||
.request("#{httpUrl}/requestCookies")
|
||||
.its("body").should("deep.eq", {})
|
||||
//# secure cookies should not have been attached
|
||||
.request(`${httpUrl}/requestCookies`)
|
||||
.its("body").should("deep.eq", {})
|
||||
|
||||
.visit("#{httpsUrl}/expirationMaxAge")
|
||||
.getCookies().should("be.empty")
|
||||
.visit(`${httpsUrl}/expirationMaxAge`)
|
||||
.getCookies().should("be.empty"));
|
||||
|
||||
it "issue: #2724 does not fail on invalid cookies", ->
|
||||
cy.request("#{httpsUrl}/invalidCookies")
|
||||
it("issue: #2724 does not fail on invalid cookies", () => cy.request(`${httpsUrl}/invalidCookies`));
|
||||
|
||||
## https://github.com/cypress-io/cypress/issues/5453
|
||||
it "can set and clear cookie", ->
|
||||
cy.setCookie('foo', 'bar')
|
||||
cy.clearCookie('foo')
|
||||
cy.getCookie('foo').should('be.null')
|
||||
//# https://github.com/cypress-io/cypress/issues/5453
|
||||
it("can set and clear cookie", function() {
|
||||
cy.setCookie('foo', 'bar');
|
||||
cy.clearCookie('foo');
|
||||
return cy.getCookie('foo').should('be.null');
|
||||
});
|
||||
|
||||
[
|
||||
return [
|
||||
'visit',
|
||||
'request'
|
||||
].forEach (cmd) ->
|
||||
context "in a cy.#{cmd}", ->
|
||||
## https://github.com/cypress-io/cypress/issues/5894
|
||||
it "can successfully send cookies as a Cookie header", ->
|
||||
cy[cmd]({
|
||||
url: "/requestCookies#{if cmd is 'visit' then 'Html' else ''}"
|
||||
headers: {
|
||||
Cookie: 'a=b;b=c;c=s%3APtCc3lNiuqN0AtR9ffgKUnUsDzR5n_4B.qzFDJDvqx8PZNvmOkmcexDs7fRJLOel56Z8Ii6PL%2BFo'
|
||||
}
|
||||
method: if cmd is 'visit' then 'POST' else 'PATCH'
|
||||
})
|
||||
.then (res) ->
|
||||
if cmd is 'visit'
|
||||
return cy.get('body').then (body) ->
|
||||
JSON.parse(body.text())
|
||||
return res.body
|
||||
.then (cookies) ->
|
||||
expect(cookies).to.deep.eq({
|
||||
a: 'b'
|
||||
b: 'c'
|
||||
c: 's:PtCc3lNiuqN0AtR9ffgKUnUsDzR5n_4B.qzFDJDvqx8PZNvmOkmcexDs7fRJLOel56Z8Ii6PL+Fo'
|
||||
})
|
||||
].forEach(cmd => context(`in a cy.${cmd}`, function() {
|
||||
//# https://github.com/cypress-io/cypress/issues/5894
|
||||
it("can successfully send cookies as a Cookie header", () => cy[cmd]({
|
||||
url: `/requestCookies${cmd === 'visit' ? 'Html' : ''}`,
|
||||
headers: {
|
||||
Cookie: 'a=b;b=c;c=s%3APtCc3lNiuqN0AtR9ffgKUnUsDzR5n_4B.qzFDJDvqx8PZNvmOkmcexDs7fRJLOel56Z8Ii6PL%2BFo'
|
||||
},
|
||||
method: cmd === 'visit' ? 'POST' : 'PATCH'
|
||||
})
|
||||
.then(function(res) {
|
||||
if (cmd === 'visit') {
|
||||
return cy.get('body').then(body => JSON.parse(body.text()));
|
||||
}
|
||||
return res.body;}).then(cookies => expect(cookies).to.deep.eq({
|
||||
a: 'b',
|
||||
b: 'c',
|
||||
c: 's:PtCc3lNiuqN0AtR9ffgKUnUsDzR5n_4B.qzFDJDvqx8PZNvmOkmcexDs7fRJLOel56Z8Ii6PL+Fo'
|
||||
})));
|
||||
|
||||
## https://github.com/cypress-io/cypress/issues/6890
|
||||
it "ignores invalid set-cookie headers that contain control chars", ->
|
||||
cy[cmd]("/invalidControlCharCookie")
|
||||
//# https://github.com/cypress-io/cypress/issues/6890
|
||||
it("ignores invalid set-cookie headers that contain control chars", function() {
|
||||
cy[cmd]("/invalidControlCharCookie");
|
||||
|
||||
cy.request("/requestCookies")
|
||||
.then (res) ->
|
||||
return res.body
|
||||
.then (cookies) ->
|
||||
expect(cookies).to.deep.eq({
|
||||
_valid: 'true'
|
||||
})
|
||||
return cy.request("/requestCookies")
|
||||
.then(res => res.body).then(cookies => expect(cookies).to.deep.eq({
|
||||
_valid: 'true'
|
||||
}));
|
||||
});
|
||||
|
||||
context "with Domain = superdomain", ->
|
||||
requestCookiesUrl = "#{Cypress.config('baseUrl')}/requestCookies"
|
||||
setDomainCookieUrl = "#{Cypress.config('baseUrl')}/setDomainCookie?domain=#{setCookieDomain}"
|
||||
context("with Domain = superdomain", function() {
|
||||
const requestCookiesUrl = `${Cypress.config('baseUrl')}/requestCookies`;
|
||||
const setDomainCookieUrl = `${Cypress.config('baseUrl')}/setDomainCookie?domain=${setCookieDomain}`;
|
||||
|
||||
it "is set properly with no redirects", ->
|
||||
cy[cmd](setDomainCookieUrl)
|
||||
it("is set properly with no redirects", function() {
|
||||
cy[cmd](setDomainCookieUrl);
|
||||
|
||||
cy.getCookies()
|
||||
.then (cookies) ->
|
||||
expect(cookies).to.have.length(1)
|
||||
expect(cookies[0]).to.include({
|
||||
name: 'domaincookie',
|
||||
value: 'foo'
|
||||
})
|
||||
cy.getCookies()
|
||||
.then(function(cookies) {
|
||||
expect(cookies).to.have.length(1);
|
||||
return expect(cookies[0]).to.include({
|
||||
name: 'domaincookie',
|
||||
value: 'foo'
|
||||
});
|
||||
});
|
||||
|
||||
cy.request(requestCookiesUrl).its('body').should('include', { 'domaincookie': 'foo' })
|
||||
cy.request('POST', requestCookiesUrl).its('body').should('include', { 'domaincookie': 'foo' })
|
||||
cy.request(requestCookiesUrl).its('body').should('include', { 'domaincookie': 'foo' });
|
||||
return cy.request('POST', requestCookiesUrl).its('body').should('include', { 'domaincookie': 'foo' });
|
||||
});
|
||||
|
||||
it "is set properly with redirects", ->
|
||||
cy[cmd]("#{setDomainCookieUrl}&redirect=/requestCookiesHtml")
|
||||
return it("is set properly with redirects", function() {
|
||||
cy[cmd](`${setDomainCookieUrl}&redirect=/requestCookiesHtml`);
|
||||
|
||||
cy.getCookies()
|
||||
.then (cookies) ->
|
||||
expect(cookies).to.have.length(1)
|
||||
expect(cookies[0]).to.include({
|
||||
name: 'domaincookie',
|
||||
value: 'foo'
|
||||
})
|
||||
cy.getCookies()
|
||||
.then(function(cookies) {
|
||||
expect(cookies).to.have.length(1);
|
||||
return expect(cookies[0]).to.include({
|
||||
name: 'domaincookie',
|
||||
value: 'foo'
|
||||
});
|
||||
});
|
||||
|
||||
if cmd == 'visit'
|
||||
cy.url().should('include', requestCookiesUrl)
|
||||
cy.contains('domaincookie')
|
||||
if (cmd === 'visit') {
|
||||
cy.url().should('include', requestCookiesUrl);
|
||||
cy.contains('domaincookie');
|
||||
}
|
||||
|
||||
cy.request(requestCookiesUrl).its('body').should('include', { 'domaincookie': 'foo' })
|
||||
cy.request('POST', requestCookiesUrl).its('body').should('include', { 'domaincookie': 'foo' })
|
||||
cy.request(requestCookiesUrl).its('body').should('include', { 'domaincookie': 'foo' });
|
||||
return cy.request('POST', requestCookiesUrl).its('body').should('include', { 'domaincookie': 'foo' });
|
||||
});
|
||||
});
|
||||
|
||||
context "with SameSite", ->
|
||||
[
|
||||
{ header: 'None', sameSite: 'no_restriction' }
|
||||
{ header: 'Strict', sameSite: 'strict' }
|
||||
{ header: 'Lax', sameSite: 'lax' }
|
||||
].forEach ({ header, sameSite }) ->
|
||||
it "#{header} is set and sent with subsequent requests", ->
|
||||
name = "ss#{header}"
|
||||
cy.getCookie(name).should('be.null')
|
||||
context("with SameSite", () => [
|
||||
{ header: 'None', sameSite: 'no_restriction' },
|
||||
{ header: 'Strict', sameSite: 'strict' },
|
||||
{ header: 'Lax', sameSite: 'lax' }
|
||||
].forEach(({ header, sameSite }) => it(`${header} is set and sent with subsequent requests`, function() {
|
||||
const name = `ss${header}`;
|
||||
cy.getCookie(name).should('be.null');
|
||||
|
||||
sameSiteUrl = "/samesite/#{header}"
|
||||
cookieDumpUrl = "/requestCookies"
|
||||
let sameSiteUrl = `/samesite/${header}`;
|
||||
let cookieDumpUrl = "/requestCookies";
|
||||
|
||||
if header is "None"
|
||||
## None should only be sent + set with HTTPS requests
|
||||
cookieDumpUrl = [httpsUrl, cookieDumpUrl].join('')
|
||||
sameSiteUrl = [httpsUrl, sameSiteUrl].join('')
|
||||
if (header === "None") {
|
||||
//# None should only be sent + set with HTTPS requests
|
||||
cookieDumpUrl = [httpsUrl, cookieDumpUrl].join('');
|
||||
sameSiteUrl = [httpsUrl, sameSiteUrl].join('');
|
||||
}
|
||||
|
||||
cy[cmd](sameSiteUrl)
|
||||
cy[cmd](sameSiteUrl);
|
||||
|
||||
cy.getCookie(name).should('include', {
|
||||
name,
|
||||
value: 'someval',
|
||||
sameSite
|
||||
})
|
||||
cy.getCookie(name).should('include', {
|
||||
name,
|
||||
value: 'someval',
|
||||
sameSite
|
||||
});
|
||||
|
||||
cy.visit("#{cookieDumpUrl}Html")
|
||||
.then (res) ->
|
||||
cy.get('body').then (body) ->
|
||||
JSON.parse(body.text())
|
||||
.then (body) ->
|
||||
expect(body).to.have.property(name).and.eq('someval')
|
||||
cy.visit(`${cookieDumpUrl}Html`)
|
||||
.then(res => cy.get('body').then(body => JSON.parse(body.text()))).then(body => expect(body).to.have.property(name).and.eq('someval'));
|
||||
|
||||
cy.request(cookieDumpUrl)
|
||||
.then ({ body }) ->
|
||||
expect(body).to.have.property(name).and.eq('someval')
|
||||
return cy.request(cookieDumpUrl)
|
||||
.then(({ body }) => expect(body).to.have.property(name).and.eq('someval'));
|
||||
})));
|
||||
|
||||
[
|
||||
['HTTP', otherUrl]
|
||||
['HTTPS', otherHttpsUrl],
|
||||
].forEach ([protocol, altUrl]) =>
|
||||
context "when redirected to a #{protocol} URL", ->
|
||||
[
|
||||
['different domain', 7]
|
||||
['same domain', 8]
|
||||
].forEach ([title, n]) ->
|
||||
it "can set cookies on lots of redirects, ending with #{title}", ->
|
||||
altDomain = (new Cypress.Location(altUrl)).getHostName()
|
||||
return [
|
||||
['HTTP', otherUrl],
|
||||
['HTTPS', otherHttpsUrl],
|
||||
].forEach(([protocol, altUrl]) => {
|
||||
return context(`when redirected to a ${protocol} URL`, () => [
|
||||
['different domain', 7],
|
||||
['same domain', 8]
|
||||
].forEach(([title, n]) => it(`can set cookies on lots of redirects, ending with ${title}`, function() {
|
||||
const altDomain = (new Cypress.Location(altUrl)).getHostName();
|
||||
|
||||
expectedGetCookiesArray = []
|
||||
let expectedGetCookiesArray = [];
|
||||
|
||||
_.times n + 1, (i) =>
|
||||
['foo', 'bar'].forEach (tag) ->
|
||||
expectedCookie = {
|
||||
"name": "name#{tag}#{i}",
|
||||
"value": "val#{tag}#{i}",
|
||||
"path": "/",
|
||||
"domain": if i % 2 == 8 - n then expectedDomain else altDomain,
|
||||
"secure": false,
|
||||
"httpOnly": false,
|
||||
}
|
||||
_.times(n + 1, i => {
|
||||
return ['foo', 'bar'].forEach(function(tag) {
|
||||
const expectedCookie = {
|
||||
"name": `name${tag}${i}`,
|
||||
"value": `val${tag}${i}`,
|
||||
"path": "/",
|
||||
"domain": (i % 2) === (8 - n) ? expectedDomain : altDomain,
|
||||
"secure": false,
|
||||
"httpOnly": false,
|
||||
};
|
||||
|
||||
if defaultSameSite
|
||||
expectedCookie.sameSite = defaultSameSite
|
||||
if (defaultSameSite) {
|
||||
expectedCookie.sameSite = defaultSameSite;
|
||||
}
|
||||
|
||||
expectedGetCookiesArray.push(expectedCookie)
|
||||
return expectedGetCookiesArray.push(expectedCookie);
|
||||
});
|
||||
});
|
||||
|
||||
expectedGetCookiesArray = _.reverse(_.sortBy(expectedGetCookiesArray, _.property('name')))
|
||||
expectedGetCookiesArray = _.reverse(_.sortBy(expectedGetCookiesArray, _.property('name')));
|
||||
|
||||
# sanity check
|
||||
cy.clearCookies({ domain: null })
|
||||
cy.getCookies({ domain: null }).should('have.length', 0)
|
||||
// sanity check
|
||||
cy.clearCookies({ domain: null });
|
||||
cy.getCookies({ domain: null }).should('have.length', 0);
|
||||
|
||||
cy[cmd]("/setCascadingCookies?n=#{n}&a=#{altUrl}&b=#{Cypress.env('baseUrl')}")
|
||||
cy[cmd](`/setCascadingCookies?n=${n}&a=${altUrl}&b=${Cypress.env('baseUrl')}`);
|
||||
|
||||
cy.getCookies({ domain: null }).then (cookies) ->
|
||||
## reverse them so they'll be in the order they were set
|
||||
cookies = _.reverse(_.sortBy(cookies, _.property('name')))
|
||||
return cy.getCookies({ domain: null }).then(function(cookies) {
|
||||
//# reverse them so they'll be in the order they were set
|
||||
cookies = _.reverse(_.sortBy(cookies, _.property('name')));
|
||||
|
||||
expect(cookies).to.deep.eq(expectedGetCookiesArray)
|
||||
return expect(cookies).to.deep.eq(expectedGetCookiesArray);
|
||||
});
|
||||
})));
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
+104
-106
@@ -1,139 +1,137 @@
|
||||
httpUrl = Cypress.env('httpUrl')
|
||||
httpsUrl = Cypress.env('httpsUrl')
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const httpUrl = Cypress.env('httpUrl');
|
||||
const httpsUrl = Cypress.env('httpsUrl');
|
||||
|
||||
describe "cookies", ->
|
||||
beforeEach ->
|
||||
cy.wrap({foo: "bar"})
|
||||
describe("cookies", function() {
|
||||
beforeEach(() => cy.wrap({foo: "bar"}));
|
||||
|
||||
context "with preserve", ->
|
||||
before ->
|
||||
Cypress.Cookies.defaults({
|
||||
preserve: "foo1"
|
||||
})
|
||||
context("with preserve", function() {
|
||||
before(() => Cypress.Cookies.defaults({
|
||||
preserve: "foo1"
|
||||
}));
|
||||
|
||||
it "can get all cookies", ->
|
||||
expectedKeys = ["domain", "name", "value", "path", "secure", "httpOnly", "expiry"]
|
||||
it("can get all cookies", function() {
|
||||
const expectedKeys = ["domain", "name", "value", "path", "secure", "httpOnly", "expiry"];
|
||||
|
||||
if Cypress.isBrowser('firefox')
|
||||
expectedKeys.push('sameSite')
|
||||
if (Cypress.isBrowser('firefox')) {
|
||||
expectedKeys.push('sameSite');
|
||||
}
|
||||
|
||||
cy
|
||||
return cy
|
||||
.clearCookie("foo1")
|
||||
.setCookie("foo", "bar").then (c) ->
|
||||
expect(c.domain).to.eq("localhost")
|
||||
expect(c.httpOnly).to.eq(false)
|
||||
expect(c.name).to.eq("foo")
|
||||
expect(c.value).to.eq("bar")
|
||||
expect(c.path).to.eq("/")
|
||||
expect(c.secure).to.eq(false)
|
||||
expect(c.expiry).to.be.a("number")
|
||||
.setCookie("foo", "bar").then(function(c) {
|
||||
expect(c.domain).to.eq("localhost");
|
||||
expect(c.httpOnly).to.eq(false);
|
||||
expect(c.name).to.eq("foo");
|
||||
expect(c.value).to.eq("bar");
|
||||
expect(c.path).to.eq("/");
|
||||
expect(c.secure).to.eq(false);
|
||||
expect(c.expiry).to.be.a("number");
|
||||
|
||||
expect(c).to.have.keys(expectedKeys)
|
||||
.getCookies()
|
||||
return expect(c).to.have.keys(expectedKeys);}).getCookies()
|
||||
.should("have.length", 1)
|
||||
.then (cookies) ->
|
||||
c = cookies[0]
|
||||
.then(function(cookies) {
|
||||
const c = cookies[0];
|
||||
|
||||
expect(c.domain).to.eq("localhost")
|
||||
expect(c.httpOnly).to.eq(false)
|
||||
expect(c.name).to.eq("foo")
|
||||
expect(c.value).to.eq("bar")
|
||||
expect(c.path).to.eq("/")
|
||||
expect(c.secure).to.eq(false)
|
||||
expect(c.expiry).to.be.a("number")
|
||||
expect(c.domain).to.eq("localhost");
|
||||
expect(c.httpOnly).to.eq(false);
|
||||
expect(c.name).to.eq("foo");
|
||||
expect(c.value).to.eq("bar");
|
||||
expect(c.path).to.eq("/");
|
||||
expect(c.secure).to.eq(false);
|
||||
expect(c.expiry).to.be.a("number");
|
||||
|
||||
expect(c).to.have.keys(expectedKeys)
|
||||
.clearCookies()
|
||||
return expect(c).to.have.keys(expectedKeys);}).clearCookies()
|
||||
.should("be.null")
|
||||
.setCookie("wtf", "bob", {httpOnly: true, path: "/foo", secure: true})
|
||||
.getCookie("wtf").then (c) ->
|
||||
expect(c.domain).to.eq("localhost")
|
||||
expect(c.httpOnly).to.eq(true)
|
||||
expect(c.name).to.eq("wtf")
|
||||
expect(c.value).to.eq("bob")
|
||||
expect(c.path).to.eq("/foo")
|
||||
expect(c.secure).to.eq(true)
|
||||
expect(c.expiry).to.be.a("number")
|
||||
.getCookie("wtf").then(function(c) {
|
||||
expect(c.domain).to.eq("localhost");
|
||||
expect(c.httpOnly).to.eq(true);
|
||||
expect(c.name).to.eq("wtf");
|
||||
expect(c.value).to.eq("bob");
|
||||
expect(c.path).to.eq("/foo");
|
||||
expect(c.secure).to.eq(true);
|
||||
expect(c.expiry).to.be.a("number");
|
||||
|
||||
expect(c).to.have.keys(expectedKeys)
|
||||
.clearCookie("wtf")
|
||||
return expect(c).to.have.keys(expectedKeys);}).clearCookie("wtf")
|
||||
.should("be.null")
|
||||
.getCookie("doesNotExist")
|
||||
.should("be.null")
|
||||
.document()
|
||||
.its("cookie")
|
||||
.should("be.empty")
|
||||
.should("be.empty");
|
||||
});
|
||||
|
||||
it "resets cookies between tests correctly", ->
|
||||
Cypress.Cookies.preserveOnce("foo2")
|
||||
it("resets cookies between tests correctly", function() {
|
||||
Cypress.Cookies.preserveOnce("foo2");
|
||||
|
||||
for i in [1..100]
|
||||
do (i) ->
|
||||
cy.setCookie("foo" + i, "#{i}")
|
||||
for (let i = 1; i <= 100; i++) {
|
||||
((i => cy.setCookie("foo" + i, `${i}`)))(i);
|
||||
}
|
||||
|
||||
cy.getCookies().should("have.length", 100)
|
||||
return cy.getCookies().should("have.length", 100);
|
||||
});
|
||||
|
||||
it "should be only two left now", ->
|
||||
cy.getCookies().should("have.length", 2)
|
||||
it("should be only two left now", () => cy.getCookies().should("have.length", 2));
|
||||
|
||||
it "handles undefined cookies", ->
|
||||
cy.visit("#{httpUrl}/cookieWithNoName")
|
||||
return it("handles undefined cookies", () => cy.visit(`${httpUrl}/cookieWithNoName`));
|
||||
});
|
||||
|
||||
context "without preserve", ->
|
||||
before ->
|
||||
Cypress.Cookies.defaults({
|
||||
preserve: []
|
||||
})
|
||||
return context("without preserve", function() {
|
||||
before(() => Cypress.Cookies.defaults({
|
||||
preserve: []
|
||||
}));
|
||||
|
||||
it "sends cookies to localhost:2121", ->
|
||||
cy
|
||||
.clearCookies()
|
||||
.setCookie("asdf", "jkl")
|
||||
.request("#{httpUrl}/requestCookies")
|
||||
.its("body").should("deep.eq", { asdf: "jkl" })
|
||||
it("sends cookies to localhost:2121", () => cy
|
||||
.clearCookies()
|
||||
.setCookie("asdf", "jkl")
|
||||
.request(`${httpUrl}/requestCookies`)
|
||||
.its("body").should("deep.eq", { asdf: "jkl" }));
|
||||
|
||||
it "handles expired cookies secure", ->
|
||||
cy
|
||||
.visit("#{httpUrl}/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("#{httpUrl}/expirationMaxAge")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
.visit("#{httpUrl}/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("#{httpUrl}/expirationExpires")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
it("handles expired cookies secure", () => cy
|
||||
.visit(`${httpUrl}/set`)
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit(`${httpUrl}/expirationMaxAge`)
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
.visit(`${httpUrl}/set`)
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit(`${httpUrl}/expirationExpires`)
|
||||
.getCookie("shouldExpire").should("not.exist"));
|
||||
|
||||
it "issue: #224 sets expired cookies between redirects", ->
|
||||
cy
|
||||
.visit("#{httpUrl}/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit("#{httpUrl}/expirationRedirect")
|
||||
.url().should("include", "/logout")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
it("issue: #224 sets expired cookies between redirects", () => cy
|
||||
.visit(`${httpUrl}/set`)
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.visit(`${httpUrl}/expirationRedirect`)
|
||||
.url().should("include", "/logout")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
|
||||
.visit("#{httpUrl}/set")
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.request("#{httpUrl}/expirationRedirect")
|
||||
.getCookie("shouldExpire").should("not.exist")
|
||||
.visit(`${httpUrl}/set`)
|
||||
.getCookie("shouldExpire").should("exist")
|
||||
.request(`${httpUrl}/expirationRedirect`)
|
||||
.getCookie("shouldExpire").should("not.exist"));
|
||||
|
||||
it "issue: #1321 failing to set or parse cookie", ->
|
||||
## this is happening because the original cookie was set
|
||||
## with a secure flag, and then expired without the secure
|
||||
## flag.
|
||||
cy
|
||||
.visit("#{httpsUrl}/setOneHourFromNowAndSecure")
|
||||
.getCookies().should("have.length", 1)
|
||||
it("issue: #1321 failing to set or parse cookie", () => //# this is happening because the original cookie was set
|
||||
//# with a secure flag, and then expired without the secure
|
||||
//# flag.
|
||||
cy
|
||||
.visit(`${httpsUrl}/setOneHourFromNowAndSecure`)
|
||||
.getCookies().should("have.length", 1)
|
||||
|
||||
## secure cookies should have been attached
|
||||
.request("#{httpsUrl}/requestCookies")
|
||||
.its("body").should("deep.eq", { shouldExpire: "oneHour" })
|
||||
//# secure cookies should have been attached
|
||||
.request(`${httpsUrl}/requestCookies`)
|
||||
.its("body").should("deep.eq", { shouldExpire: "oneHour" })
|
||||
|
||||
## secure cookies should not have been attached
|
||||
.request("#{httpUrl}/requestCookies")
|
||||
.its("body").should("deep.eq", {})
|
||||
//# secure cookies should not have been attached
|
||||
.request(`${httpUrl}/requestCookies`)
|
||||
.its("body").should("deep.eq", {})
|
||||
|
||||
.visit("#{httpsUrl}/expirationMaxAge")
|
||||
.getCookies().should("be.empty")
|
||||
.visit(`${httpsUrl}/expirationMaxAge`)
|
||||
.getCookies().should("be.empty"));
|
||||
|
||||
it "issue: #2724 does not fail on invalid cookies", ->
|
||||
cy.request("#{httpsUrl}/invalidCookies")
|
||||
return it("issue: #2724 does not fail on invalid cookies", () => cy.request(`${httpsUrl}/invalidCookies`));
|
||||
});
|
||||
});
|
||||
|
||||
+11
-10
@@ -1,12 +1,13 @@
|
||||
describe "localhost", ->
|
||||
it "can visit", ->
|
||||
cy.visit("http://app.localhost:4848")
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("localhost", () => it("can visit", () => cy.visit("http://app.localhost:4848")));
|
||||
|
||||
describe "com.au", ->
|
||||
it "can visit", ->
|
||||
cy.visit("http://foo.bar.baz.com.au:4848")
|
||||
describe("com.au", () => it("can visit", () => cy.visit("http://foo.bar.baz.com.au:4848")));
|
||||
|
||||
describe "herokuapp.com", ->
|
||||
it "can visit", ->
|
||||
cy.visit("https://cypress-example.herokuapp.com")
|
||||
cy.contains("Getting Started with Node on Heroku")
|
||||
describe("herokuapp.com", () => it("can visit", function() {
|
||||
cy.visit("https://cypress-example.herokuapp.com");
|
||||
return cy.contains("Getting Started with Node on Heroku");
|
||||
}));
|
||||
|
||||
+11
-10
@@ -1,12 +1,13 @@
|
||||
describe "localhost", ->
|
||||
it "can visit", ->
|
||||
cy.visit("http://app.localhost:4848")
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("localhost", () => it("can visit", () => cy.visit("http://app.localhost:4848")));
|
||||
|
||||
describe "com.au", ->
|
||||
it "can visit", ->
|
||||
cy.visit("http://foo.bar.baz.com.au:4848")
|
||||
describe("com.au", () => it("can visit", () => cy.visit("http://foo.bar.baz.com.au:4848")));
|
||||
|
||||
describe "herokuapp.com", ->
|
||||
it "can visit", ->
|
||||
cy.visit("https://cypress-example.herokuapp.com")
|
||||
cy.contains("Getting Started with Node on Heroku")
|
||||
describe("herokuapp.com", () => it("can visit", function() {
|
||||
cy.visit("https://cypress-example.herokuapp.com");
|
||||
return cy.contains("Getting Started with Node on Heroku");
|
||||
}));
|
||||
|
||||
+14
-10
@@ -1,14 +1,18 @@
|
||||
describe "ending early", ->
|
||||
it "does not end early", ->
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("ending early", function() {
|
||||
it("does not end early", function() {});
|
||||
|
||||
it "does end early", (done) ->
|
||||
return it("does end early", function(done) {
|
||||
cy
|
||||
.noop({})
|
||||
.then ->
|
||||
Cypress.Promise.delay(1000)
|
||||
.noop({})
|
||||
.wrap({})
|
||||
.then(() => Cypress.Promise.delay(1000)).noop({})
|
||||
.wrap({});
|
||||
|
||||
setTimeout ->
|
||||
done()
|
||||
, 500
|
||||
return setTimeout(() => done()
|
||||
, 500);
|
||||
});
|
||||
});
|
||||
+6
-2
@@ -1,2 +1,6 @@
|
||||
describe "stdout_specfile_display_spec", ->
|
||||
it "passes", ->
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("stdout_specfile_display_spec", () => it("passes", function() {}));
|
||||
+6
-2
@@ -1,2 +1,6 @@
|
||||
describe "stdout_specfile_display_spec", ->
|
||||
it "passes", ->
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("stdout_specfile_display_spec", () => it("passes", function() {}));
|
||||
+6
-3
@@ -1,3 +1,6 @@
|
||||
describe "stdout_specfile_display_spec", ->
|
||||
it "passes", ->
|
||||
cy.screenshot()
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
describe("stdout_specfile_display_spec", () => it("passes", () => cy.screenshot()));
|
||||
+9
-3
@@ -1,3 +1,9 @@
|
||||
it "nests the file based on spec path", ->
|
||||
cy.screenshot({ capture: "runner" })
|
||||
cy.readFile("cypress/screenshots/nested-1/nested-2/screenshot_nested_file_spec.coffee/nests the file based on spec path.png", 'base64')
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
it("nests the file based on spec path", function() {
|
||||
cy.screenshot({ capture: "runner" });
|
||||
return cy.readFile("cypress/screenshots/nested-1/nested-2/screenshot_nested_file_spec.coffee/nests the file based on spec path.png", 'base64');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user