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

fix: remove --config-file false references and update types #20643

Merged
merged 9 commits into from
Mar 21, 2022
5 changes: 2 additions & 3 deletions cli/__snapshots__/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ exports['shows help for open --foo 1'] = `
cypress.config.{ts|js}.
-C, --config-file <config-file> path to script file where configuration
values are set. defaults to
"cypress.config.{ts|js}". pass "false" to
disable.
"cypress.config.{ts|js}".
-d, --detached [bool] runs Cypress application in detached mode
--e2e runs end to end tests
-e, --env <env> sets environment variables. separate
Expand Down Expand Up @@ -72,7 +71,7 @@ exports['shows help for run --foo 1'] = `
--ci-build-id <id> the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers
--component runs component tests
-c, --config <config> sets configuration values. separate multiple values with a comma. overrides any value in cypress.config.{ts|js}.
-C, --config-file <config-file> path to script file where configuration values are set. defaults to "cypress.config.{ts|js}". pass "false" to disable.
-C, --config-file <config-file> path to script file where configuration values are set. defaults to "cypress.config.{ts|js}".
--e2e runs end to end tests
-e, --env <env> sets environment variables. separate multiple values with a comma. overrides any value in cypress.config.{ts|js} or cypress.env.json
--group <name> a named group for recorded runs in the Cypress Dashboard
Expand Down
1 change: 1 addition & 0 deletions cli/__snapshots__/errors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ exports['errors individual has the following errors 1'] = [
"incompatibleTestTypeFlags",
"incompatibleTestingTypeAndFlag",
"invalidCacheDirectory",
"invalidConfigFile",
"invalidCypressEnv",
"invalidOS",
"invalidRunProjectPath",
Expand Down
7 changes: 0 additions & 7 deletions cli/__snapshots__/run_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ exports['exec run .processRunOptions passes --record option 1'] = [
"my record id"
]

exports['exec run .processRunOptions passes --config-file false option 1'] = [
"--run-project",
null,
"--config-file",
false
]

exports['exec run .processRunOptions defaults to e2e testingType 1'] = [
"--run-project",
null
Expand Down
10 changes: 1 addition & 9 deletions cli/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ function unknownOption (flag, type = 'option') {
}
commander.Command.prototype.unknownOption = unknownOption

const coerceFalseOrString = (arg) => {
return arg !== 'false' ? arg : false
}

const coerceFalse = (arg) => {
return arg !== 'false'
}
Expand Down Expand Up @@ -106,7 +102,7 @@ const descriptions = {
ciBuildId: 'the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers',
component: 'runs component tests',
config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.config.{ts|js}.',
configFile: 'path to script file where configuration values are set. defaults to "cypress.config.{ts|js}". pass "false" to disable.',
configFile: 'path to script file where configuration values are set. defaults to "cypress.config.{ts|js}".',
detached: 'runs Cypress application in detached mode',
dev: 'runs cypress in development and bypasses binary check',
e2e: 'runs end to end tests',
Expand Down Expand Up @@ -315,10 +311,6 @@ const castCypressOptions = (opts) => {
castOpts.port = coerceAnyStringToInt(opts.port)
}

if (_.has(opts, 'configFile')) {
castOpts.configFile = coerceFalseOrString(opts.configFile)
}

return castOpts
}

Expand Down
6 changes: 6 additions & 0 deletions cli/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ const incompatibleTestingTypeAndFlag = {
solution: 'Either set `testingType` or pass a testing type flag, but not both.',
}

const invalidConfigFile = {
description: '`--config-file` cannot be false.',
solution: 'Either pass a relative path to a valid Cypress config file or remove this option.',
}

/**
* This error happens when CLI detects that the child Test Runner process
* was killed with a signal, like SIGBUS
Expand Down Expand Up @@ -424,5 +429,6 @@ module.exports = {
invalidTestingType,
incompatibleTestTypeFlags,
incompatibleTestingTypeAndFlag,
invalidConfigFile,
},
}
26 changes: 18 additions & 8 deletions cli/lib/exec/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const debug = require('debug')('cypress:cli')
const util = require('../util')
const spawn = require('./spawn')
const verify = require('../tasks/verify')
const { processTestingType } = require('./shared')
const { processTestingType, checkConfigFile } = require('./shared')
const { exitWithError } = require('../errors')

/**
* Maps options collected by the CLI
Expand All @@ -25,6 +26,7 @@ const processOpenOptions = (options = {}) => {
}

if (options.configFile !== undefined) {
checkConfigFile(options)
args.push('--config-file', options.configFile)
}

Expand Down Expand Up @@ -67,14 +69,22 @@ const processOpenOptions = (options = {}) => {
module.exports = {
processOpenOptions,
start (options = {}) {
const args = processOpenOptions(options)

function open () {
return spawn.start(args, {
dev: options.dev,
detached: Boolean(options.detached),
stdio: 'inherit',
})
try {
const args = processOpenOptions(options)

return spawn.start(args, {
dev: options.dev,
detached: Boolean(options.detached),
stdio: 'inherit',
})
} catch (err) {
if (err.details) {
return exitWithError(err.details)()
}

throw err
}
}

if (options.dev) {
Expand Down
19 changes: 9 additions & 10 deletions cli/lib/exec/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const util = require('../util')
const spawn = require('./spawn')
const verify = require('../tasks/verify')
const { exitWithError, errors } = require('../errors')
const { processTestingType, throwInvalidOptionError } = require('./shared')
const { processTestingType, throwInvalidOptionError, checkConfigFile } = require('./shared')

/**
* Typically a user passes a string path to the project.
Expand Down Expand Up @@ -58,6 +58,7 @@ const processRunOptions = (options = {}) => {
}

if (options.configFile !== undefined) {
checkConfigFile(options)
args.push('--config-file', options.configFile)
}

Expand Down Expand Up @@ -164,23 +165,21 @@ module.exports = {
})

function run () {
let args

try {
args = processRunOptions(options)
const args = processRunOptions(options)

debug('run to spawn.start args %j', args)

return spawn.start(args, {
dev: options.dev,
})
} catch (err) {
if (err.details) {
return exitWithError(err.details)()
}

throw err
}

debug('run to spawn.start args %j', args)

return spawn.start(args, {
dev: options.dev,
})
}

if (options.dev) {
Expand Down
12 changes: 12 additions & 0 deletions cli/lib/exec/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ const processTestingType = (options) => {
return []
}

/**
* Throws an error if configFile is string 'false' or boolean false
* @param {*} options
*/
const checkConfigFile = (options) => {
// CLI will parse as string, module API can pass in boolean
if (options.configFile === 'false' || options.configFile === false) {
throwInvalidOptionError(errors.invalidConfigFile)
}
}

module.exports = {
throwInvalidOptionError,
processTestingType,
checkConfigFile,
}
42 changes: 0 additions & 42 deletions cli/test/lib/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ describe('cypress', function () {
expect(args).to.deep.eq({ config: JSON.stringify(config) })
})
})

