-
Notifications
You must be signed in to change notification settings - Fork 58
/
resolve-spec.test.js
85 lines (62 loc) · 2.32 KB
/
resolve-spec.test.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
'use strict';
const fs = require('fs');
const proxyquire = require('proxyquire');
const { assert, sinon } = require('@sinonjs/referee-sinon');
describe('mochify/lib/resolve-spec', () => {
let resolveSpec;
let glob;
beforeEach(() => {
glob = sinon.fake();
({ resolveSpec } = proxyquire('./resolve-spec', { glob }));
});
it('resolves glob "test/**/*.js" for undefined', async () => {
const promise = resolveSpec(undefined);
const matches = ['test/this.js', 'test/that.js'];
assert.calledOnceWith(glob, 'test/**/*.js');
glob.callback(null, matches);
await assert.resolves(promise, matches);
});
it('invokes glob with given string pattern', () => {
const pattern = 'some/*.js';
resolveSpec(pattern);
assert.calledOnceWith(glob, pattern);
});
it('invokes glob concurrently with patterns from array', () => {
const patterns = ['a/*.js', 'b/*.js', 'c/*.js'];
resolveSpec(patterns);
assert.calledThrice(glob);
assert.calledWith(glob, patterns[0]);
assert.calledWith(glob, patterns[1]);
assert.calledWith(glob, patterns[2]);
});
it('resolves with the result from a single pattern', async () => {
const pattern = 'test/**/*.js';
const matches = ['test/this.js', 'test/that.js'];
const promise = resolveSpec(pattern);
glob.firstCall.callback(null, matches);
await assert.resolves(promise, matches);
});
it('resolves with the result from a pattern array', async () => {
const patterns = ['a/*.js', 'b/*.js'];
const matches_a = ['a/this.js', 'a/that.js'];
const matches_b = ['b/more.js'];
const promise = resolveSpec(patterns);
glob.firstCall.callback(null, matches_a);
glob.secondCall.callback(null, matches_b);
await assert.resolves(promise, matches_a.concat(matches_b));
});
it('rejects with error from glob', async () => {
const patterns = ['a/*.js', 'b/*.js'];
const matches_a = ['a/this.js', 'a/that.js'];
const error = new Error('Oh noes!');
const promise = resolveSpec(patterns);
glob.firstCall.callback(null, matches_a);
glob.secondCall.callback(error);
await assert.rejects(promise, error);
});
it('passes through streams', async () => {
const stream = fs.createReadStream(__filename);
const promise = resolveSpec(stream);
await assert.resolves(promise, stream);
});
});