|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const {validatePlugin, list} = require('../../../lib/cli/run-helpers'); |
4 | | -const {createSandbox} = require('sinon'); |
5 | 4 |
|
6 | | -describe('cli "run" command', function() { |
7 | | - let sandbox; |
| 5 | +describe('run helper functions', function() { |
| 6 | + describe('validatePlugin()', function() { |
| 7 | + describe('when used with "reporter" key', function() { |
| 8 | + it('should disallow an array of names', function() { |
| 9 | + expect( |
| 10 | + () => validatePlugin({reporter: ['bar']}, 'reporter'), |
| 11 | + 'to throw', |
| 12 | + { |
| 13 | + code: 'ERR_MOCHA_INVALID_REPORTER', |
| 14 | + message: /can only be specified once/i |
| 15 | + } |
| 16 | + ); |
| 17 | + }); |
8 | 18 |
|
9 | | - beforeEach(function() { |
10 | | - sandbox = createSandbox(); |
11 | | - }); |
| 19 | + it('should fail to recognize an unknown reporter', function() { |
| 20 | + expect( |
| 21 | + () => validatePlugin({reporter: 'bar'}, 'reporter'), |
| 22 | + 'to throw', |
| 23 | + {code: 'ERR_MOCHA_INVALID_REPORTER', message: /cannot find module/i} |
| 24 | + ); |
| 25 | + }); |
| 26 | + }); |
12 | 27 |
|
13 | | - afterEach(function() { |
14 | | - sandbox.restore(); |
15 | | - }); |
| 28 | + describe('when used with an "interfaces" key', function() { |
| 29 | + it('should disallow an array of names', function() { |
| 30 | + expect( |
| 31 | + () => validatePlugin({interface: ['bar']}, 'interface'), |
| 32 | + 'to throw', |
| 33 | + { |
| 34 | + code: 'ERR_MOCHA_INVALID_INTERFACE', |
| 35 | + message: /can only be specified once/i |
| 36 | + } |
| 37 | + ); |
| 38 | + }); |
16 | 39 |
|
17 | | - describe('helpers', function() { |
18 | | - describe('validatePlugin()', function() { |
19 | | - it('should disallow an array of module names', function() { |
| 40 | + it('should fail to recognize an unknown interface', function() { |
20 | 41 | expect( |
21 | | - () => validatePlugin({foo: ['bar']}, 'foo'), |
22 | | - 'to throw a', |
23 | | - TypeError |
| 42 | + () => validatePlugin({interface: 'bar'}, 'interface'), |
| 43 | + 'to throw', |
| 44 | + {code: 'ERR_MOCHA_INVALID_INTERFACE', message: /cannot find module/i} |
24 | 45 | ); |
25 | 46 | }); |
26 | 47 | }); |
27 | 48 |
|
28 | | - describe('list()', function() { |
29 | | - describe('when provided a flat array', function() { |
30 | | - it('should return a flat array', function() { |
31 | | - expect(list(['foo', 'bar']), 'to equal', ['foo', 'bar']); |
32 | | - }); |
33 | | - }); |
34 | | - describe('when provided a nested array', function() { |
35 | | - it('should return a flat array', function() { |
36 | | - expect(list([['foo', 'bar'], 'baz']), 'to equal', [ |
37 | | - 'foo', |
38 | | - 'bar', |
39 | | - 'baz' |
40 | | - ]); |
41 | | - }); |
42 | | - }); |
43 | | - describe('when given a comma-delimited string', function() { |
44 | | - it('should return a flat array', function() { |
45 | | - expect(list('foo,bar'), 'to equal', ['foo', 'bar']); |
46 | | - }); |
| 49 | + describe('when used with an unknown plugin type', function() { |
| 50 | + it('should fail', function() { |
| 51 | + expect( |
| 52 | + () => validatePlugin({frog: 'bar'}, 'frog'), |
| 53 | + 'to throw', |
| 54 | + /unknown plugin/i |
| 55 | + ); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('when a plugin throws an exception upon load', function() { |
| 60 | + it('should fail and report the original error', function() { |
| 61 | + expect( |
| 62 | + () => |
| 63 | + validatePlugin( |
| 64 | + { |
| 65 | + reporter: require.resolve('./fixtures/bad-module.fixture.js') |
| 66 | + }, |
| 67 | + 'reporter' |
| 68 | + ), |
| 69 | + 'to throw', |
| 70 | + {message: /wonky/, code: 'ERR_MOCHA_INVALID_REPORTER'} |
| 71 | + ); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + describe('list()', function() { |
| 77 | + describe('when provided a flat array', function() { |
| 78 | + it('should return a flat array', function() { |
| 79 | + expect(list(['foo', 'bar']), 'to equal', ['foo', 'bar']); |
| 80 | + }); |
| 81 | + }); |
| 82 | + describe('when provided a nested array', function() { |
| 83 | + it('should return a flat array', function() { |
| 84 | + expect(list([['foo', 'bar'], 'baz']), 'to equal', [ |
| 85 | + 'foo', |
| 86 | + 'bar', |
| 87 | + 'baz' |
| 88 | + ]); |
| 89 | + }); |
| 90 | + }); |
| 91 | + describe('when given a comma-delimited string', function() { |
| 92 | + it('should return a flat array', function() { |
| 93 | + expect(list('foo,bar'), 'to equal', ['foo', 'bar']); |
47 | 94 | }); |
48 | 95 | }); |
49 | 96 | }); |
|
0 commit comments