Skip to content

Commit

Permalink
Update: Add some integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanx authored and phated committed Dec 21, 2017
1 parent 6aa90b4 commit d8b14e8
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Command Line Utility for Gulp
<td>Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here.</td>
</tr>
<tr>
<td>--verify</td>
<td>--verify [path (optional)]</td>
<td></td>
<td>Will verify plugins referenced in project's package.json against the plugins blacklist.</td>
</tr>
Expand Down
19 changes: 19 additions & 0 deletions test/expected/flags-help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +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]

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

function noop() {}

gulp.task('default', noop);
1 change: 0 additions & 1 deletion test/fixtures/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var gulp = require('gulp');

function noop() {}
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/packages/invalid-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "test-package",
"description": "Test Package for Testing!",
"version": "0.0.1",
"tags": [
],
"files": [
],
"dependencies": {
"gulp-blink": "^0.1.4"
},
"engines": {
"node": ">= 0.9"
},
"licenses": [
{
"type": "MIT",
"url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE"
}
]
}
21 changes: 21 additions & 0 deletions test/fixtures/packages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "default-package",
"description": "Test Package for Testing!",
"version": "0.0.1",
"tags": [
],
"files": [
],
"dependencies": {
"gulp-blink": "^0.1.4"
},
"engines": {
"node": ">= 0.9"
},
"licenses": [
{
"type": "MIT",
"url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE"
}
]
}
21 changes: 21 additions & 0 deletions test/fixtures/packages/valid-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "test-package-2",
"description": "Test Package for Testing!",
"version": "0.0.1",
"tags": [
],
"files": [
],
"dependencies": {
"yargs": "^3.27.0"
},
"engines": {
"node": ">= 0.9"
},
"licenses": [
{
"type": "MIT",
"url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE"
}
]
}
20 changes: 20 additions & 0 deletions test/flags-gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +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);
});
});

});
27 changes: 27 additions & 0 deletions test/flags-help.js
Original file line number Diff line number Diff line change
@@ -0,0 +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();
});
});

});
11 changes: 11 additions & 0 deletions test/flags-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'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');
});
38 changes: 38 additions & 0 deletions test/flags-verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
var lab = exports.lab = require('lab').script();
var code = require('code');

var child = require('child_process');

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

lab.test('dependencies with invalid dependency', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --verify "packages/invalid-package.json" --cwd "./test/fixtures/packages/"', function(err, stdout) {
// Ignore err as the verify failure is considered a error state.
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[1]).to.contain('Blacklisted plugins found in this project:');
code.expect(stdout[2]).to.contain('gulp-blink: deprecated. use `blink` instead.');
done();
});
});

lab.test('dependencies with valid dependency', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --verify "packages/valid-package.json" --cwd "./test/fixtures/packages/"', function(err, stdout) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[1]).to.contain(' There are no blacklisted plugins in this project');
done(err);
});
});

lab.test('default args with invalid dependency', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --verify "packages/package.json" --cwd ./test/fixtures/packages/', function(err, stdout) {
console.log(stdout);
// Ignore err as the verify failure is considered a error state.
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[1]).to.contain('Blacklisted plugins found in this project:');
code.expect(stdout[2]).to.contain('gulp-blink: deprecated. use `blink` instead.');
done();
});
});

});

0 comments on commit d8b14e8

Please sign in to comment.