it('passes configFile: false', () => {
const opts = {
configFile: false,
}

return cypress.open(opts)
.then(getStartArgs)
.then((args) => {
expect(args).to.deep.eq(opts)
})
})
})

context('.run fails to write results file', function () {
Expand Down Expand Up @@ -152,18 +140,6 @@ describe('cypress', function () {
return cypress.run().then(snapshot)
})

it('passes configFile: false', () => {
const opts = {
configFile: false,
}

return cypress.run(opts)
.then(getStartArgs)
.then((args) => {
expect(args).to.deep.eq(opts)
})
})

it('rejects if project is an empty string', () => {
return expect(cypress.run({ project: '' })).to.be.rejected
})
Expand Down Expand Up @@ -223,15 +199,6 @@ describe('cypress', function () {
})
})

it('coerces --config-file false to boolean', async () => {
const args = 'cypress run --config-file false'.split(' ')
const options = await cypress.cli.parseRunArguments(args)

expect(options).to.deep.equal({
configFile: false,
})
})

it('coerces --config-file cypress.config.js to string', async () => {
const args = 'cypress run --config-file cypress.config.js'.split(' ')
const options = await cypress.cli.parseRunArguments(args)
Expand All @@ -241,15 +208,6 @@ describe('cypress', function () {
})
})

