-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtest.js
95 lines (75 loc) · 2.26 KB
/
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
86
87
88
89
90
91
92
93
94
95
import fs from 'fs';
import path from 'path';
import test from 'ava';
import sinon from 'sinon';
import gutil from 'gulp-util';
import proxyquire from 'proxyquire';
import stripAnsi from 'strip-ansi';
import pEvent from 'p-event';
const gutilStub = {
log() {
// Uncomment the next line to see the log messages written by `gulp-debug` during test
// (by default they are swallowed by the sinon stub replacing the log method)
// gutil.log.apply(gutil.log, arguments);
}
};
const debug = proxyquire('.', {
'gulp-util': gutilStub
});
let file;
test.beforeEach(() => {
sinon.spy(gutilStub, 'log');
file = new gutil.File({
cwd: __dirname,
base: __dirname,
path: path.join(__dirname, 'foo.js'),
stat: fs.statSync('test.js'),
contents: Buffer.from('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
});
});
test.afterEach(() => {
gutilStub.log.restore();
});
test('output debug info', async t => {
const stream = debug({title: 'unicorn:'});
const finish = pEvent(stream, 'finish');
stream.end(file);
await finish;
t.is(stripAnsi(gutilStub.log.firstCall.args[0]).split('\n')[0], 'unicorn: foo.js');
});
test('output singular item count', async t => {
const stream = debug({title: 'unicorn:'});
const finish = pEvent(stream, 'finish');
stream.end(file);
await finish;
t.is(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item');
});
test('output zero item count', async t => {
const stream = debug({title: 'unicorn:'});
const finish = pEvent(stream, 'finish');
stream.end();
await finish;
t.is(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 0 items');
});
test('output plural item count', async t => {
const stream = debug({title: 'unicorn:'});
const finish = pEvent(stream, 'finish');
stream.write(file, () => {
stream.end(file);
});
await finish;
t.is(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 2 items');
});
test('not output file names when `showFiles` is false.', async t => {
const stream = debug({
title: 'unicorn:',
showFiles: false
});
const finish = pEvent(stream, 'finish');
stream.write(file, () => {
t.true(gutilStub.log.notCalled);
stream.end();
});
await finish;
t.is(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item');
});