Skip to content

Commit

Permalink
Update: Add more integration tests & test against gulp 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanx authored and phated committed Dec 21, 2017
1 parent 6c9f9f8 commit 6c5e892
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 153 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"coveralls": "^2.7.0",
"eslint": "^1.7.3",
"eslint-config-gulp": "^2.0.0",
"gulp": ">=3.8.10",
"fs-extra": "^0.26.1",
"gulp": "gulpjs/gulp#4.0",
"jscs": "^2.3.5",
"jscs-preset-gulp": "^1.0.0",
"lab": "^6.2.0",
Expand Down
38 changes: 19 additions & 19 deletions test/expected/flags-help.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Usage: gulp [options] tasks
Options:
--help, -h Show this help. [boolean]
--version, -v Print the global and local gulp versions. [boolean]
--require Will require a module before running the gulpfile. This is useful for transpilers but also has other applications. [string]
--gulpfile Manually set path of gulpfile. Useful if you have multiple gulpfiles. This will set the CWD to the gulpfile directory as well. [string]
--cwd Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here. [string]
--verify Will verify plugins referenced in project's package.json against the plugins blacklist.
--tasks, -T Print the task dependency tree for the loaded gulpfile. [boolean]
--tasks-simple Print a plaintext list of tasks for the loaded gulpfile. [boolean]
--tasks-json Print the task dependency tree, in JSON format, for the loaded gulpfile.
--color Will force gulp and gulp plugins to display colors, even when no color support is detected. [boolean]
--no-color Will force gulp and gulp plugins to not display colors, even when color support is detected. [boolean]
--silent, -S Suppress all gulp logging. [boolean]
--continue Continue execution of tasks upon failure. [boolean]
--log-level, -L Set the loglevel. -L for least verbose and -LLLL for most verbose. -LLL is default. [count]

Usage: gulp [options] tasks

Options:
--help, -h Show this help. [boolean]
--version, -v Print the global and local gulp versions. [boolean]
--require Will require a module before running the gulpfile. This is useful for transpilers but also has other applications. [string]
--gulpfile Manually set path of gulpfile. Useful if you have multiple gulpfiles. This will set the CWD to the gulpfile directory as well. [string]
--cwd Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here. [string]
--verify Will verify plugins referenced in project's package.json against the plugins blacklist.
--tasks, -T Print the task dependency tree for the loaded gulpfile. [boolean]
--tasks-simple Print a plaintext list of tasks for the loaded gulpfile. [boolean]
--tasks-json Print the task dependency tree, in JSON format, for the loaded gulpfile.
--color Will force gulp and gulp plugins to display colors, even when no color support is detected. [boolean]
--no-color Will force gulp and gulp plugins to not display colors, even when color support is detected. [boolean]
--silent, -S Suppress all gulp logging. [boolean]
--continue Continue execution of tasks upon failure. [boolean]
--log-level, -L Set the loglevel. -L for least verbose and -LLLL for most verbose. -LLL is default. [count]

1 change: 1 addition & 0 deletions test/expected/flags-tasks-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]
1 change: 1 addition & 0 deletions test/expected/flags-tasks-simple.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test1
test2
test3
test4
default
26 changes: 26 additions & 0 deletions test/expected/flags-tasks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
gulp-cli/test
├─┬ test1
│ └─┬ <series>
│ └── noop
├─┬ test2
│ └─┬ <series>
│ ├─┬ test1
│ │ └─┬ <series>
│ │ └── noop
│ └── noop
├─┬ test3
│ └─┬ <series>
│ └── described
├─┬ test4
│ └─┬ <series>
│ ├── errorFunction
│ └── anon
└─┬ default
└─┬ <series>
├─┬ test1
│ └─┬ <series>
│ └── noop
├─┬ test3
│ └─┬ <series>
│ └── described
└── noop
14 changes: 8 additions & 6 deletions test/fixtures/gulpfile-2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
var gulp = require('gulp');

function noop() {}

gulp.task('default', noop);
'use strict';
var gulp = require('gulp');

function noop(cb) {
return cb()
}

gulp.task('default', gulp.series(noop));
12 changes: 12 additions & 0 deletions test/fixtures/gulpfile-3.8.10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
var gulp = require('gulp');

function noop() {}
function described() {}
described.description = 'description';

