From dc5e4e5673838c889e7d881961a3e59a84d189c4 Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Wed, 10 Nov 2021 15:01:48 -0800 Subject: [PATCH 1/4] Fix loading of specs with % in the filename --- packages/runner-shared/src/store.ts | 2 +- packages/runner/src/iframe/iframes.jsx | 2 +- packages/server/lib/routes-e2e.ts | 2 +- .../projects/spec-name-special-characters/cypress.json | 1 + .../cypress/integration/fixture%.js | 3 +++ .../spec-name-special-characters/cypress/spec.js | 8 ++++++++ system-tests/test/specs_spec.js | 10 ++++++++++ 7 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 system-tests/projects/spec-name-special-characters/cypress.json create mode 100644 system-tests/projects/spec-name-special-characters/cypress/integration/fixture%.js create mode 100644 system-tests/projects/spec-name-special-characters/cypress/spec.js diff --git a/packages/runner-shared/src/store.ts b/packages/runner-shared/src/store.ts index b56c83b08df..567994a0ad1 100644 --- a/packages/runner-shared/src/store.ts +++ b/packages/runner-shared/src/store.ts @@ -42,7 +42,7 @@ export abstract class BaseStore { } @action updateSpecByUrl (specUrl: string) { - const foundSpec = this.specs.find((x) => x.name === decodeURI(specUrl)) + const foundSpec = this.specs.find((x) => x.name === specUrl) if (foundSpec) { this.spec = foundSpec diff --git a/packages/runner/src/iframe/iframes.jsx b/packages/runner/src/iframe/iframes.jsx index 0ae25a74ea0..72811c47c69 100644 --- a/packages/runner/src/iframe/iframes.jsx +++ b/packages/runner/src/iframe/iframes.jsx @@ -162,7 +162,7 @@ export default class Iframes extends Component { class: 'spec-iframe', }).appendTo($container) - $specIframe.prop('src', specSrc) + $specIframe.prop('src', encodeURI(specSrc)) return $autIframe } diff --git a/packages/server/lib/routes-e2e.ts b/packages/server/lib/routes-e2e.ts index c358131a1c6..757af292f99 100644 --- a/packages/server/lib/routes-e2e.ts +++ b/packages/server/lib/routes-e2e.ts @@ -23,7 +23,7 @@ export const createRoutesE2E = ({ // this could be just a regular .js file or a .coffee file routesE2E.get('/__cypress/tests', (req, res, next) => { // slice out the cache buster - const test = CacheBuster.strip(req.query.p) + const test = decodeURI(CacheBuster.strip(req.query.p)) specController.handle(test, req, res, config, next, onError) }) diff --git a/system-tests/projects/spec-name-special-characters/cypress.json b/system-tests/projects/spec-name-special-characters/cypress.json new file mode 100644 index 00000000000..0967ef424bc --- /dev/null +++ b/system-tests/projects/spec-name-special-characters/cypress.json @@ -0,0 +1 @@ +{} diff --git a/system-tests/projects/spec-name-special-characters/cypress/integration/fixture%.js b/system-tests/projects/spec-name-special-characters/cypress/integration/fixture%.js new file mode 100644 index 00000000000..540eab0077e --- /dev/null +++ b/system-tests/projects/spec-name-special-characters/cypress/integration/fixture%.js @@ -0,0 +1,3 @@ +it('passes', () => { + expect(1).to.equal(1) +}) diff --git a/system-tests/projects/spec-name-special-characters/cypress/spec.js b/system-tests/projects/spec-name-special-characters/cypress/spec.js new file mode 100644 index 00000000000..df600082261 --- /dev/null +++ b/system-tests/projects/spec-name-special-characters/cypress/spec.js @@ -0,0 +1,8 @@ +/// +describe('fixtures in subfolder', () => { + it('works', () => { + cy.fixture('example').should('deep.equal', { + works: true, + }) + }) +}) diff --git a/system-tests/test/specs_spec.js b/system-tests/test/specs_spec.js index 13c0ed0da5a..da4d3405290 100644 --- a/system-tests/test/specs_spec.js +++ b/system-tests/test/specs_spec.js @@ -40,4 +40,14 @@ describe('e2e specs', () => { expectedExitCode: 0, }) }) + + it('handles specs with % in the name', function () { + const project = Fixtures.projectPath('spec-name-special-characters') + + return systemTests.exec(this, { + project, + snapshot: false, + expectedExitCode: 0, + }) + }) }) From 07fed273bcf3f8163c696ca035f94082b6f83867 Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Fri, 12 Nov 2021 09:10:26 -0800 Subject: [PATCH 2/4] Use decodeURIComponent to completely ensure spec names work --- packages/runner/src/iframe/iframes.jsx | 4 ++-- packages/server/lib/routes-e2e.ts | 2 +- .../cypress/integration/{fixture%.js => fixture&%.js} | 0 system-tests/test/specs_spec.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename system-tests/projects/spec-name-special-characters/cypress/integration/{fixture%.js => fixture&%.js} (100%) diff --git a/packages/runner/src/iframe/iframes.jsx b/packages/runner/src/iframe/iframes.jsx index 72811c47c69..afc8449d65a 100644 --- a/packages/runner/src/iframe/iframes.jsx +++ b/packages/runner/src/iframe/iframes.jsx @@ -151,7 +151,7 @@ export default class Iframes extends Component { // jQuery is a better fit for managing these iframes, since they need to get // wiped out and reset on re-runs and the snapshots are from dom we don't control _loadIframes (specPath) { - const specSrc = `/${this.props.config.namespace}/iframes/${specPath}` + const specSrc = `/${this.props.config.namespace}/iframes/${encodeURIComponent(specPath)}` const $container = $(this.refs.container).empty() const $autIframe = this.autIframe.create(this.props.config).appendTo($container) @@ -162,7 +162,7 @@ export default class Iframes extends Component { class: 'spec-iframe', }).appendTo($container) - $specIframe.prop('src', encodeURI(specSrc)) + $specIframe.prop('src', specSrc) return $autIframe } diff --git a/packages/server/lib/routes-e2e.ts b/packages/server/lib/routes-e2e.ts index 757af292f99..67d1f589b09 100644 --- a/packages/server/lib/routes-e2e.ts +++ b/packages/server/lib/routes-e2e.ts @@ -23,7 +23,7 @@ export const createRoutesE2E = ({ // this could be just a regular .js file or a .coffee file routesE2E.get('/__cypress/tests', (req, res, next) => { // slice out the cache buster - const test = decodeURI(CacheBuster.strip(req.query.p)) + const test = decodeURIComponent(CacheBuster.strip(req.query.p)) specController.handle(test, req, res, config, next, onError) }) diff --git a/system-tests/projects/spec-name-special-characters/cypress/integration/fixture%.js b/system-tests/projects/spec-name-special-characters/cypress/integration/fixture&%.js similarity index 100% rename from system-tests/projects/spec-name-special-characters/cypress/integration/fixture%.js rename to system-tests/projects/spec-name-special-characters/cypress/integration/fixture&%.js diff --git a/system-tests/test/specs_spec.js b/system-tests/test/specs_spec.js index da4d3405290..f546b359931 100644 --- a/system-tests/test/specs_spec.js +++ b/system-tests/test/specs_spec.js @@ -41,7 +41,7 @@ describe('e2e specs', () => { }) }) - it('handles specs with % in the name', function () { + it('handles specs with special characters in the file name', function () { const project = Fixtures.projectPath('spec-name-special-characters') return systemTests.exec(this, { From 57abeb911c3eccb9ab016d1d3f4986cde99a2a6b Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Fri, 12 Nov 2021 11:42:30 -0800 Subject: [PATCH 3/4] Don't rely on spec-names not being uri encoded when testing retries --- .../cypress/integration/e2e/rerun_spec.js | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/packages/driver/cypress/integration/e2e/rerun_spec.js b/packages/driver/cypress/integration/e2e/rerun_spec.js index 8572f0f3d79..1d1cb929c2e 100644 --- a/packages/driver/cypress/integration/e2e/rerun_spec.js +++ b/packages/driver/cypress/integration/e2e/rerun_spec.js @@ -4,12 +4,8 @@ // store these on our outer top window // so they are globally preserved -if (window.top.hasRunOnce == null) { - window.top.hasRunOnce = false -} - -if (window.top.previousHash == null) { - window.top.previousHash = window.top.location.hash +if (window.top.runCount == null) { + window.top.runCount = 0 } const isTextTerminal = Cypress.config('isTextTerminal') @@ -20,26 +16,19 @@ describe('rerun state bugs', () => { // but we get the hashchange coverage for free on this. it('stores viewport globally and does not hang on re-runs', () => { cy.viewport(500, 500).then(() => { - if (!window.top.hasRunOnce) { + window.top.runCount++ + if (window.top.runCount === 1) { // turn off mocha events for a second Cypress.config('isTextTerminal', false) - // 1st time around - window.top.hasRunOnce = true - - // cause a rerun event to occur - // by changing the hash - let { hash } = window.top.location - - window.top.location.hash = `${hash}?rerun` + // cause a rerun event to occur by triggering a hash change + window.top.dispatchEvent(new Event('hashchange')) + } else if (window.top.runCount === 2) { + // Second time, do nothing, with mocha events still disabled } else { - if (window.top.location.hash === window.top.previousHash) { - // 3rd time around - // let the mocha end events fire if they're supposed to - Cypress.config('isTextTerminal', isTextTerminal) - } - - window.top.location.hash = window.top.previousHash + // 3rd time around + // let the mocha end events fire if they're supposed to + Cypress.config('isTextTerminal', isTextTerminal) } }) }) From 594053d78b9af8b7948c3c4a361baae6706f5af6 Mon Sep 17 00:00:00 2001 From: Blue F Date: Tue, 16 Nov 2021 08:55:04 -0800 Subject: [PATCH 4/4] Copy-paste error from another test --- .../projects/spec-name-special-characters/cypress/spec.js | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 system-tests/projects/spec-name-special-characters/cypress/spec.js diff --git a/system-tests/projects/spec-name-special-characters/cypress/spec.js b/system-tests/projects/spec-name-special-characters/cypress/spec.js deleted file mode 100644 index df600082261..00000000000 --- a/system-tests/projects/spec-name-special-characters/cypress/spec.js +++ /dev/null @@ -1,8 +0,0 @@ -/// -describe('fixtures in subfolder', () => { - it('works', () => { - cy.fixture('example').should('deep.equal', { - works: true, - }) - }) -})