-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
run-helpers.spec.js
121 lines (111 loc) · 3.76 KB
/
run-helpers.spec.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
const {validateLegacyPlugin, list} = require('../../../lib/cli/run-helpers');
const Mocha = require('../../../lib/mocha');
describe('helpers', function () {
describe('validateLegacyPlugin()', function () {
describe('when used with "reporter" key', function () {
it('should disallow an array of names', function () {
expect(
() => validateLegacyPlugin({reporter: ['bar']}, 'reporter'),
'to throw',
{
code: 'ERR_MOCHA_INVALID_REPORTER',
message: /can only be specified once/i
}
);
});
it('should fail to recognize an unknown reporter', function () {
expect(
() => validateLegacyPlugin({reporter: 'bar'}, 'reporter'),
'to throw',
{code: 'ERR_MOCHA_INVALID_REPORTER', message: /cannot find module/i}
);
});
});
describe('when used with an "ui" key', function () {
it('should disallow an array of names', function () {
expect(() => validateLegacyPlugin({ui: ['bar']}, 'ui'), 'to throw', {
code: 'ERR_MOCHA_INVALID_INTERFACE',
message: /can only be specified once/i
});
});
it('should fail to recognize an unknown interface', function () {
expect(() => validateLegacyPlugin({ui: 'bar'}, 'ui'), 'to throw', {
code: 'ERR_MOCHA_INVALID_INTERFACE',
message: /cannot find module/i
});
});
});
describe('when used with an unknown plugin type', function () {
it('should fail', function () {
expect(
() => validateLegacyPlugin({frog: 'bar'}, 'frog'),
'to throw',
/unknown plugin/i
);
});
});
describe('when used with a third-party interface', function () {
it('should add the interface to "Mocha.interfaces"', function () {
// let's suppose that `glob` is an interface
const opts = {ui: 'glob'};
validateLegacyPlugin(opts, 'ui', Mocha.interfaces);
expect(opts.ui, 'to equal', 'glob');
expect(Mocha.interfaces, 'to satisfy', {glob: require('glob')});
delete Mocha.interfaces.glob;
});
});
describe('when a plugin throws an exception upon load', function () {
it('should fail and report the original error', function () {
expect(
() =>
validateLegacyPlugin(
{
reporter: require.resolve('./fixtures/bad-module.fixture.js')
},
'reporter'
),
'to throw',
{message: /wonky/, code: 'ERR_MOCHA_INVALID_REPORTER'}
);
});
it('should fail and report the original "MODULE_NOT_FOUND" error.message', function () {
expect(
() =>
validateLegacyPlugin(
{
reporter: require.resolve('./fixtures/bad-require.fixture.js')
},
'reporter'
),
'to throw',
{
message: /Error: Cannot find module 'fake'/,
code: 'ERR_MOCHA_INVALID_REPORTER'
}
);
});
});
});
describe('list()', function () {
describe('when provided a flat array', function () {
it('should return a flat array', function () {
expect(list(['foo', 'bar']), 'to equal', ['foo', 'bar']);
});
});
describe('when provided a nested array', function () {
it('should return a flat array', function () {
expect(list([['foo', 'bar'], 'baz']), 'to equal', [
'foo',
'bar',
'baz'
]);
});
});
describe('when given a comma-delimited string', function () {
it('should return a flat array', function () {
expect(list('foo,bar'), 'to equal', ['foo', 'bar']);
});
});
});
});