Skip to content

Commit

Permalink
Drop dependency on deprecated gulp-util (#41)
Browse files Browse the repository at this point in the history
Closes #40
  • Loading branch information
demurgos authored and sindresorhus committed Dec 31, 2017
1 parent 4db5871 commit 38b9e67
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
9 changes: 6 additions & 3 deletions index.js
@@ -1,6 +1,6 @@
'use strict';
const path = require('path');
const gutil = require('gulp-util');
const fancyLog = require('fancy-log');
const through = require('through2');
const tildify = require('tildify');
const stringifyObject = require('stringify-object');
Expand Down Expand Up @@ -36,13 +36,16 @@ module.exports = opts => {

const output = opts.minimal ? prop(path.relative(process.cwd(), file.path)) : full;

gutil.log(opts.title + ' ' + output);
module.exports._log(opts.title + ' ' + output);
}

count++;
cb(null, file);
}, cb => {
gutil.log(opts.title + ' ' + chalk.green(count + ' ' + plur('item', count)));
module.exports._log(opts.title + ' ' + chalk.green(count + ' ' + plur('item', count)));
cb();
});
};

// Internal: Log function used by gulp-debug exposed for testing.
module.exports._log = fancyLog;
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -32,7 +32,7 @@
],
"dependencies": {
"chalk": "^1.0.0",
"gulp-util": "^3.0.0",
"fancy-log": "^1.3.2",
"plur": "^2.0.0",
"stringify-object": "^3.0.0",
"through2": "^2.0.0",
Expand All @@ -42,9 +42,9 @@
"ava": "*",
"gulp": "^3.8.10",
"p-event": "^1.0.0",
"proxyquire": "^1.0.1",
"sinon": "^2.1.0",
"strip-ansi": "^3.0.0",
"vinyl": "^2.1.0",
"xo": "*"
},
"ava": {
Expand Down
34 changes: 12 additions & 22 deletions test.js
Expand Up @@ -2,29 +2,19 @@ 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 Vinyl from 'vinyl';
import stripAnsi from 'strip-ansi';
import pEvent from 'p-event';
import debug from '.';

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
});
const sandbox = sinon.sandbox.create();

let file;

test.beforeEach(() => {
sinon.spy(gutilStub, 'log');
sandbox.spy(debug, '_log');

file = new gutil.File({
file = new Vinyl({
cwd: __dirname,
base: __dirname,
path: path.join(__dirname, 'foo.js'),
Expand All @@ -34,7 +24,7 @@ test.beforeEach(() => {
});

test.afterEach(() => {
gutilStub.log.restore();
sandbox.restore();
});

test('output debug info', async t => {
Expand All @@ -43,7 +33,7 @@ test('output debug info', async t => {
stream.end(file);
await finish;

t.is(stripAnsi(gutilStub.log.firstCall.args[0]).split('\n')[0], 'unicorn: foo.js');
t.is(stripAnsi(debug._log.firstCall.args[0]).split('\n')[0], 'unicorn: foo.js');
});

test('output singular item count', async t => {
Expand All @@ -52,7 +42,7 @@ test('output singular item count', async t => {
stream.end(file);
await finish;

t.is(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item');
t.is(stripAnsi(debug._log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item');
});

test('output zero item count', async t => {
Expand All @@ -61,7 +51,7 @@ test('output zero item count', async t => {
stream.end();
await finish;

t.is(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 0 items');
t.is(stripAnsi(debug._log.lastCall.args[0]).split('\n')[0], 'unicorn: 0 items');
});

test('output plural item count', async t => {
Expand All @@ -74,7 +64,7 @@ test('output plural item count', async t => {

await finish;

t.is(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 2 items');
t.is(stripAnsi(debug._log.lastCall.args[0]).split('\n')[0], 'unicorn: 2 items');
});

test('not output file names when `showFiles` is false.', async t => {
Expand All @@ -85,11 +75,11 @@ test('not output file names when `showFiles` is false.', async t => {
const finish = pEvent(stream, 'finish');

stream.write(file, () => {
t.true(gutilStub.log.notCalled);
t.true(debug._log.notCalled);
stream.end();
});

await finish;

t.is(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item');
t.is(stripAnsi(debug._log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item');
});

0 comments on commit 38b9e67

Please sign in to comment.