Files
cypress/cli/test/lib/errors_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

91 lines
2.4 KiB
TypeScript

import '../spec_helper'
import os from 'os'
import snapshot from '../support/snapshot'
import util from '../../lib/util'
import { errors, getError, formErrorText } from '../../lib/errors'
describe('errors', function () {
const { missingXvfb } = errors
beforeEach(function (): void {
sinon.stub(util, 'pkgVersion').returns('1.2.3')
;(os.platform as any).returns('test platform')
})
describe('individual', () => {
it('has the following errors', () => {
return snapshot(Object.keys(errors).sort())
})
})
context('getError', () => {
it('forms full message and creates Error object', () => {
const errObject = errors.childProcessKilled('exit', 'SIGKILL')
snapshot('child kill error object', errObject)
return getError(errObject).then((e: any) => {
expect(e).to.be.an('Error')
expect(e).to.have.property('known', true)
snapshot('Error message', e.message)
})
})
})
context('.errors.formErrorText', function () {
it('returns fully formed text message', () => {
expect(missingXvfb).to.be.an('object')
return formErrorText(missingXvfb)
.then((text: string) => {
expect(text).to.be.a('string')
snapshot(text)
})
})
it('calls solution if a function', () => {
const solution = sinon.stub().returns('a solution')
const error = {
description: 'description',
solution,
}
return formErrorText(error)
.then((text: string) => {
snapshot(text)
expect(solution).to.have.been.calledOnce
})
})
it('passes message and previous message', () => {
const solution = sinon.stub().returns('a solution')
const error = {
description: 'description',
solution,
}
return formErrorText(error, 'msg', 'prevMsg')
.then(() => {
expect(solution).to.have.been.calledWithExactly('msg', 'prevMsg')
})
})
it('expects solution to be a string', () => {
const error = {
description: 'description',
solution: 42,
}
return expect(formErrorText(error)).to.be.rejected
})
it('forms full text for invalid display error', () => {
return formErrorText(errors.invalidSmokeTestDisplayError, 'current message', 'prev message')
.then((text: string) => {
snapshot('invalid display error', text)
})
})
})
})