Skip to content

Commit

Permalink
Merge branch 'develop' into ryanm/fix/improve-binary-cleanup-to-look-…
Browse files Browse the repository at this point in the history
…at-binary-rather-than-monorepo
  • Loading branch information
ryanthemanuel committed Nov 9, 2022
2 parents 8e22bad + 547b700 commit cc95def
Show file tree
Hide file tree
Showing 40 changed files with 2,804 additions and 491 deletions.
8 changes: 4 additions & 4 deletions npm/grep/README.md
Expand Up @@ -84,12 +84,12 @@ yarn add -D @cypress/grep
```js
// cypress/support/index.js
// load and register the grep feature using "require" function
// https://github.com/cypress-io/cypress-grep
const registerCypressGrep = require('cypress-grep')
// https://github.com/cypress-io/cypress/tree/develop/npm/grep
const registerCypressGrep = require('@cypress/grep')
registerCypressGrep()

// if you want to use the "import" keyword
import registerCypressGrep from 'cypress-grep'
import registerCypressGrep from '@cypress/grep'
registerCypressGrep()
```

Expand All @@ -102,7 +102,7 @@ registerCypressGrep()
{
e2e: {
setupNodeEvents(on, config) {
require('cypress-grep/src/plugin')(config);
require('@cypress/grep/src/plugin')(config);
return config;
},
}
Expand Down
2 changes: 1 addition & 1 deletion npm/grep/src/support.js
Expand Up @@ -4,7 +4,7 @@
const { parseGrep, shouldTestRun } = require('./utils')
// @ts-ignore
const { version } = require('../package.json')
const debug = require('debug')('cypress-grep')
const debug = require('debug')('@cypress/grep')

debug.log = console.info.bind(console)

Expand Down
7 changes: 7 additions & 0 deletions npm/vite-dev-server/CHANGELOG.md
@@ -1,3 +1,10 @@
# [@cypress/vite-dev-server-v4.0.1](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v4.0.0...@cypress/vite-dev-server-v4.0.1) (2022-11-08)


### Bug Fixes

* vite-dev-server hoisting issue in binary ([#24599](https://github.com/cypress-io/cypress/issues/24599)) ([2513bea](https://github.com/cypress-io/cypress/commit/2513beac307e95267ab736a93a39cd1cd1280506))

# [@cypress/vite-dev-server-v4.0.0](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v3.4.0...@cypress/vite-dev-server-v4.0.0) (2022-11-07)


Expand Down
2 changes: 1 addition & 1 deletion npm/vite-dev-server/package.json
Expand Up @@ -15,7 +15,7 @@
"test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js"
},
"dependencies": {
"debug": "4.3.3",
"debug": "^4.3.4",
"find-up": "6.3.0",
"node-html-parser": "5.3.3"
},
Expand Down
7 changes: 7 additions & 0 deletions npm/webpack-dev-server/CHANGELOG.md
@@ -1,3 +1,10 @@
# [@cypress/webpack-dev-server-v3.0.1](https://github.com/cypress-io/cypress/compare/@cypress/webpack-dev-server-v3.0.0...@cypress/webpack-dev-server-v3.0.1) (2022-11-08)


### Bug Fixes

* revert dynamic import of webpack config file ([#24598](https://github.com/cypress-io/cypress/issues/24598)) ([69f7dab](https://github.com/cypress-io/cypress/commit/69f7dabc94a5adb25edc7fda6057e92b8bd2e072))

# [@cypress/webpack-dev-server-v3.0.0](https://github.com/cypress-io/cypress/compare/@cypress/webpack-dev-server-v2.5.0...@cypress/webpack-dev-server-v3.0.0) (2022-11-07)


Expand Down
1 change: 1 addition & 0 deletions npm/webpack-dev-server/package.json
Expand Up @@ -21,6 +21,7 @@
"fs-extra": "9.1.0",
"html-webpack-plugin-4": "npm:html-webpack-plugin@^4",
"html-webpack-plugin-5": "npm:html-webpack-plugin@^5",
"local-pkg": "0.4.1",
"speed-measure-webpack-plugin": "1.4.2",
"tslib": "^2.3.1",
"webpack-dev-server": "^4.7.4",
Expand Down
5 changes: 3 additions & 2 deletions npm/webpack-dev-server/src/makeWebpackConfig.ts
@@ -1,11 +1,12 @@
import { debug as debugFn } from 'debug'
import * as path from 'path'
import { merge } from 'webpack-merge'
import { importModule } from 'local-pkg'
import type { Configuration, EntryObject } from 'webpack'
import { makeCypressWebpackConfig } from './makeDefaultWebpackConfig'
import type { CreateFinalWebpackConfig } from './createWebpackDevServer'
import { configFiles } from './constants'
import { dynamicAbsoluteImport, dynamicImport } from './dynamic-import'
import { dynamicImport } from './dynamic-import'

const debug = debugFn('cypress:webpack-dev-server:makeWebpackConfig')

Expand Down Expand Up @@ -90,7 +91,7 @@ export async function makeWebpackConfig (

if (configFile) {
debug('found webpack config %s', configFile)
const sourcedConfig = await dynamicAbsoluteImport(configFile)
const sourcedConfig = await importModule(configFile)

debug('config contains %o', sourcedConfig)
if (sourcedConfig && typeof sourcedConfig === 'object') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cypress",
"version": "10.11.0",
"version": "11.0.0",
"description": "Cypress is a next generation front end testing tool built for the modern web",
"private": true,
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/browser.ts
Expand Up @@ -156,7 +156,7 @@ export const matchesConfigKey = (key: string) => {
}

export const validate = (cfg: any, onErr: (property: ErrResult | string) => void, testingType: TestingType | null) => {
debug('validating configuration')
debug('validating configuration', cfg)

return _.each(cfg, (value, key) => {
const validationFn = validationRules[key]
Expand All @@ -166,7 +166,7 @@ export const validate = (cfg: any, onErr: (property: ErrResult | string) => void
const result = validationFn(key, value, {
testingType,
// TODO: remove with experimentalSessionAndOrigin. Fixed with: https://github.com/cypress-io/cypress/issues/21471
experimentalSessionAndOrigin: cfg.experimentalSessionAndOrigin,
experimentalSessionAndOrigin: cfg.e2e?.experimentalSessionAndOrigin || cfg.experimentalSessionAndOrigin,
})

if (result !== true) {
Expand Down
38 changes: 38 additions & 0 deletions packages/driver/cypress/e2e/e2e/origin/origin.cy.ts
Expand Up @@ -10,6 +10,44 @@ describe('cy.origin', { browser: '!webkit' }, () => {
})
})

it('creates and injects into google subdomains', () => {
// Intercept google to keep our tests independent from google.
cy.intercept('https://www.google.com', {
body: '<html><head><title></title></head><body><p>google.com</p></body></html>',
})

cy.intercept('https://accounts.google.com', {
body: '<html><head><title></title></head><body><p>accounts.google.com</p></body></html>',
})

cy.visit('https://www.google.com')
cy.visit('https://accounts.google.com')
cy.origin('https://accounts.google.com', () => {
cy.window().then((win) => {
expect(win.Cypress).to.exist
})
})
})

it('creates and injects into google subdomains when visiting in an origin block', () => {
// Intercept google to keep our tests independent from google.
cy.intercept('https://www.google.com', {
body: '<html><head><title></title></head><body><p>google.com</p></body></html>',
})

cy.intercept('https://accounts.google.com', {
body: '<html><head><title></title></head><body><p>accounts.google.com</p></body></html>',
})

cy.visit('https://www.google.com')
cy.origin('https://accounts.google.com', () => {
cy.visit('https://accounts.google.com')
cy.window().then((win) => {
expect(win.Cypress).to.exist
})
})
})

it('passes viewportWidth/Height state to the secondary origin', () => {
const expectedViewport = [320, 480]

Expand Down
84 changes: 84 additions & 0 deletions packages/driver/cypress/e2e/e2e/origin/validation.cy.ts
@@ -1,4 +1,8 @@
describe('cy.origin', { browser: '!webkit' }, () => {
beforeEach(() => {
cy.visit('')
})

describe('successes', () => {
it('succeeds on a localhost domain name', () => {
cy.origin('localhost', () => undefined)
Expand Down Expand Up @@ -357,3 +361,83 @@ describe('cy.origin', { browser: '!webkit' }, () => {
})
})
})

describe('cy.origin - external hosts', { browser: '!webkit' }, () => {
describe('successes', () => {
it('succeeds on a complete origin from https using https', () => {
cy.visit('https://www.foobar.com:3502/fixtures/primary-origin.html')
cy.origin('https://www.idp.com:3502', () => undefined)
cy.then(() => {
const expectedSrc = `https://www.idp.com:3502/__cypress/spec-bridge-iframes`
const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://www.idp.com:3502') as HTMLIFrameElement

expect(iframe.src).to.equal(expectedSrc)
})
})

it('succeeds if url is the super domain as top but the super domain is excepted and must be strictly same origin', () => {
// Intercept google to keep our tests independent from google.
cy.intercept('https://www.google.com', {
body: '<html><head><title></title></head><body><p></body></html>',
})

cy.visit('https://www.google.com')
cy.origin('accounts.google.com', () => undefined)
cy.then(() => {
const expectedSrc = `https://accounts.google.com/__cypress/spec-bridge-iframes`
const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://accounts.google.com') as HTMLIFrameElement

expect(iframe.src).to.equal(expectedSrc)
})
})
})

describe('errors', () => {
it('errors if the url param is same superDomainOrigin as top', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.include('`cy.origin()` requires the first argument to be a different domain than top. You passed `http://app.foobar.com` to the origin command, while top is at `http://www.foobar.com`.')

done()
})

cy.intercept('http://www.foobar.com', {
body: '<html><head><title></title></head><body><p></body></html>',
})

cy.intercept('http://app.foobar.com', {
body: '<html><head><title></title></head><body><p></body></html>',
})

cy.visit('http://www.foobar.com')

cy.origin('http://app.foobar.com', () => undefined)
})

it('errors if the url param is same origin as top', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.include('`cy.origin()` requires the first argument to be a different origin than top. You passed `https://www.google.com` to the origin command, while top is at `https://www.google.com`.')

done()
})

// Intercept google to keep our tests independent from google.
cy.intercept('https://www.google.com', {
body: '<html><head><title></title></head><body><p></body></html>',
})

cy.visit('https://www.google.com')
cy.origin('https://www.google.com', () => undefined)
})

it('errors and does not hang when throwing a mixed content error creating the spec bridge', { defaultCommandTimeout: 50 }, (done) => {
cy.on('fail', (err) => {
expect(err.message).to.include(`\`cy.origin()\` failed to create a spec bridge to communicate with the specified origin. This can happen when you attempt to create a spec bridge to an insecure (http) frame from a secure (https) frame.`)

done()
})

cy.visit('https://www.foobar.com:3502/fixtures/primary-origin.html')
cy.origin('http://www.foobar.com:3500', () => {})
})
})
})
30 changes: 16 additions & 14 deletions packages/driver/src/cy/commands/origin/index.ts
Expand Up @@ -38,7 +38,7 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State
communicator.userInvocationStack = userInvocationStack

// this command runs for as long as the commands in the secondary
// origin run, so it can't have its own timeout
// origin run, so it can't have its own timeout except in the case where we're creating the spec bridge.
cy.clearTimeout()

if (!config('experimentalSessionAndOrigin')) {
Expand All @@ -47,6 +47,7 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State

let options
let callbackFn
const timeout = Cypress.config('defaultCommandTimeout')

if (fn) {
callbackFn = fn
Expand All @@ -64,7 +65,7 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State
name: 'origin',
type: 'parent',
message: urlOrDomain,
timeout: 0,
timeout,
// @ts-ignore TODO: revisit once log-grouping has more implementations
}, (_log) => {
log = _log
Expand All @@ -84,15 +85,15 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State
const url = new URL(normalizeOrigin(urlOrDomain)).toString()
const location = $Location.create(url)

validator.validateLocation(location, urlOrDomain)
validator.validateLocation(location, urlOrDomain, window.location.href)

const origin = location.origin

// This is set while IN the cy.origin command.
cy.state('currentActiveOrigin', origin)

return new Bluebird((resolve, reject, onCancel) => {
const cleanup = ({ readyForOriginFailed }: {readyForOriginFailed?: boolean} = {}): void => {
const cleanup = (): void => {
cy.state('currentActiveOrigin', undefined)

communicator.off('queue:finished', onQueueFinished)
Expand All @@ -108,8 +109,10 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State
resolve(unserializableSubjectType ? createUnserializableSubjectProxy(unserializableSubjectType) : subject)
}

const _reject = (err, cleanupOptions: {readyForOriginFailed?: boolean} = {}) => {
cleanup(cleanupOptions)
const _reject = (err) => {
// Prevent cypress from trying to add the function to the error log
err.onFail = () => {}
cleanup()
log?.error(err)
reject(err)
}
Expand Down Expand Up @@ -141,9 +144,6 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State
wrappedErr.name = err.name
wrappedErr.stack = $stackUtils.replacedStack(wrappedErr, err.stack)

// Prevent cypress from trying to add the function to the error log
wrappedErr.onFail = () => {}

return _reject(wrappedErr)
}

Expand All @@ -168,9 +168,15 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State
})
}

// If the spec bridge isn't created in time, it likely failed and we shouldn't hang the test.
const timeoutId = setTimeout(() => {
_reject($errUtils.errByPath('origin.failed_to_create_spec_bridge'))
}, timeout)

// fired once the spec bridge is set up and ready to receive messages
communicator.once('bridge:ready', async (_data, { origin: specBridgeOrigin }) => {
if (specBridgeOrigin === origin) {
clearTimeout(timeoutId)
// now that the spec bridge is ready, instantiate Cypress with the current app config and environment variables for initial sync when creating the instance
communicator.toSpecBridge(origin, 'initialize:cypress', {
config: preprocessConfig(Cypress.config()),
Expand Down Expand Up @@ -229,11 +235,7 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State
// It tries to add a bunch of stuff that's not useful and ends up
// messing up the stack that we want on the error
wrappedErr.__stackCleaned__ = true

// Prevent cypress from trying to add the function to the error log
wrappedErr.onFail = () => {}

_reject(wrappedErr, { readyForOriginFailed: true })
_reject(wrappedErr)
}
}
})
Expand Down

3 comments on commit cc95def

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cc95def Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/11.0.1/linux-x64/ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo-cc95defc7147a7ab6fcb134a8d3e29604d072b65/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cc95def Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/11.0.1/linux-arm64/ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo-cc95defc7147a7ab6fcb134a8d3e29604d072b65/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cc95def Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/11.0.1/darwin-x64/ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo-cc95defc7147a7ab6fcb134a8d3e29604d072b65/cypress.tgz

Please sign in to comment.