Files
cypress/cli/test/lib/exec/open_spec.ts
Bill Glesias 3481d1acaf chore: refactor cypress/cli to TypeScript (#32063)
* 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
2025-09-02 17:52:45 -04:00

146 lines
4.3 KiB
TypeScript

import '../../spec_helper'
import util from '../../../lib/util'
import verify from '../../../lib/tasks/verify'
import spawn from '../../../lib/exec/spawn'
import open from '../../../lib/exec/open'
describe('exec open', function () {
context('.start', function () {
beforeEach(function (): void {
sinon.stub(util, 'isInstalledGlobally').returns(true)
sinon.stub(verify, 'start').resolves()
sinon.stub(spawn, 'start').resolves()
})
it('verifies download', function () {
return open.start()
.then(() => {
expect(verify.start).to.be.called
})
})
it('calls spawn with correct options', function () {
return open.start({ dev: true })
.then(() => {
expect(spawn.start).to.be.calledWith([], {
detached: false,
dev: true,
})
})
})
it('spawns with port', function () {
return open.start({ port: '1234' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--port', '1234'])
})
})
it('spawns with --env', function () {
return open.start({ env: 'host=http://localhost:1337,name=brian' })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--env', 'host=http://localhost:1337,name=brian'],
)
})
})
it('spawns with --config', function () {
return open.start({ config: 'watchForFileChanges=false,baseUrl=localhost' })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--config', 'watchForFileChanges=false,baseUrl=localhost'],
)
})
})
it('spawns with --config-file set', function () {
return open.start({ configFile: 'special-cypress.config.js' })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--config-file', 'special-cypress.config.js'],
)
})
})
it('spawns with cwd as --project if not installed globally', function () {
// @ts-expect-error - is shorthand stub on a function
util.isInstalledGlobally.returns(false)
return open.start()
.then(() => {
expect(spawn.start).to.be.calledWith(
['--project', process.cwd()],
)
})
})
it('spawns without --project if not installed globally and passing --global option', function () {
// @ts-expect-error - is shorthand stub on a function
util.isInstalledGlobally.returns(false)
return open.start({ global: true })
.then(() => {
expect(spawn.start).not.to.be.calledWith(
['--project', process.cwd()],
)
})
})
it('spawns with --project passed in as options even when not installed globally', function () {
// @ts-expect-error - is shorthand stub on a function
util.isInstalledGlobally.returns(false)
return open.start({ project: '/path/to/project' })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--project', '/path/to/project'],
)
})
})
it('spawns with --project if specified and installed globally', function () {
return open.start({ project: '/path/to/project' })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--project', '/path/to/project'],
)
})
})
it('spawns without --project if not specified and installed globally', function () {
return open.start()
.then(() => {
expect(spawn.start).to.be.calledWith([])
})
})
it('spawns without --testing-type when not specified', () => {
return open.start().then(() => {
expect(spawn.start).to.be.calledWith([])
})
})
it('spawns with --testing-type e2e', () => {
return open.start({ testingType: 'e2e' }).then(() => {
expect(spawn.start).to.be.calledWith(['--testing-type', 'e2e'])
})
})
it('spawns with --testing-type component', () => {
return open.start({ testingType: 'component' }).then(() => {
expect(spawn.start).to.be.calledWith(['--testing-type', 'component'])
})
})
it('throws if --testing-type is invalid', () => {
expect(() => open.processOpenOptions({ testingType: 'randomTestingType' })).to.throw()
})
it('throws if --config-file is false', () => {
expect(() => open.processOpenOptions({ configFile: 'false' })).to.throw()
})
})
})