Skip to content

Commit

Permalink
New: Add config flags.logLevel (closes #110) (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk authored and phated committed Dec 21, 2017
1 parent 4c49f4a commit 7f0b050
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 6 deletions.
7 changes: 1 addition & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# http://www.appveyor.com/docs/appveyor-yml
# http://www.appveyor.com/docs/lang/nodejs-iojs

branches:
# whitelist
only:
- master

environment:
matrix:
# node.js
Expand All @@ -15,7 +10,7 @@ environment:
- nodejs_version: "6"

install:
- npm -g install npm@latest
- npm -g install npm@2
- set PATH=%APPDATA%\npm;%PATH%
- ps: Install-Product node $env:nodejs_version
- npm install
Expand Down
1 change: 1 addition & 0 deletions lib/shared/config/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var copyProps = require('copy-props');
var fromTo = {
'flags.silent': 'silent',
'flags.continue': 'continue',
'flags.logLevel': 'logLevel',
};

function mergeConfigToCliFlags(opt, config) {
Expand Down
188 changes: 188 additions & 0 deletions test/config-flags-log-level.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
'use strict';

var expect = require('expect');
var path = require('path');
var eraseTime = require('gulp-test-tools').eraseTime;
var runner = require('gulp-test-tools').gulpRunner;

describe('config: flag.logLevel', function() {

describe('log level 3 by default', function() {
it('Should output error log', function(done) {
runner({ verbose: false })
.gulp('--gulpfile x')
.run(function(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(stdout).toEqual('');
expect(eraseTime(stderr)).toEqual('No gulpfile found\n');
done();
});
});

it('Should output warn log', function(done) {
var packageJsonPath = path.resolve(__dirname, 'fixtures/packages',
'invalid-package.json');

runner({ verbose: false })
.gulp('--verify', packageJsonPath)
.run(function(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(eraseTime(stdout)).toEqual(
'Verifying plugins in ' + packageJsonPath + '\n' +
'Blacklisted plugins found in this project:\n' +
'gulp-blink: deprecated. use \`blink` instead.\n');
expect(stderr).toEqual('');
done();
});
});

it('Should output info log', function(done) {
var packageJsonPath = path.resolve(__dirname, 'fixtures/packages',
'valid-package.json');

runner({ verbose: false })
.gulp('--verify', packageJsonPath)
.run(function(err, stdout, stderr) {
expect(err).toEqual(null);
expect(eraseTime(stdout)).toEqual(
'Verifying plugins in ' + packageJsonPath + '\n' +
'There are no blacklisted plugins in this project\n');
expect(stderr).toEqual('');
done(err);
});
});
});

describe('log level 1 by config `flags.logLevel`', function() {
var gulp = runner({ verbose: false })
.basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L'))
.gulp;

it('Should output error log', function(done) {
gulp('--gulpfile x')
.run(function(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(stdout).toEqual('');
expect(eraseTime(stderr)).toEqual('No gulpfile found\n');
done();
});
});

it('Should output warn log', function(done) {
var packageJsonPath = path.resolve(__dirname, 'fixtures/packages',
'invalid-package.json');

gulp('--verify', packageJsonPath)
.run(function(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(stdout).toEqual('');
expect(stderr).toEqual('');
done();
});
});

it('Should output info log', function(done) {
var packageJsonPath = path.resolve(__dirname, 'fixtures/packages',
'valid-package.json');

gulp('--verify', packageJsonPath)
.run(function(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stdout).toEqual('');
expect(stderr).toEqual('');
done(err);
});
});
});

describe('log level 2 by config `flags.logLevel`', function() {
var gulp = runner({ verbose: false })
.basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LL'))
.gulp;

it('Should output error log', function(done) {
gulp('--gulpfile x')
.run(function(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(stdout).toEqual('');
expect(eraseTime(stderr)).toEqual('No gulpfile found\n');
done();
});
});

it('Should output warn log', function(done) {
var packageJsonPath = path.resolve(__dirname, 'fixtures/packages',
'invalid-package.json');

gulp('--verify', packageJsonPath)
.run(function(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(eraseTime(stdout)).toEqual(
'Blacklisted plugins found in this project:\n' +
'gulp-blink: deprecated. use \`blink` instead.\n');
expect(stderr).toEqual('');
done();
});
});

it('Should output info log', function(done) {
var packageJsonPath = path.resolve(__dirname, 'fixtures/packages',
'valid-package.json');

gulp('--verify', packageJsonPath)
.run(function(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stdout).toEqual('');
expect(stderr).toEqual('');
done(err);
});
});
});

describe('log level 3 by config `flags.logLevel`', function() {
var gulp = runner({ verbose: false })
.basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL'))
.gulp;

it('Should output error log', function(done) {
gulp('--gulpfile x')
.run(function(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(stdout).toEqual('');
expect(eraseTime(stderr)).toEqual('No gulpfile found\n');
done();
});
});

it('Should output warn log', function(done) {
var packageJsonPath = path.resolve(__dirname, 'fixtures/packages',
'invalid-package.json');

gulp('--verify', packageJsonPath)
.run(function(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(eraseTime(stdout)).toEqual(
'Verifying plugins in ' + packageJsonPath + '\n' +
'Blacklisted plugins found in this project:\n' +
'gulp-blink: deprecated. use \`blink` instead.\n');
expect(stderr).toEqual('');
done();
});
});

it('Should output info log', function(done) {
var packageJsonPath = path.resolve(__dirname, 'fixtures/packages',
'valid-package.json');

gulp('--verify', packageJsonPath)
.run(function(err, stdout, stderr) {
expect(err).toEqual(null);
expect(eraseTime(stdout)).toEqual(
'Verifying plugins in ' + packageJsonPath + '\n' +
'There are no blacklisted plugins in this project\n');
expect(stderr).toEqual('');
done(err);
});
});
});
});
5 changes: 5 additions & 0 deletions test/fixtures/config/flags/logLevel/L/.gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flags": {
"logLevel": 1
}
}
5 changes: 5 additions & 0 deletions test/fixtures/config/flags/logLevel/LL/.gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flags": {
"logLevel": 2
}
}
5 changes: 5 additions & 0 deletions test/fixtures/config/flags/logLevel/LLL/.gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flags": {
"logLevel": 3
}
}

0 comments on commit 7f0b050

Please sign in to comment.