mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-03 21:40:28 -05:00
3481d1acaf
* migrate cli scripts to TypeScript * convert all javascript source files in the CLI to TypeScript rebase into first * chore: refactor all tests to TypeScript rebase into second * add npmignore for cli for typescript files * update build process * fix publically available exports * Fix cy-in-cy tests * add ts-expect-error to failing files * fix projectConfigIpc failures as there are now multiple installs of tsx * fix after-pack hook * fix binary script * chore: update publish binary to account for CLI being an ESModule compiled down to CommonJS * does this work? * fix the verify spec by making the listr2 renderer silent as it behaves differently since the refactor and is printing non deterministic outputs into our tests that do not have a large impact on the area we are testing and mostly served to actually test the renders of the listr2 framework itself * empty commit * additional refactor to code to remove strange any typing and exporting * bump cache and build binaries * fix CLI exports to keep backwards compatibility * fix unit-tests * turn on mac jobs * fix group name rename in CLI * remove babel deps from cli and explicitly install typescript * address feedback from code review * dont just falsy check results and instead explicitly check for null or undefined * add ts-expect-error * additional pass on cleaning up dynamic require / import from global lib references * annotate ts-expect-errors with reason for why error is expected * add rest of ts-expect-error comments * removing hardcoded branch to publish binary chore/migrate_cli_to_typescript
247 lines
7.5 KiB
TypeScript
247 lines
7.5 KiB
TypeScript
import '../../spec_helper'
|
|
import os from 'os'
|
|
import snapshot from '../../support/snapshot'
|
|
import util from '../../../lib/util'
|
|
import run from '../../../lib/exec/run'
|
|
import spawn from '../../../lib/exec/spawn'
|
|
import verify from '../../../lib/tasks/verify'
|
|
|
|
describe('exec run', function () {
|
|
beforeEach(function () {
|
|
sinon.stub(util, 'isInstalledGlobally').returns(true)
|
|
sinon.stub(process, 'exit')
|
|
})
|
|
|
|
context('.processRunOptions', function () {
|
|
it('allows string --project option', () => {
|
|
const args = run.processRunOptions({
|
|
project: '/path/to/project',
|
|
})
|
|
|
|
expect(args).to.deep.equal(['--run-project', '/path/to/project'])
|
|
})
|
|
|
|
it('throws an error for empty string --project', () => {
|
|
expect(() => run.processRunOptions({ project: '' })).to.throw()
|
|
})
|
|
|
|
it('throws an error for boolean --project', () => {
|
|
expect(() => run.processRunOptions({ project: false })).to.throw()
|
|
expect(() => run.processRunOptions({ project: true })).to.throw()
|
|
})
|
|
|
|
it('throws an error for --project "false" or "true"', () => {
|
|
expect(() => run.processRunOptions({ project: 'false' })).to.throw()
|
|
expect(() => run.processRunOptions({ project: 'true' })).to.throw()
|
|
})
|
|
|
|
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('does not allow setting paradoxical --headed and --headless flags', () => {
|
|
(os.platform as any).returns('linux')
|
|
|
|
;(process.exit as any).returns()
|
|
|
|
expect(() => run.processRunOptions({ headed: true, headless: true })).to.throw()
|
|
})
|
|
|
|
it('passes --headed according to --headless', () => {
|
|
expect(run.processRunOptions({ headless: true })).to.deep.eq([
|
|
'--run-project', undefined, '--headed', 'false',
|
|
])
|
|
})
|
|
|
|
it('does not remove --record option when using --browser', () => {
|
|
const args = run.processRunOptions({
|
|
record: 'foo',
|
|
browser: 'test browser',
|
|
})
|
|
|
|
snapshot(args)
|
|
})
|
|
|
|
it('defaults to e2e testingType', () => {
|
|
const args = run.processRunOptions()
|
|
|
|
snapshot(args)
|
|
})
|
|
|
|
it('passes e2e testingType', () => {
|
|
expect(run.processRunOptions({ testingType: 'e2e' })).to.deep.eq([
|
|
'--run-project', undefined, '--testing-type', 'e2e',
|
|
])
|
|
})
|
|
|
|
it('passes component testingType', () => {
|
|
expect(run.processRunOptions({ testingType: 'component' })).to.deep.eq([
|
|
'--run-project', undefined, '--testing-type', 'component',
|
|
])
|
|
})
|
|
|
|
it('throws if testingType is invalid', () => {
|
|
expect(() => run.processRunOptions({ testingType: 'randomTestingType' })).to.throw()
|
|
})
|
|
|
|
it('throws if both e2e and component are set', () => {
|
|
expect(() => run.processRunOptions({ e2e: true, component: true })).to.throw()
|
|
})
|
|
|
|
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 () {
|
|
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 set', function () {
|
|
return run.start({ configFile: 'special-cypress.config.js' })
|
|
.then(() => {
|
|
expect(spawn.start).to.be.calledWith(
|
|
['--run-project', process.cwd(), '--config-file', 'special-cypress.config.js'],
|
|
)
|
|
})
|
|
})
|
|
|
|
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 --testing-type e2e when given --e2e', function () {
|
|
return run.start({ e2e: true })
|
|
.then(() => {
|
|
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--testing-type', 'e2e'])
|
|
})
|
|
})
|
|
|
|
it('spawns with --testing-type component when given --component', function () {
|
|
return run.start({ component: true })
|
|
.then(() => {
|
|
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--testing-type', 'component'])
|
|
})
|
|
})
|
|
|
|
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',
|
|
])
|
|
})
|
|
})
|
|
|
|
it('spawns with --auto-cancel-after-failures value', function () {
|
|
return run.start({ autoCancelAfterFailures: 4 })
|
|
.then(() => {
|
|
expect(spawn.start).to.be.calledWith([
|
|
'--run-project', process.cwd(), '--auto-cancel-after-failures', 4,
|
|
])
|
|
})
|
|
})
|
|
|
|
it('spawns with --auto-cancel-after-failures value false', function () {
|
|
return run.start({ autoCancelAfterFailures: false })
|
|
.then(() => {
|
|
expect(spawn.start).to.be.calledWith([
|
|
'--run-project', process.cwd(), '--auto-cancel-after-failures', false,
|
|
])
|
|
})
|
|
})
|
|
|
|
it('spawns with --runner-ui', function () {
|
|
return run.start({ runnerUi: true })
|
|
.then(() => {
|
|
expect(spawn.start).to.be.calledWith([
|
|
'--run-project', process.cwd(), '--runner-ui', true,
|
|
])
|
|
})
|
|
})
|
|
})
|
|
})
|