forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_spec.js
More file actions
66 lines (49 loc) · 1.78 KB
/
errors_spec.js
File metadata and controls
66 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* 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('NOT_LOGGED_IN')
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('NOT_LOGGED_IN')
return errors.logException(err)
.then((ret) => {
expect(ret).to.be.undefined
})
})
})