Skip to content

Commit

Permalink
Revert "feat: support ct/e2e specific overrides in cypress.json (#15444
Browse files Browse the repository at this point in the history
…)"

This reverts commit a94c9d5.
  • Loading branch information
chrisbreiding committed Mar 15, 2021
1 parent db6b00d commit ff4a824
Show file tree
Hide file tree
Showing 22 changed files with 296 additions and 416 deletions.
563 changes: 275 additions & 288 deletions cli/schema/cypress.schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare namespace Cypress {
type RequestBody = string | object
type ViewportOrientation = 'portrait' | 'landscape'
type PrevSubject = 'optional' | 'element' | 'document' | 'window'
type PluginConfig = (on: PluginEvents, config: PluginConfigOptions, mode: 'e2e' | 'component') => void | ConfigOptions | Promise<ConfigOptions>
type PluginConfig = (on: PluginEvents, config: PluginConfigOptions) => void | ConfigOptions | Promise<ConfigOptions>

interface CommandOptions {
prevSubject: boolean | PrevSubject | PrevSubject[]
Expand Down
6 changes: 1 addition & 5 deletions npm/react/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ const webpackConfig = {
/**
* @type Cypress.PluginConfig
*/
module.exports = (on, config, mode) => {
if (mode !== 'component') {
throw Error('This is an component project. mode should be `component`.')
}

module.exports = (on, config) => {
on('dev-server:start', (options) => {
return startDevServer({ options, webpackConfig, disableLazyCompilation: false })
})
Expand Down
6 changes: 1 addition & 5 deletions npm/vue/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const webpackConfig = require('../../webpack.config')
/**
* @type Cypress.PluginConfig
*/
module.exports = (on, config, mode) => {
if (mode !== 'component') {
throw Error('This is a component testing project. mode should be `component`.')
}

module.exports = (on, config) => {
require('@cypress/code-coverage/task')(on, config)
on('dev-server:start', (options) => startDevServer({ options, webpackConfig }))

Expand Down
3 changes: 1 addition & 2 deletions packages/server-ct/src/project-ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ProjectCt extends ProjectBase<ServerCt> {
this.server.socket.changeToUrl(targetUrl)
}

open (options: Record<string, unknown>) {
open (options) {
this._server = new ServerCt()

return super.open(options, {
Expand Down Expand Up @@ -85,7 +85,6 @@ export class ProjectCt extends ProjectBase<ServerCt> {
return plugins.init(allowedCfg, {
projectRoot: this.projectRoot,
configFile: settings.pathToConfigFile(this.projectRoot, options),
mode: options.mode,
})
.then((modifiedCfg) => {
debug('plugin config yielded: %o', modifiedCfg)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/open_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ const moduleFactory = () => {
debug('opening project %s', path)
debug('and options %o', options)

return openProject.open({ ...options, mode: args.testingType })
return openProject.open(options)
.return(this)
},
}
Expand Down
14 changes: 4 additions & 10 deletions packages/server/lib/plugins/child/run_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ const getDefaultPreprocessor = function (config) {

let plugins

/**
* @param {EventEmitter} ipc
* @param {object} config
* @param {string} pluginsFile
* @param {'component' | 'e2e'} string
*/
const load = (ipc, config, pluginsFile, mode) => {
const load = (ipc, config, pluginsFile) => {
debug('run plugins function')

let eventIdCount = 0
Expand Down Expand Up @@ -93,7 +87,7 @@ const load = (ipc, config, pluginsFile, mode) => {
.try(() => {
debug('run plugins function')

return plugins(register, config, mode)
return plugins(register, config)
})
.tap(() => {
if (!registeredEventsByName['file:preprocessor']) {
Expand Down Expand Up @@ -198,10 +192,10 @@ const runPlugins = (ipc, pluginsFile, projectRoot) => {
return
}

ipc.on('load', (config, mode) => {
ipc.on('load', (config) => {
debug('plugins load file "%s"', pluginsFile)
debug('passing config %o', config)
load(ipc, config, pluginsFile, mode)
load(ipc, config, pluginsFile)
})

ipc.on('execute', (event, ids, args) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const init = (config, options) => {
version: pkg.version,
})

ipc.send('load', config, options.mode)
ipc.send('load', config)

ipc.on('loaded', (newCfg, registrations) => {
_.omit(config, 'projectRoot', 'configFile')
Expand Down
3 changes: 1 addition & 2 deletions packages/server/lib/project-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ProjectE2E extends ProjectBase<ServerE2E> {
return 'e2e'
}

open (options: Record<string, unknown>) {
open (options) {
this._server = new ServerE2E()

return super.open(options, {
Expand Down Expand Up @@ -59,7 +59,6 @@ export class ProjectE2E extends ProjectBase<ServerE2E> {
return plugins.init(cfg, {
projectRoot: this.projectRoot,
configFile: settings.pathToConfigFile(this.projectRoot, options),
mode: options.mode,
onError (err) {
debug('got plugins error', err.stack)

Expand Down
14 changes: 0 additions & 14 deletions packages/server/lib/util/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ module.exports = {
}, _.cloneDeep(obj))
},

isComponentTesting (options = {}) {
return options.experimentalComponentTesting || options.componentTesting || options.testingType === 'component'
},

configFile (options = {}) {
return options.configFile === false ? false : (options.configFile || 'cypress.json')
},
Expand Down Expand Up @@ -155,16 +151,6 @@ module.exports = {
.catch({ code: 'ENOENT' }, () => {
return this._write(file, {})
}).then((json = {}) => {
if (this.isComponentTesting(options) && 'component' in json) {
json = { ...json, ...json.component }
delete json.component
}

if (!this.isComponentTesting(options) && 'e2e' in json) {
json = { ...json, ...json.e2e }
delete json.e2e
}

const changed = this._applyRewriteRules(json)

// if our object is unchanged
Expand Down
1 change: 0 additions & 1 deletion packages/server/test/integration/plugins_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('lib/plugins', () => {

const options = {
onWarning,
mode: 'e2e',
}

return plugins.init(projectConfig, options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ const { expect } = require('chai')
const fse = require('fs-extra')
const path = require('path')

module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
const parentPid = process.ppid
let { PATH_TO_CHROME_PROFILE } = config.env

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ const webpackConfig = {
/**
* @type Cypress.PluginConfig
*/
module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
require('@cypress/code-coverage/task')(on, config)
on('dev-server:start', (options) => startDevServer({ options, webpackConfig }))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ const { useFixedFirefoxResolution } = require('../../../utils')
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
let performance = {
track: () => Promise.resolve(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ let timings = []
let rss = []
let intervalId

module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
on('task', {
'console' (...args) {
console.log(...args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ const getHandlersByType = (type) => {
}
}

module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
const beforeBrowserLaunchHandler = config.env.BEFORE_BROWSER_LAUNCH_HANDLER

if (!beforeBrowserLaunchHandler) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const semver = require('semver')

module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
if (!semver.valid(config.version)) {
throw new Error('config.version is invalid')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
return new Promise((resolve) => {
setTimeout(resolve, 100)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
if (config.env.NO_MUTATE_RETURN) {
on('before:browser:launch', (browser, options) => {
// this will emit a warning
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const fs = require('fs')
const { expect } = require('chai')

module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
expect(process.geteuid()).to.not.eq(0)
console.log('✅ not running as root')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const { useFixedFirefoxResolution } = require('../../../utils')
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config, mode) => {
if (mode !== 'e2e') {
throw Error('This is an e2e project. mode should be `e2e`.')
}

module.exports = (on, config) => {
on('before:browser:launch', (browser, options) => {
useFixedFirefoxResolution(browser, options, config)

Expand Down
36 changes: 0 additions & 36 deletions packages/server/test/unit/settings_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,42 +111,6 @@ describe('lib/settings', () => {
})
})

it('promises cypress.json and merges CT specific properties for via testingType: component', function () {
return this.setup({ a: 'b', component: { a: 'c' } })
.then(() => {
return settings.read(projectRoot, { testingType: 'component' })
}).then((obj) => {
expect(obj).to.deep.eq({ a: 'c' })
})
})

it('promises cypress.json and merges CT specific properties for via componentTesting: true', function () {
return this.setup({ a: 'b', component: { a: 'c' } })
.then(() => {
return settings.read(projectRoot, { componentTesting: true })
}).then((obj) => {
expect(obj).to.deep.eq({ a: 'c' })
})
})

it('promises cypress.json and merges CT specific properties for via experimentalComponentTesting: true', function () {
return this.setup({ a: 'b', component: { a: 'c' } })
.then(() => {
return settings.read(projectRoot, { experimentalComponentTesting: true })
}).then((obj) => {
expect(obj).to.deep.eq({ a: 'c' })
})
})

it('promises cypress.json and merges e2e specific properties', function () {
return this.setup({ a: 'b', e2e: { a: 'c' } })
.then(() => {
return settings.read(projectRoot)
}).then((obj) => {
expect(obj).to.deep.eq({ a: 'c' })
})
})

it('renames commandTimeout -> defaultCommandTimeout', function () {
return this.setup({ commandTimeout: 30000, foo: 'bar' })
.then(() => {
Expand Down

0 comments on commit ff4a824

Please sign in to comment.