gulp.task('test1', noop);
gulp.task('test2', ['test1'], noop);
gulp.task('test3', described);

gulp.task('default', ['test1', 'test3'], noop);
20 changes: 15 additions & 5 deletions test/fixtures/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
'use strict';

var gulp = require('gulp');

function noop() {}
function noop(cb) {
return cb()
}
function described() {}
function errorFunction() {
throw new Error('Error!');
}
function anon(cb) {
return cb()
}
described.description = 'description';

gulp.task('test1', noop);
gulp.task('test2', ['test1'], noop);
gulp.task('test3', described);
gulp.task('test1', gulp.series(noop));
gulp.task('test2', gulp.series('test1', noop));
gulp.task('test3', gulp.series(described));
gulp.task('test4', gulp.series(errorFunction, anon));

gulp.task('default', ['test1', 'test3'], noop);
gulp.task('default', gulp.series('test1', 'test3', noop));
6 changes: 3 additions & 3 deletions test/fixtures/test-module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
console.log('inside test module');
exports = function() {
console.log('inside test module function');
console.log('inside test module');
exports = function() {
console.log('inside test module function');
};
31 changes: 31 additions & 0 deletions test/flags-continue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

var lab = exports.lab = require('lab').script();
var code = require('code');

var fs = require('fs');
var child = require('child_process');

lab.experiment('flag: --continue', function() {

lab.test('continues execution when flag is set', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js test4 --continue --cwd ./test/fixtures', function(err, stdout, stderr) {
code.expect(stdout).to.contain('Starting \'errorFunction\'');
code.expect(stderr).to.contain('\'errorFunction\' errored after');
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[4]).to.contain('Starting \'anon\'');
code.expect(stdout[5]).to.contain('Finished \'anon\'');
done();
});
});

lab.test('stops execution when flag is not set', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js test4 --cwd ./test/fixtures', function(err, stdout, stderr) {
code.expect(stdout).to.contain('Starting \'errorFunction\'');
code.expect(stderr).to.contain('\'errorFunction\' errored after');
code.expect(stdout[4]).to.not.contain('Starting \'anon\'');
done();
});
});

});
40 changes: 20 additions & 20 deletions test/flags-gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use strict';

var lab = exports.lab = require('lab').script();
var code = require('code');

var fs = require('fs');
var child = require('child_process');

lab.experiment('flag: --gulpfile', function() {

lab.test('Manually set path of gulpfile', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --gulpfile "./test/fixtures/gulpfile-2.js"', function(err, stdout) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[1]).to.contain('test/fixtures/gulpfile-2.js');
code.expect(stdout[3]).to.contain('Finished \'default\'');
done(err);
});
});

});
'use strict';

var lab = exports.lab = require('lab').script();
var code = require('code');

var fs = require('fs');
var child = require('child_process');

lab.experiment('flag: --gulpfile', function() {

lab.test('Manually set path of gulpfile', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --gulpfile "./test/fixtures/gulpfile-2.js"', function(err, stdout) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[1]).to.contain('test/fixtures/gulpfile-2.js');
code.expect(stdout[5]).to.contain('Finished \'default\'');
done(err);
});
});

});
54 changes: 27 additions & 27 deletions test/flags-help.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
'use strict';

var lab = exports.lab = require('lab').script();
var code = require('code');

var fs = require('fs');
var child = require('child_process');

var output = fs.readFileSync(__dirname + '/expected/flags-help.txt', 'utf8').replace(/\r\n/g, '\n');

lab.experiment('flag: help', function() {

lab.test('shows help using --help', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --help', function(err, stdout) {
code.expect(stdout).to.equals(output);
done();
});
});

lab.test('shows help using short --h', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --h', function(err, stdout) {
code.expect(stdout).to.equals(output);
done();
});
});

});
'use strict';

var lab = exports.lab = require('lab').script();
var code = require('code');

var fs = require('fs');
var child = require('child_process');

var output = fs.readFileSync(__dirname + '/expected/flags-help.txt', 'utf8').replace(/(\r\n|\n|\r)\s?/gm,'\n');

lab.experiment('flag: help', function() {

lab.test('shows help using --help', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --help --cwd ./test/fixtures', function(err, stdout) {
code.expect(stdout.replace(/(\r\n|\n|\r)\s?/gm,'\n')).to.equals(output);
done(err);
});
});

