Files
cypress/packages/server/test/unit/errors_spec.js
Jennifer Shehane 480d7d9cf7 chore: remove dead code from errors.ts in packages/errors (#31536)
* chore: remove 'not logged in' error - which is dead code

* Remove function getMsgByType which is no longer called in code

* remove errors around 'private test' plans

* Remove snapshots

* update system test snapshot
2025-04-17 18:49:58 -04:00

67 lines
1.8 KiB
JavaScript

/* eslint-disable no-console */
require('../spec_helper')
const exception = require(`../../lib/cloud/exception`)
const chalk = require('chalk')
const errors = require('../../lib/errors')
context('.logException', () => {
beforeEach(() => {
sinon.stub(console, 'log')
})
it('calls exception.create with unknown error', () => {
sinon.stub(exception, 'create').resolves()
sinon.stub(process.env, 'CYPRESS_INTERNAL_ENV').value('production')
const err = new Error('foo')
return errors.logException(err)
.then(() => {
expect(console.log).to.be.calledWith(chalk.red(err.stack ?? ''))
expect(exception.create).to.be.calledWith(err)
})
})
it('does not call exception.create when known error', () => {
sinon.stub(exception, 'create').resolves()
sinon.stub(process.env, 'CYPRESS_INTERNAL_ENV').value('production')
const err = errors.get('TESTS_DID_NOT_START_FAILED')
return errors.logException(err)
.then(() => {
expect(console.log).not.to.be.calledWith(err.stack)
expect(exception.create).not.to.be.called
})
})
it('does not call exception.create when not in production env', () => {
sinon.stub(exception, 'create').resolves()
sinon.stub(process.env, 'CYPRESS_INTERNAL_ENV').value('development')
const err = new Error('foo')
return errors.logException(err)
.then(() => {
expect(console.log).not.to.be.calledWith(err.stack)
expect(exception.create).not.to.be.called
})
})
it('swallows creating exception errors', () => {
sinon.stub(exception, 'create').rejects(new Error('foo'))
sinon.stub(process.env, 'CYPRESS_INTERNAL_ENV').value('production')
const err = errors.get('TESTS_DID_NOT_START_FAILED')
return errors.logException(err)
.then((ret) => {
expect(ret).to.be.undefined
})
})
})