Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Initial work on creating a multidomain bundle #16230

Merged
merged 7 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/driver/cypress/fixtures/multidomain-aut.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Multidomain AUT</h1>
<p>Some text in the cross-domain AUT</p>
<script>
setTimeout(() => {
window.onReady()
}, 500)
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions packages/driver/cypress/fixtures/multidomain-sibling.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script src="/cypress_multidomain_runner.js"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions packages/driver/cypress/fixtures/multidomain.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<iframe src="http://localhost:3501/fixtures/multidomain-aut.html" width="800" height="800"></iframe>
<iframe src="http://localhost:3501/fixtures/multidomain-sibling.html" width="10" height="10"></iframe>
</body>
</html>
5 changes: 5 additions & 0 deletions packages/driver/cypress/integration/e2e/multidomain_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: this test only exists for manual verification as the
// multidomain bundle is a very incomplete work-in-progress
it('loads multidomain playground', () => {
cy.visit('/fixtures/multidomain.html')
})
8 changes: 8 additions & 0 deletions packages/driver/cypress/plugins/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const path = require('path')
const Promise = require('bluebird')

const PATH_TO_SERVER_PKG = path.dirname(require.resolve('@packages/server'))
const PATH_TO_RUNNER_PKG = path.dirname(require.resolve('@packages/runner'))
const httpPorts = [3500, 3501]
const httpsPort = 3502

Expand Down Expand Up @@ -156,6 +157,13 @@ const createApp = (port) => {
.send('<html><body>server error</body></html>')
})

app.get('/cypress_multidomain_runner.js', (req, res) => {
res.type('application/javascript')
res.sendFile(path.join('dist', 'cypress_multidomain_runner.js'), {
root: path.join(PATH_TO_RUNNER_PKG, '..'),
})
})

let _var = ''

app.get('/set-var', (req, res) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/driver/src/cypress/cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ const setTopOnError = function (Cypress, cy) {

curCy = cy

try {
// this will throw if AUT is cross-domain and we don't need to worry
// about top's error handler in that case anyway
top.__alreadySetErrorHandlers__
} catch (err) {
return
}

// prevent overriding top.onerror twice when loading more than one
// instance of test runner.
if (top.__alreadySetErrorHandlers__) {
Expand Down
48 changes: 48 additions & 0 deletions packages/driver/src/multidomain/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import $Cypress from '../cypress'
import $Cy from '../cypress/cy'
import $Commands from '../cypress/commands'
import $Log from '../cypress/log'

export const initialize = (autWindow) => {
const specWindow = {
Error,
}
const Cypress = $Cypress.create({
browser: {
channel: 'stable',
displayName: 'Chrome',
family: 'chromium',
isChosen: true,
isHeaded: true,
isHeadless: false,
majorVersion: 90,
name: 'chrome',
path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
version: '90.0.4430.212',
},
})
const log = (...args) => {
return Cypress.log.apply(Cypress, args)
}
const cy = $Cy.create(specWindow, Cypress, Cypress.Cookies, Cypress.state, Cypress.config, log)

Cypress.log = $Log.create(Cypress, cy, Cypress.state, Cypress.config)
Cypress.runner = {
addLog () {},
}

Cypress.state('window', autWindow)
Cypress.state('document', autWindow.document)
Cypress.state('runnable', {
ctx: {},
clearTimeout () {},
resetTimeout () {},
timeout () {},
})

$Commands.create(Cypress, cy, Cypress.state)

return {
cy,
}
}
5 changes: 5 additions & 0 deletions packages/runner/multidomain/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"globals": {
"window": true
}
}
33 changes: 33 additions & 0 deletions packages/runner/multidomain/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { initialize } from '@packages/driver/src/multidomain'

const autWindow = window.parent.frames[0]

const { cy } = initialize(autWindow)

autWindow.onReady = () => {
cy.now('get', 'p').then(($el) => {
// eslint-disable-next-line no-console
console.log('got the paragaph with text:', $el.text())
})
}

/*

Need:
- Cypress
- cy, with
- built-in commands
- user-defined commands

Commands need:
- state
- config
- events

Don't need:
- UI components
- spec runner
- mocha
- wasm / source map utils

*/
15 changes: 14 additions & 1 deletion packages/runner/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,17 @@ const injectionConfig: webpack.Configuration = {
},
}

export default [mainConfig, injectionConfig]
// @ts-ignore
const multiDomainConfig: webpack.Configuration = {
mode: 'development',
...getSimpleConfig(),
entry: {
cypress_multidomain_runner: [path.resolve(__dirname, 'multidomain/index.js')],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
}

export default [mainConfig, injectionConfig, multiDomainConfig]
45 changes: 37 additions & 8 deletions packages/web-config/webpack.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ function makeSassLoaders ({ modules }): RuleSetRule {
}
}

// the chrome version should be synced with
// npm/webpack-batteries-included-preprocessor/index.js and
// packages/server/lib/browsers/chrome.ts
const babelPresetEnvConfig = [require.resolve('@babel/preset-env'), { targets: { 'chrome': '64' } }]
const babelPresetTypeScriptConfig = [require.resolve('@babel/preset-typescript'), { allowNamespaces: true }]

export const getCommonConfig = () => {
const commonConfig: Configuration = {
mode: 'none',
Expand Down Expand Up @@ -128,12 +134,9 @@ export const getCommonConfig = () => {
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }],
],
presets: [
// the chrome version should be synced with
// npm/webpack-batteries-included-preprocessor/index.js and
// packages/server/lib/browsers/chrome.ts
[require.resolve('@babel/preset-env'), { targets: { 'chrome': '64' } }],
babelPresetEnvConfig,
require.resolve('@babel/preset-react'),
[require.resolve('@babel/preset-typescript'), { allowNamespaces: true }],
babelPresetTypeScriptConfig,
],
babelrc: false,
},
Expand Down Expand Up @@ -216,8 +219,15 @@ export const getCommonConfig = () => {

// eslint-disable-next-line @cypress/dev/arrow-body-multiline-braces
export const getSimpleConfig = () => ({
node: {
fs: 'empty',
child_process: 'empty',
net: 'empty',
tls: 'empty',
module: 'empty',
},
resolve: {
extensions: ['.js'],
extensions: ['.js', '.ts', '.json'],
},

stats,
Expand All @@ -228,18 +238,37 @@ export const getSimpleConfig = () => ({
module: {
rules: [
{
test: /\.(js)$/,
test: /\.(js|ts)$/,
exclude: /node_modules/,
use: {
loader: require.resolve('babel-loader'),
options: {
plugins: [
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }],
],
presets: [
[require.resolve('@babel/preset-env'), { targets: { 'chrome': 63 } }],
babelPresetEnvConfig,
babelPresetTypeScriptConfig,
],
babelrc: false,
},
},
},
// FIXME: we don't actually want or need wasm support in the
// multidomain bundle that uses this config, but we need to refactor
// the driver so that it doesn't load the wasm code in
// packages/driver/src/cypress/source_map_utils.js when creating
// the multidomain bundle. for now, this is necessary so the build
// doesn't fail
{
test: /\.wasm$/,
type: 'javascript/auto',
use: [
{
loader: require.resolve('arraybuffer-loader'),
},
],
},
],
},

Expand Down