it('parses config file false', async () => {
const args = 'cypress run --config-file false'.split(' ')
const options = await cypress.cli.parseRunArguments(args)

expect(options).to.deep.equal({
configFile: false,
})
})

it('parses config', async () => {
const args = 'cypress run --config baseUrl=localhost,video=true'.split(' ')
const options = await cypress.cli.parseRunArguments(args)
Expand Down
15 changes: 5 additions & 10 deletions cli/test/lib/exec/open_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ describe('exec open', function () {
})
})

it('spawns with --config-file false', function () {
return open.start({ configFile: false })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--config-file', false],
)
})
})

it('spawns with --config-file set', function () {
return open.start({ configFile: 'special-cypress.config.js' })
.then(() => {
Expand Down Expand Up @@ -142,7 +133,11 @@ describe('exec open', function () {
})

it('throws if --testing-type is invalid', () => {
expect(() => open.start({ testingType: 'randomTestingType' })).to.throw()
expect(() => open.processOpenOptions({ testingType: 'randomTestingType' })).to.throw()
})

it('throws if --config-file is false', () => {
expect(() => open.processOpenOptions({ configFile: 'false' })).to.throw()
})
})
})
21 changes: 4 additions & 17 deletions cli/test/lib/exec/run_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ describe('exec run', function () {
snapshot(args)
})

it('passes --config-file false option', () => {
const args = run.processRunOptions({
configFile: false,
})

snapshot(args)
})

it('does not allow setting paradoxical --headed and --headless flags', () => {
os.platform.returns('linux')
process.exit.returns()
Expand Down Expand Up @@ -112,6 +104,10 @@ describe('exec run', function () {
it('throws if both testingType and component are set', () => {
expect(() => run.processRunOptions({ testingType: 'component', component: true })).to.throw()
})

it('throws if --config-file is false', () => {
expect(() => run.processRunOptions({ configFile: 'false' })).to.throw()
})
})

context('.start', function () {
Expand Down Expand Up @@ -148,15 +144,6 @@ describe('exec run', function () {
})
})

it('spawns with --config-file false', function () {
return run.start({ configFile: false })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--run-project', process.cwd(), '--config-file', false],
)
})
})

it('spawns with --config-file set', function () {
return run.start({ configFile: 'special-cypress.config.js' })
.then(() => {
Expand Down
4 changes: 1 addition & 3 deletions cli/types/cypress-npm-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,9 @@ declare namespace CypressCommandLine {
/**
* Path to the config file to be used.
*
* If `false` is passed, no config file will be used.
*
* @default "cypress.config.{ts|js}"
*/
configFile: string | false
configFile: string
/**
* Specify environment variables.
* TODO: isn't this duplicate of config.env?!
Expand Down
4 changes: 2 additions & 2 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2882,9 +2882,9 @@ declare namespace Cypress {
*/
interface RuntimeConfigOptions extends Partial<RuntimeServerConfigOptions> {
/**
* Absolute path to the config file (default: <projectRoot>/cypress.config.{ts|js}) or false
* Absolute path to the config file (default: <projectRoot>/cypress.config.{ts|js})
*/
configFile: string | false
configFile: string
/**
* CPU architecture, from Node `os.arch()`
*
Expand Down
4 changes: 0 additions & 4 deletions cli/types/tests/cypress-npm-api-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ cypress.run().then(results => {
cypress.open() // $ExpectType Promise<void>
cypress.run() // $ExpectType Promise<CypressRunResult | CypressFailedRunResult>

cypress.open({
configFile: false
})

cypress.run({
configFile: "abc123"
})
Expand Down
2 changes: 1 addition & 1 deletion cli/types/tests/plugins-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const pluginConfig: Cypress.PluginConfig = (on, config) => {}
// allows synchronous returns
const pluginConfig2: Cypress.PluginConfig = (on, config) => {
config // $ExpectType PluginConfigOptions
config.configFile // $ExpectType string | false
config.configFile // $ExpectType string
config.fixturesFolder // $ExpectType string | false
config.screenshotsFolder // $ExpectType string | false
config.videoCompression // $ExpectType number | false
Expand Down
Loading