This repository has been archived by the owner on May 15, 2024. It is now read-only.
forked from sindresorhus/gulp-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
85 lines (69 loc) · 2.03 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
'use strict';
var fs = require('fs');
var assert = require('assert');
var sinon = require('sinon');
var gutil = require('gulp-util');
var proxyquire = require('proxyquire');
var stripAnsi = require('strip-ansi');
var gutilStub = {
log: function () {
// 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);
}
};
var debug = proxyquire('./', {
'gulp-util': gutilStub
});
var file;
beforeEach(function () {
sinon.spy(gutilStub, 'log');
file = new gutil.File({
cwd: __dirname,
base: __dirname,
path: __dirname + '/foo.js',
stat: fs.statSync('test.js'),
contents: new Buffer('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
});
});
afterEach(function () {
gutilStub.log.restore();
});
it('should output debug info', function (cb) {
var stream = debug({title: 'unicorn:'});
stream.write(file, 'utf8', function () {
assert(gutilStub.log.calledOnce);
assert.strictEqual(stripAnsi(gutilStub.log.firstCall.args[0]).split('\n')[0], 'unicorn: foo.js');
cb();
});
});
it('should output singular item count', function (cb) {
var stream = debug({title: 'unicorn:'});
stream.on('finish', function () {
assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item');
cb();
});
stream.write(file, function () {
stream.end();
});
});
it('should output zero item count', function (cb) {
var stream = debug({title: 'unicorn:'});
stream.on('finish', function () {
assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 0 items');
cb();
});
stream.end();
});
it('should output plural item count', function (cb) {
var stream = debug({title: 'unicorn:'});
stream.on('finish', function () {
assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 2 items');
cb();
});
stream.write(file, function () {
stream.write(file, function () {
stream.end();
});
});
});