Skip to content

Commit

Permalink
decaffeinate: Run post-processing cleanups on screenshots_spec.coffee
Browse files Browse the repository at this point in the history
clean up cy chaining + eslint, decaffeinate suggestions

rename .coffee to .js files in spec

- reference own filename in test assertions
- fix some element screenshots that were no longer chained off el.

fix eslint for fixture specs (#5176)

* update eslint to lint files within 'fixtures' in support files

- ignore some edge cases like jquery, jsx and obvious js files we wrote
with broken code

* Fixes from eslint to 'fixtures' files

Catch env variable with reserved name CYPRESS_ENV 1621 (#1626)

* server: check CYPRESS_ENV variable when merging configs

* catch invalid CYPRESS_ENV value in CLI, close #1621

* linting

* sanitize platform in test snapshot

* linting

* update error message text

* add missing comma

* fix finally merge in JS code

* pass CLI linter

* fix log reference, should be debug

* use correct sinon reference

* update message, show first part in red

* update error message text

Addresses #2953 (#5174)

* Addresses #2953

* Added proper test for new error message

* Didn't realize it ran this test as well, whoops

* Implementing changes as suggested by @jennifer-shehane

* Fixing tests and error output. Moved the checks to the start of the get command to ensure we always catch improper options

* Removing issue test since the querying spec covers it

* Using coffescript isArray check
  • Loading branch information
jennifer-shehane authored and kuceb committed Sep 24, 2019
1 parent a8aa7d0 commit 333a0ef
Show file tree
Hide file tree
Showing 40 changed files with 672 additions and 403 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
**/node_modules
**/support/fixtures/*
!**/support/fixtures/projects
**/support/fixtures/projects/**/_fixtures/*
**/support/fixtures/projects/**/*.jsx
**/support/fixtures/projects/**/jquery.js
**/support/fixtures/projects/**/fail.js
**/test/fixtures
**/vendor

Expand Down
29 changes: 29 additions & 0 deletions cli/__snapshots__/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,32 @@ exports['shows help for run --foo 1'] = `
-------
`

exports['cli CYPRESS_ENV allows staging environment 1'] = `
code: 0
stderr:
-------
-------
`

exports['cli CYPRESS_ENV catches environment "foo" 1'] = `
code: 11
stderr:
-------
The environment variable with the reserved name "CYPRESS_ENV" is set.
Unset the "CYPRESS_ENV" environment variable and run Cypress again.
----------
CYPRESS_ENV=foo
----------
Platform: xxx
Cypress Version: 1.2.3
-------
`
1 change: 1 addition & 0 deletions cli/__snapshots__/errors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports['errors individual has the following errors 1'] = [
"failedDownload",
"failedUnzip",
"invalidCacheDirectory",
"invalidCypressEnv",
"invalidSmokeTestDisplayError",
"missingApp",
"missingDependency",
Expand Down
2 changes: 1 addition & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ switch (args.exec) {

break
default:
// export our node module interface
debug('exporting Cypress module interface')
module.exports = require('./lib/cypress')
}
107 changes: 86 additions & 21 deletions cli/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const logSymbols = require('log-symbols')
const debug = require('debug')('cypress:cli')
const util = require('./util')
const logger = require('./logger')
const errors = require('./errors')
const cache = require('./tasks/cache')

// patch "commander" method called when a user passed an unknown option
Expand All @@ -27,7 +28,9 @@ const coerceFalse = (arg) => {
const spaceDelimitedSpecsMsg = (files) => {
logger.log()
logger.warn(stripIndent`
${logSymbols.warning} Warning: It looks like you're passing --spec a space-separated list of files:
${
logSymbols.warning
} Warning: It looks like you're passing --spec a space-separated list of files:
"${files.join(' ')}"
Expand All @@ -54,7 +57,8 @@ const parseVariableOpts = (fnArgs, args) => {
const nextOptOffset = _.findIndex(_.slice(args, argIndex), (arg) => {
return _.startsWith(arg, '--')
})
const endIndex = nextOptOffset !== -1 ? argIndex + nextOptOffset : args.length
const endIndex =
nextOptOffset !== -1 ? argIndex + nextOptOffset : args.length

const maybeSpecs = _.slice(args, argIndex, endIndex)
const extraSpecs = _.intersection(maybeSpecs, fnArgs)
Expand All @@ -70,11 +74,34 @@ const parseVariableOpts = (fnArgs, args) => {
}

const parseOpts = (opts) => {
opts = _.pick(opts,
'project', 'spec', 'reporter', 'reporterOptions', 'path', 'destination',
'port', 'env', 'cypressVersion', 'config', 'record', 'key',
'browser', 'detached', 'headed', 'global', 'dev', 'force', 'exit',
'cachePath', 'cacheList', 'cacheClear', 'parallel', 'group', 'ciBuildId')
opts = _.pick(
opts,
'project',
'spec',
'reporter',
'reporterOptions',
'path',
'destination',
'port',
'env',
'cypressVersion',
'config',
'record',
'key',
'browser',
'detached',
'headed',
'global',
'dev',
'force',
'exit',
'cachePath',
'cacheList',
'cacheClear',
'parallel',
'group',
'ciBuildId'
)

if (opts.exit) {
opts = _.omit(opts, 'exit')
Expand All @@ -86,16 +113,23 @@ const parseOpts = (opts) => {
}

const descriptions = {
record: 'records the run. sends test results, screenshots and videos to your Cypress Dashboard.',
key: 'your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable.',
record:
'records the run. sends test results, screenshots and videos to your Cypress Dashboard.',
key:
'your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable.',
spec: 'runs a specific spec file. defaults to "all"',
reporter: 'runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"',
reporter:
'runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"',
reporterOptions: 'options for the mocha reporter. defaults to "null"',
port: 'runs Cypress on a specific port. overrides any value in cypress.json.',
env: 'sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json',
config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.',
browserRunMode: 'runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path.',
browserOpenMode: 'path to a custom browser to be added to the list of available browsers in Cypress',
env:
'sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json',
config:
'sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.',
browserRunMode:
'runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path.',
browserOpenMode:
'path to a custom browser to be added to the list of available browsers in Cypress',
detached: 'runs Cypress application in detached mode',
project: 'path to the project',
global: 'force Cypress into global mode as if its globally installed',
Expand All @@ -108,11 +142,25 @@ const descriptions = {
cacheList: 'list cached binary versions',
cacheClear: 'delete all cached binaries',
group: 'a named group for recorded runs in the Cypress dashboard',
parallel: 'enables concurrent runs and automatic load balancing of specs across multiple machines or processes',
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',
parallel:
'enables concurrent runs and automatic load balancing of specs across multiple machines or processes',
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',
}

const knownCommands = ['version', 'run', 'open', 'install', 'verify', '-v', '--version', 'help', '-h', '--help', 'cache']
const knownCommands = [
'version',
'run',
'open',
'install',
'verify',
'-v',
'--version',
'help',
'-h',
'--help',
'cache',
]

const text = (description) => {
if (!descriptions[description]) {
Expand All @@ -123,9 +171,11 @@ const text = (description) => {
}

function includesVersion (args) {
return _.includes(args, 'version') ||
return (
_.includes(args, 'version') ||
_.includes(args, '--version') ||
_.includes(args, '-v')
)
}

function showVersions () {
Expand All @@ -147,6 +197,14 @@ module.exports = {
args = process.argv
}

if (!util.isValidCypressEnvValue(process.env.CYPRESS_ENV)) {
debug('invalid CYPRESS_ENV value', process.env.CYPRESS_ENV)

return errors.exitWithError(errors.errors.invalidCypressEnv)(
`CYPRESS_ENV=${process.env.CYPRESS_ENV}`
)
}

const program = new commander.Command()

// bug in commaner not printing name
Expand Down Expand Up @@ -177,7 +235,10 @@ module.exports = {
.option('-k, --key <record-key>', text('key'))
.option('-s, --spec <spec>', text('spec'))
.option('-r, --reporter <reporter>', text('reporter'))
.option('-o, --reporter-options <reporter-options>', text('reporterOptions'))
.option(
'-o, --reporter-options <reporter-options>',
text('reporterOptions')
)
.option('-p, --port <port>', text('port'))
.option('-e, --env <env>', text('env'))
.option('-c, --config <config>', text('config'))
Expand Down Expand Up @@ -218,7 +279,9 @@ module.exports = {
program
.command('install')
.usage('[options]')
.description('Installs the Cypress executable matching this package\'s version')
.description(
'Installs the Cypress executable matching this package\'s version'
)
.option('-f, --force', text('forceInstall'))
.action((opts) => {
require('./tasks/install')
Expand All @@ -229,7 +292,9 @@ module.exports = {
program
.command('verify')
.usage('[options]')
.description('Verifies that Cypress is installed correctly and executable')
.description(
'Verifies that Cypress is installed correctly and executable'
)
.option('--dev', text('dev'), coerceFalse)
.action((opts) => {
const defaultOpts = { force: true, welcomeMessage: false }
Expand Down
Loading

0 comments on commit 333a0ef

Please sign in to comment.