Skip to content

Commit

Permalink
Update: Add flags.continue to config
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Dec 21, 2017
1 parent 5cce19c commit 4c49f4a
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 8 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ var usage =
var parser = yargs.usage(usage, cliOptions);
var opts = parser.argv;

// This translates the --continue flag in gulp
// To the settle env variable for undertaker
// We use the process.env so the user's gulpfile
// Can know about the flag
if (opts.continue) {
process.env.UNDERTAKER_SETTLE = 'true';
}

// Set up event listeners for logging temporarily.
toConsole(log, opts);

Expand Down Expand Up @@ -103,6 +95,14 @@ function handleArguments(env) {
opts = mergeConfigToCliFlags(opts, cfg);
env = mergeConfigToEnvFlags(env, cfg);

// This translates the --continue flag in gulp
// To the settle env variable for undertaker
// We use the process.env so the user's gulpfile
// Can know about the flag
if (opts.continue) {
process.env.UNDERTAKER_SETTLE = 'true';
}

// Set up event listeners for logging again after configuring.
toConsole(log, opts);

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 @@ -4,6 +4,7 @@ var copyProps = require('copy-props');

var fromTo = {
'flags.silent': 'silent',
'flags.continue': 'continue',
};

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

var expect = require('expect');
var path = require('path');
var skipLines = require('gulp-test-tools').skipLines;
var headLines = require('gulp-test-tools').headLines;
var eraseTime = require('gulp-test-tools').eraseTime;
var eraseLapse = require('gulp-test-tools').eraseLapse;

var fixturesDir = path.join(__dirname, 'fixtures/config');
var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir);

describe('config: flags.continue', function() {

it('Should continue if `flags.continue` is true in .gulp.*',
function(done) {
runner
.chdir('flags/continue/t')
.gulp()
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toNotEqual(null);

stdout = eraseLapse(eraseTime(skipLines(stdout, 1)));
expect(stdout).toEqual(
'Starting \'default\'...\n' +
'Starting \'err\'...\n' +
'Starting \'next\'...\n' +
'Finished \'next\' after ?\n' +
''
);
stderr = eraseLapse(eraseTime(headLines(stderr, 2)));
expect(stderr).toEqual(
'\'err\' errored after ?\n' +
'Error: Error!'
);
done();
}
});

it('Should not continue if `flags.continue` is false in .gulp.*',
function(done) {
runner
.chdir('flags/continue/f')
.gulp()
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toNotEqual(null);

stdout = eraseLapse(eraseTime(skipLines(stdout, 1)));
expect(stdout).toEqual(
'Starting \'default\'...\n' +
'Starting \'err\'...\n' +
''
);
stderr = eraseLapse(eraseTime(headLines(stderr, 2)));
expect(stderr).toEqual(
'\'err\' errored after ?\n' +
'Error: Error!'
);
done();
}
});

});
5 changes: 5 additions & 0 deletions test/fixtures/config/flags/continue/f/.gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flags": {
"continue": false
}
}
13 changes: 13 additions & 0 deletions test/fixtures/config/flags/continue/f/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

var gulp = require('gulp');

function err(done) {
done(new Error('Error!'));
}

function next(done) {
done();
}

gulp.task('default', gulp.series(err, next));
5 changes: 5 additions & 0 deletions test/fixtures/config/flags/continue/t/.gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flags": {
"continue": true
}
}
13 changes: 13 additions & 0 deletions test/fixtures/config/flags/continue/t/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

var gulp = require('gulp');

function err(done) {
done(new Error('Error!'));
}

function next(done) {
done();
}

gulp.task('default', gulp.series(err, next));
2 changes: 2 additions & 0 deletions test/lib/config-cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ describe('lib: config/cli-flags', function() {
description: 'DESCRIPTION.',
flags: {
silent: true,
continue: true,
gulpfile: '/path/to/gulpfile',
},
};

var result = mergeConfig(opts, config);
expect(result).toEqual({
silent: true,
continue: true,
});
done();
});
Expand Down

0 comments on commit 4c49f4a

Please sign in to comment.