Skip to content

Commit

Permalink
Build: Improve tests and raise coverage (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk authored and phated committed Apr 20, 2019
1 parent 12a022a commit 2d8a320
Show file tree
Hide file tree
Showing 34 changed files with 334 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
.DS_Store
*.log
node_modules
!test/fixtures/errors/bad-gulp-version/node_modules/
build
*.node
components
Expand Down
15 changes: 10 additions & 5 deletions index.js
Expand Up @@ -70,6 +70,7 @@ cli.on('requireFail', function(name, error) {
ansi.yellow('Failed to load external module'),
ansi.magenta(name)
);
/* istanbul ignore else */
if (error) {
log.warn(ansi.yellow(error.toString()));
}
Expand Down Expand Up @@ -122,20 +123,20 @@ function handleArguments(env) {

// Anything that needs to print outside of the logging mechanism should use console.log
if (opts.version) {
console.log('CLI version', cliVersion);
if (env.modulePackage && typeof env.modulePackage.version !== 'undefined') {
console.log('Local version', env.modulePackage.version);
}
console.log('CLI version:', cliVersion);
console.log('Local version:', env.modulePackage.version || 'Unknown');
exit(0);
}

if (opts.verify) {
var pkgPath = opts.verify !== true ? opts.verify : 'package.json';
/* istanbul ignore else */
if (path.resolve(pkgPath) !== path.normalize(pkgPath)) {
pkgPath = path.join(env.cwd, pkgPath);
}
log.info('Verifying plugins in ' + pkgPath);
return getBlacklist(function(err, blacklist) {
/* istanbul ignore if */
if (err) {
return logBlacklistError(err);
}
Expand All @@ -147,10 +148,12 @@ function handleArguments(env) {
}

if (!env.modulePath) {
/* istanbul ignore next */
var missingNodeModules =
fs.existsSync(path.join(env.cwd, 'package.json'))
&& !fs.existsSync(path.join(env.cwd, 'node_modules'));

/* istanbul ignore next */
var missingGulpMessage =
missingNodeModules
? 'Local modules not found in'
Expand All @@ -159,6 +162,7 @@ function handleArguments(env) {
ansi.red(missingGulpMessage),
ansi.magenta(tildify(env.cwd))
);
/* istanbul ignore next */
var installCommand =
missingNodeModules
? 'npm install'
Expand Down Expand Up @@ -186,9 +190,10 @@ function handleArguments(env) {
var range = findRange(env.modulePackage.version, ranges);

if (!range) {
return log.error(
log.error(
ansi.red('Unsupported gulp version', env.modulePackage.version)
);
exit(1);
}

// Load and execute the CLI version
Expand Down
2 changes: 2 additions & 0 deletions lib/shared/ansi.js
Expand Up @@ -5,6 +5,7 @@ var supportsColor = require('color-support');

var hasColors = colorize();

/* istanbul ignore next */
module.exports = {
red: hasColors ? colors.red : noColor,
green: hasColors ? colors.green : noColor,
Expand All @@ -31,6 +32,7 @@ function colorize() {
return false;
}

/* istanbul ignore if */
if (hasFlag('color')) {
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/shared/config/env-flags.js
Expand Up @@ -34,11 +34,10 @@ function mergeConfigToEnvFlags(env, config, cliOpts) {
return [].concat(envInfo.value, configInfo.value);
}

/* istanbul ignore else */
if (envInfo.keyChain === 'nodeFlags') {
return [].concat(configInfo.value || []);
}

return configInfo.value;
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/shared/exit.js
Expand Up @@ -2,6 +2,7 @@

// Fix stdout truncation on windows
function exit(code) {
/* istanbul ignore next */
if (process.platform === 'win32' && process.stdout.bufferSize) {
process.stdout.once('drain', function() {
process.exit(code);
Expand Down
4 changes: 4 additions & 0 deletions lib/shared/get-blacklist.js
Expand Up @@ -19,6 +19,7 @@ function parse(str, cb) {
try {
cb(null, JSON.parse(str));
} catch (err) {
/* istanbul ignore next */
cb(new Error('Invalid Blacklist JSON.'));
}
}
Expand All @@ -28,6 +29,7 @@ function getBlacklist(cb) {
https.get(url, onRequest);

function onRequest(res) {
/* istanbul ignore if */
if (res.statusCode !== 200) {
// TODO: Test different status codes
return cb(new Error('Request failed. Status Code: ' + res.statusCode));
Expand All @@ -39,6 +41,7 @@ function getBlacklist(cb) {
}

function onCollect(err, result) {
/* istanbul ignore if */
if (err) {
return cb(err);
}
Expand All @@ -47,6 +50,7 @@ function getBlacklist(cb) {
}

function onParse(err, blacklist) {
/* istanbul ignore if */
if (err) {
return cb(err);
}
Expand Down
1 change: 1 addition & 0 deletions lib/shared/log/blacklist-error.js
Expand Up @@ -5,6 +5,7 @@ var log = require('gulplog');
var ansi = require('../ansi');
var exit = require('../exit');

/* istanbul ignore next */
function logBlacklistError(err) {
log.error(ansi.red('Error: failed to retrieve plugins black-list'));
log.error(err.message); // Avoid duplicating for each version
Expand Down
2 changes: 2 additions & 0 deletions lib/shared/log/tasks.js
Expand Up @@ -60,6 +60,7 @@ function getNodeFactory(getTask, entryObserver) {
},

taskNode: function(node) {
/* istanbul ignore next */
var task = getTask(node.label) || {};

var newNode = {
Expand All @@ -74,6 +75,7 @@ function getNodeFactory(getTask, entryObserver) {
if (flag.length === 0) {
return;
}
/* istanbul ignore next */
var opt = {
label: flag,
desc: typeof task.flags[flag] === 'string' ? task.flags[flag] : '',
Expand Down
1 change: 1 addition & 0 deletions lib/shared/log/to-console.js
Expand Up @@ -2,6 +2,7 @@

var fancyLog = require('fancy-log');

/* istanbul ignore next */
function noop() {}

// The sorting of the levels is
Expand Down
1 change: 1 addition & 0 deletions lib/versioned/^4.0.0/format-error.js
@@ -1,6 +1,7 @@
'use strict';

// Format orchestrator errors
/* istanbul ignore next */
function formatError(e) {
if (!e.error) {
return e.message;
Expand Down
2 changes: 2 additions & 0 deletions lib/versioned/^4.0.0/log/events.js
Expand Up @@ -12,6 +12,7 @@ function logEvents(gulpInst) {
var loggedErrors = [];

gulpInst.on('start', function(evt) {
/* istanbul ignore next */
// TODO: batch these
// so when 5 tasks start at once it only logs one time with all 5
var level = evt.branch ? 'debug' : 'info';
Expand All @@ -20,6 +21,7 @@ function logEvents(gulpInst) {

gulpInst.on('stop', function(evt) {
var time = prettyTime(evt.duration);
/* istanbul ignore next */
var level = evt.branch ? 'debug' : 'info';
log[level](
'Finished', '\'' + ansi.cyan(evt.name) + '\'',
Expand Down
2 changes: 2 additions & 0 deletions lib/versioned/^4.0.0/log/get-task.js
Expand Up @@ -16,6 +16,7 @@ function getDescription(task) {
if (typeof task.description === 'string') {
return task.description;
}
/* istanbul ignore else */
if (typeof task.unwrap === 'function') {
var origFn = task.unwrap();
if (typeof origFn.description === 'string') {
Expand All @@ -29,6 +30,7 @@ function getFlags(task) {
if (isObject(task.flags)) {
return task.flags;
}
/* istanbul ignore else */
if (typeof task.unwrap === 'function') {
var origFn = task.unwrap();
if (isObject(origFn.flags)) {
Expand Down

0 comments on commit 2d8a320

Please sign in to comment.