lab.test('shows help using short --h', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --h --cwd ./test/fixtures', function(err, stdout) {
code.expect(stdout.replace(/(\r\n|\n|\r)\s?/gm,'\n')).to.equals(output);
done(err);
});
});

});
50 changes: 25 additions & 25 deletions test/flags-require.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
'use strict';

var lab = exports.lab = require('lab').script();
var code = require('code');

var fs = require('fs');
var child = require('child_process');

lab.experiment('flag: --require', function() {
lab.test('requires module before running gulpfile', function(done) {
child.exec('node ' + __dirname + '\\..\\bin\\gulp.js --require ./test-module.js --cwd ./test/fixtures', function(err, stdout) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[0]).to.equal('inside test module');
code.expect(stdout[1]).to.contain('Requiring external module ./test-module.js');
done(err);
});
});
lab.test('errors if module doesn\'t exist', function(done) {
child.exec('node ' + __dirname + '\\..\\bin\\gulp.js --require ./null-module.js --cwd ./test/fixtures', function(err, stdout, stderr) {
stderr = stderr.replace(/\\/g, '/').split('\n');
code.expect(stderr[0]).to.contain('Failed to load external module ./null-module.js');
done(err);
});
});
});
'use strict';

var lab = exports.lab = require('lab').script();
var code = require('code');

var fs = require('fs');
var child = require('child_process');

lab.experiment('flag: --require', function() {
lab.test('requires module before running gulpfile', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --require ./test-module.js --cwd ./test/fixtures', function(err, stdout) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[0]).to.equal('inside test module');
code.expect(stdout[1]).to.contain('Requiring external module ./test-module.js');
done(err);
});
});
lab.test('errors if module doesn\'t exist', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --require ./null-module.js --cwd ./test/fixtures', function(err, stdout, stderr) {
stderr = stderr.replace(/\\/g, '/').split('\n');
code.expect(stderr[0]).to.contain('Failed to load external module ./null-module.js');
done(err);
});
});
});
18 changes: 18 additions & 0 deletions test/flags-silent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

var lab = exports.lab = require('lab').script();
var code = require('code');

var fs = require('fs');
var child = require('child_process');

lab.experiment('flag: --silent', function() {

lab.test('prints nothing when silent flag is set', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --silent --cwd ./test/fixtures', function(err, stdout) {
code.expect(stdout).to.equal('');
done(err);
});
});

});
2 changes: 1 addition & 1 deletion test/flags-task-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var code = require('code');
var fs = require('fs');
var child = require('child_process');

var output = fs.readFileSync(__dirname + '/expected/flags-tasks-simple.txt', 'utf8').replace(/\r\n/g, '\n');
var output = fs.readFileSync(__dirname + '/expected/flags-tasks-simple.txt', 'utf8').replace(/(\r\n|\n|\r)/gm,'\n');

lab.experiment('flag: --tasks-simple', function() {

Expand Down
36 changes: 36 additions & 0 deletions test/flags-tasks-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var fs = require('fs-extra');
var lab = exports.lab = require('lab').script();
var code = require('code');

var child = require('child_process');
var output = require('./expected/flags-tasks-json.json')

lab.experiment('flag: --tasks-json', function() {

lab.test('prints the task list with no args', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks-json --gulpfile "./test/fixtures/gulpfile.js" ', function(err, stdout) {
stdout = stdout.replace(/\\/g, '/').split('\n');
var parsedJson = JSON.parse(stdout[1]);
code.expect(parsedJson).to.deep.equal(output);
done(err);
});
});

lab.test('writes the task list to file with path', function(done) {
fs.emptyDir(__dirname + '/output/', function(err) {
if (err) {
return done(err);
}

child.exec('node ' + __dirname + '/../bin/gulp.js --tasks-json "../output/tasks.json" --gulpfile "./test/fixtures/gulpfile.js" ', function(err, stdout) {
var file = fs.readFileSync(__dirname + '/output/tasks.json', 'utf8')
var parsedJson = JSON.parse(file);
code.expect(parsedJson).to.deep.equal(output);
fs.removeSync(__dirname + '/output/')
done(err);
});
});
});
});
Loading

0 comments on commit 6c5e892

Please sign in to comment.