Skip to content

Commit 2d8a320

Browse files
sttkphated
authored andcommitted
Build: Improve tests and raise coverage (#190)
1 parent 12a022a commit 2d8a320

34 files changed

+334
-88
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
*.log
33
node_modules
4+
!test/fixtures/errors/bad-gulp-version/node_modules/
45
build
56
*.node
67
components

index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ cli.on('requireFail', function(name, error) {
7070
ansi.yellow('Failed to load external module'),
7171
ansi.magenta(name)
7272
);
73+
/* istanbul ignore else */
7374
if (error) {
7475
log.warn(ansi.yellow(error.toString()));
7576
}
@@ -122,20 +123,20 @@ function handleArguments(env) {
122123

123124
// Anything that needs to print outside of the logging mechanism should use console.log
124125
if (opts.version) {
125-
console.log('CLI version', cliVersion);
126-
if (env.modulePackage && typeof env.modulePackage.version !== 'undefined') {
127-
console.log('Local version', env.modulePackage.version);
128-
}
126+
console.log('CLI version:', cliVersion);
127+
console.log('Local version:', env.modulePackage.version || 'Unknown');
129128
exit(0);
130129
}
131130

132131
if (opts.verify) {
133132
var pkgPath = opts.verify !== true ? opts.verify : 'package.json';
133+
/* istanbul ignore else */
134134
if (path.resolve(pkgPath) !== path.normalize(pkgPath)) {
135135
pkgPath = path.join(env.cwd, pkgPath);
136136
}
137137
log.info('Verifying plugins in ' + pkgPath);
138138
return getBlacklist(function(err, blacklist) {
139+
/* istanbul ignore if */
139140
if (err) {
140141
return logBlacklistError(err);
141142
}
@@ -147,10 +148,12 @@ function handleArguments(env) {
147148
}
148149

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

156+
/* istanbul ignore next */
154157
var missingGulpMessage =
155158
missingNodeModules
156159
? 'Local modules not found in'
@@ -159,6 +162,7 @@ function handleArguments(env) {
159162
ansi.red(missingGulpMessage),
160163
ansi.magenta(tildify(env.cwd))
161164
);
165+
/* istanbul ignore next */
162166
var installCommand =
163167
missingNodeModules
164168
? 'npm install'
@@ -186,9 +190,10 @@ function handleArguments(env) {
186190
var range = findRange(env.modulePackage.version, ranges);
187191

188192
if (!range) {
189-
return log.error(
193+
log.error(
190194
ansi.red('Unsupported gulp version', env.modulePackage.version)
191195
);
196+
exit(1);
192197
}
193198

194199
// Load and execute the CLI version

lib/shared/ansi.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var supportsColor = require('color-support');
55

66
var hasColors = colorize();
77

8+
/* istanbul ignore next */
89
module.exports = {
910
red: hasColors ? colors.red : noColor,
1011
green: hasColors ? colors.green : noColor,
@@ -31,6 +32,7 @@ function colorize() {
3132
return false;
3233
}
3334

35+
/* istanbul ignore if */
3436
if (hasFlag('color')) {
3537
return true;
3638
}

lib/shared/config/env-flags.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ function mergeConfigToEnvFlags(env, config, cliOpts) {
3434
return [].concat(envInfo.value, configInfo.value);
3535
}
3636

37+
/* istanbul ignore else */
3738
if (envInfo.keyChain === 'nodeFlags') {
3839
return [].concat(configInfo.value || []);
3940
}
40-
41-
return configInfo.value;
4241
}
4342
}
4443

lib/shared/exit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Fix stdout truncation on windows
44
function exit(code) {
5+
/* istanbul ignore next */
56
if (process.platform === 'win32' && process.stdout.bufferSize) {
67
process.stdout.once('drain', function() {
78
process.exit(code);

lib/shared/get-blacklist.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function parse(str, cb) {
1919
try {
2020
cb(null, JSON.parse(str));
2121
} catch (err) {
22+
/* istanbul ignore next */
2223
cb(new Error('Invalid Blacklist JSON.'));
2324
}
2425
}
@@ -28,6 +29,7 @@ function getBlacklist(cb) {
2829
https.get(url, onRequest);
2930

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

4143
function onCollect(err, result) {
44+
/* istanbul ignore if */
4245
if (err) {
4346
return cb(err);
4447
}
@@ -47,6 +50,7 @@ function getBlacklist(cb) {
4750
}
4851

4952
function onParse(err, blacklist) {
53+
/* istanbul ignore if */
5054
if (err) {
5155
return cb(err);
5256
}

lib/shared/log/blacklist-error.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var log = require('gulplog');
55
var ansi = require('../ansi');
66
var exit = require('../exit');
77

8+
/* istanbul ignore next */
89
function logBlacklistError(err) {
910
log.error(ansi.red('Error: failed to retrieve plugins black-list'));
1011
log.error(err.message); // Avoid duplicating for each version

lib/shared/log/tasks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function getNodeFactory(getTask, entryObserver) {
6060
},
6161

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

6566
var newNode = {
@@ -74,6 +75,7 @@ function getNodeFactory(getTask, entryObserver) {
7475
if (flag.length === 0) {
7576
return;
7677
}
78+
/* istanbul ignore next */
7779
var opt = {
7880
label: flag,
7981
desc: typeof task.flags[flag] === 'string' ? task.flags[flag] : '',

lib/shared/log/to-console.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

5+
/* istanbul ignore next */
56
function noop() {}
67

78
// The sorting of the levels is

lib/versioned/^4.0.0/format-error.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
// Format orchestrator errors
4+
/* istanbul ignore next */
45
function formatError(e) {
56
if (!e.error) {
67
return e.message;

0 commit comments

Comments
 (0)