Skip to content

Commit

Permalink
fix: Revert cypress.json changes (#15499)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding authored Mar 15, 2021
1 parent db6b00d commit 237c426
Show file tree
Hide file tree
Showing 29 changed files with 324 additions and 478 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
4 changes: 2 additions & 2 deletions packages/server/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ module.exports = {
return this.set({
projectName: this.getNameFromRoot(projectRoot),
projectRoot,
config: settings,
envFile,
config: _.cloneDeep(settings),
envFile: _.cloneDeep(envFile),
options,
})
})
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
23 changes: 1 addition & 22 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 @@ -144,27 +140,10 @@ module.exports = {

const file = this.pathToConfigFile(projectRoot, options)

const requireAsync = (file) => {
return Promise.try(() => require(file))
}

return requireAsync(file)
.catch({ code: 'MODULE_NOT_FOUND' }, () => {
return this._write(file, {})
})
return fs.readJsonAsync(file)
.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
5 changes: 0 additions & 5 deletions packages/server/test/e2e/6_visit_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const https = require('https')
const useragent = require('express-useragent')
const { allowDestroy } = require('@packages/network')
const e2e = require('../support/helpers/e2e').default
const { clearCypressJsonCache } = require('../specUtils')

// create an HTTPS server that forces TLSv1
const startTlsV1Server = (port) => {
Expand Down Expand Up @@ -117,10 +116,6 @@ foo\
}

describe('e2e visit', () => {
beforeEach(() => {
clearCypressJsonCache()
})

context('low response timeout', () => {
e2e.setup({
settings: {
Expand Down
5 changes: 0 additions & 5 deletions packages/server/test/e2e/6_web_security_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const e2e = require('../support/helpers/e2e').default
const { clearCypressJsonCache } = require('../specUtils')

const onServer = function (app) {
app.get('/link', (req, res) => {
Expand Down Expand Up @@ -52,10 +51,6 @@ const onServer = function (app) {
}

describe('e2e web security', () => {
beforeEach(() => {
clearCypressJsonCache()
})

e2e.setup({
servers: [{
port: 4466,
Expand Down
5 changes: 0 additions & 5 deletions packages/server/test/e2e/7_record_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {
postInstanceTestsResponse,
} = require('../support/helpers/serverStub')
const { expectRunsToHaveCorrectTimings } = require('../support/helpers/resultsUtils')
const { clearCypressJsonCache } = require('../specUtils')

const e2ePath = Fixtures.projectPath('e2e')
const outputPath = path.join(e2ePath, 'output.json')
Expand Down Expand Up @@ -689,10 +688,6 @@ describe('e2e record', () => {
})

describe('create run 500', () => {
beforeEach(() => {
clearCypressJsonCache()
})

const routes = createRoutes({
postRun: {
res (req, res) {
Expand Down
33 changes: 11 additions & 22 deletions packages/server/test/integration/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const system = require(`${root}lib/util/system`)
const appData = require(`${root}lib/util/app_data`)
const electronApp = require('../../lib/util/electron-app')
const savedState = require(`${root}lib/saved_state`)
const { clearCypressJsonCache } = require('../specUtils')

const TYPICAL_BROWSERS = [
{
Expand Down Expand Up @@ -428,7 +427,6 @@ describe('lib/cypress', () => {
sinon.stub(runMode, 'listenForProjectEnd').resolves({ stats: { failures: 0 } })
sinon.stub(browsers, 'open')
sinon.stub(commitInfo, 'getRemoteOrigin').resolves('remoteOrigin')
clearCypressJsonCache()
})

it('runs project headlessly and exits with exit code 0', function () {
Expand Down Expand Up @@ -1228,8 +1226,6 @@ describe('lib/cypress', () => {

describe('--port', () => {
beforeEach(() => {
clearCypressJsonCache()

return runMode.listenForProjectEnd.resolves({ stats: { failures: 0 } })
})

Expand Down Expand Up @@ -1264,7 +1260,6 @@ describe('lib/cypress', () => {
describe('--env', () => {
beforeEach(() => {
process.env = _.omit(process.env, 'CYPRESS_DEBUG')
clearCypressJsonCache()

return runMode.listenForProjectEnd.resolves({ stats: { failures: 0 } })
})
Expand Down Expand Up @@ -1307,10 +1302,6 @@ describe('lib/cypress', () => {
})

describe('--config-file', () => {
beforeEach(() => {
clearCypressJsonCache()
})

it('false does not require cypress.json to run', function () {
return fs.statAsync(path.join(this.pristinePath, 'cypress.json'))
.then(() => {
Expand Down Expand Up @@ -1930,21 +1921,21 @@ describe('lib/cypress', () => {

describe('--config-file', () => {
beforeEach(function () {
clearCypressJsonCache()
this.filename = 'foo.bar.baz.asdf.quux.json'
this.open = sinon.stub(ServerE2E.prototype, 'open').resolves([])
})

it('reads config from a custom config file', function () {
const filename = 'foo.bar.baz.asdf.quux.json'
sinon.stub(fs, 'readJsonAsync')
fs.readJsonAsync.withArgs(path.join(this.pristinePath, this.filename)).resolves({
env: { foo: 'bar' },
port: 2020,
})

fs.writeFileAsync(
path.join(this.pristinePath, filename),
JSON.stringify({ env: { foo: 'bar' }, port: 2020 }),
'utf8',
)
fs.readJsonAsync.callThrough()

return cypress.start([
`--config-file=${filename}`,
`--config-file=${this.filename}`,
])
.then(() => {
const options = Events.start.firstCall.args[0]
Expand All @@ -1962,13 +1953,11 @@ describe('lib/cypress', () => {
})

it('creates custom config file if it does not exist', function () {
const filename = 'foo.quux.test.json'

return cypress.start([
`--config-file=${filename}`,
`--config-file=${this.filename}`,
])
.then(() => {
debug('cypress started with config %s', filename)
debug('cypress started with config %s', this.filename)
const options = Events.start.firstCall.args[0]

debug('first call arguments %o', Events.start.firstCall.args)
Expand All @@ -1977,7 +1966,7 @@ describe('lib/cypress', () => {
}).then(() => {
expect(this.open, 'open was called').to.be.called

return fs.readJsonAsync(path.join(this.pristinePath, filename))
return fs.readJsonAsync(path.join(this.pristinePath, this.filename))
.then((json) => {
expect(json, 'json file is empty').to.deep.equal({})
})
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
8 changes: 0 additions & 8 deletions packages/server/test/specUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,3 @@ export const getFs = () => {

return recurse({ root: mockfs.getMockRoot() }, -1).root
}

export const clearCypressJsonCache = () => {
Object.keys(require.cache).forEach((key) => {
if (key.includes('cypress.json')) {
delete require.cache[key]
}
})
}
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
Loading

4 comments on commit 237c426

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 237c426 Mar 15, 2021

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/6.7.1/circle-develop-237c426707714a287ff20ef2bdabff5f0c39e93a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 237c426 Mar 15, 2021

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/6.7.1/circle-develop-237c426707714a287ff20ef2bdabff5f0c39e93a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 237c426 Mar 15, 2021

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 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/6.7.1/appveyor-develop-237c426707714a287ff20ef2bdabff5f0c39e93a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 237c426 Mar 15, 2021

Choose a reason for hiding this comment

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

AppVeyor has built the win32 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/6.7.1/appveyor-develop-237c426707714a287ff20ef2bdabff5f0c39e93a/cypress.tgz

Please sign in to comment.