Files
cypress/cli/test/lib/exec/run_spec.js
Jennifer Shehane 692a3c07d9 Support --tag argument (#5164)
* Alphabetize cli options for my own sanity

* begin added tag flag

* Fix some minor grammar in cli help output + be more specific for specs description

* update snapshot based on alphabetization change

* update snapshot to include --tag in help output

* update logic for pulling out space delimited args to look through --tag and --spec flags dynamically

* Support and pass along tag flag to run and record

- show err if passed without record flag
- sanitize args into comma separated string
- display tag in record errors

* fix some tests/snapshots where 'tag' was missing

* Actually try passing in tag through tests to ensure it prints.

* Merge branch 'develop' into issue-2561-tags

# Conflicts:
#	cli/__snapshots__/cli_spec.js
#	cli/lib/cli.js
#	cli/lib/exec/run.js
#	packages/server/lib/modes/run.js
#	packages/server/lib/util/args.js

* Send 'tags' as an array to backend API

* Update json-schemas to query against 2.2.0 of postRun

- this will require a bump to json-schemas repo

* update test to reflect tags array

* update snapshot to display nightly tag

* rearrange args to alphabetical order in specs

* Add tags to runResponses / remove tag from incorrect instance post

* Fix failing specs / snapshots

* Update error messages + snapshots

* Fix snapshot that no longer displays tag arg

* fix args unit test

* remove extra slash

* add a few more cli tests

* another test just in case

* a quick unit test for displayFlags utility


Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
2019-12-05 23:02:14 +06:30

154 lines
4.2 KiB
JavaScript

require('../../spec_helper')
const snapshot = require('../../support/snapshot')
const util = require(`${lib}/util`)
const run = require(`${lib}/exec/run`)
const spawn = require(`${lib}/exec/spawn`)
const verify = require(`${lib}/tasks/verify`)
describe('exec run', function () {
beforeEach(function () {
sinon.stub(util, 'isInstalledGlobally').returns(true)
sinon.stub(process, 'exit')
})
context('.processRunOptions', function () {
it('passes --browser option', () => {
const args = run.processRunOptions({
browser: 'test browser',
})
snapshot(args)
})
it('passes --record option', () => {
const args = run.processRunOptions({
record: 'my record id',
})
snapshot(args)
})
it('passes --config-file false option', () => {
const args = run.processRunOptions({
configFile: false,
})
snapshot(args)
})
it('does not remove --record option when using --browser', () => {
const args = run.processRunOptions({
record: 'foo',
browser: 'test browser',
})
snapshot(args)
})
})
context('.start', function () {
beforeEach(function () {
sinon.stub(spawn, 'start').resolves()
sinon.stub(verify, 'start').resolves()
})
it('verifies cypress', function () {
return run.start()
.then(() => {
expect(verify.start).to.be.calledOnce
})
})
it('spawns with --key and xvfb', function () {
return run.start({ port: '1234' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--port', '1234'])
})
})
it('spawns with --env', function () {
return run.start({ env: 'host=http://localhost:1337,name=brian' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--env', 'host=http://localhost:1337,name=brian'])
})
})
it('spawns with --config', function () {
return run.start({ config: 'watchForFileChanges=false,baseUrl=localhost' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--config', 'watchForFileChanges=false,baseUrl=localhost'])
})
})
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.json' })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--run-project', process.cwd(), '--config-file', 'special-cypress.json']
)
})
})
it('spawns with --record false', function () {
return run.start({ record: false })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--record', false])
})
})
it('spawns with --headed true', function () {
return run.start({ headed: true })
.then(() => {
expect(spawn.start).to.be.calledWith([
'--run-project', process.cwd(), '--headed', true,
])
})
})
it('spawns with --no-exit', function () {
return run.start({ exit: false })
.then(() => {
expect(spawn.start).to.be.calledWith([
'--run-project', process.cwd(), '--no-exit',
])
})
})
it('spawns with --output-path', function () {
return run.start({ outputPath: '/path/to/output' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--output-path', '/path/to/output'])
})
})
it('spawns with --tag value', function () {
return run.start({ tag: 'nightly' })
.then(() => {
expect(spawn.start).to.be.calledWith([
'--run-project', process.cwd(), '--tag', 'nightly',
])
})
})
it('spawns with several --tag words unchanged', function () {
return run.start({ tag: 'nightly, sanity' })
.then(() => {
expect(spawn.start).to.be.calledWith([
'--run-project', process.cwd(), '--tag', 'nightly, sanity',
])
})
})
})
})