-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Use gulp-test-tools for testing (#98)
- Loading branch information
Showing
23 changed files
with
312 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,33 @@ | ||
'use strict'; | ||
|
||
var lab = exports.lab = require('lab').script(); | ||
var code = require('code'); | ||
|
||
var child = require('child_process'); | ||
|
||
var fs = require('fs-extra'); | ||
var path = require('path'); | ||
|
||
var outfile = path.resolve(__dirname, 'output/completion.out'); | ||
var expect = require('code').expect; | ||
var runner = require('gulp-test-tools').gulpRunner; | ||
|
||
lab.experiment('flag: --completion', function() { | ||
|
||
lab.before(function(done) { | ||
fs.mkdirpSync(path.resolve(__dirname, 'output')); | ||
done(); | ||
}); | ||
|
||
lab.after(function(done) { | ||
fs.remove(path.resolve(__dirname, 'output')); | ||
done(); | ||
}); | ||
|
||
['bash', 'fish', 'powershell', 'zsh'].forEach(function(type) { | ||
lab.test('returns completion script for ' + type, function(done) { | ||
child.exec('node ' + __dirname + '/../bin/gulp.js --completion=' + type + ' > ' + outfile, function(err) { | ||
var stdout = fs.readFileSync(outfile, { encoding: 'utf8' }); | ||
code.expect(stdout).to.contain('gulp --completion=' + type); | ||
runner({ verbose: false }) | ||
.gulp('--completion=' + type) | ||
.run(cb); | ||
|
||
function cb(err, stdout) { | ||
expect(stdout).to.contain('gulp --completion=' + type); | ||
done(err); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
lab.test('shows error message for unknown completion type', function(done) { | ||
child.exec('node ' + __dirname + '/../bin/gulp.js --completion=unknown > ' + outfile, function() { | ||
var stdout = fs.readFileSync(outfile, { encoding: 'utf8' }); | ||
code.expect(stdout).to.contain('rules for \'unknown\' not found'); | ||
runner({ verbose: false }) | ||
.gulp('--completion=unknown') | ||
.run(cb); | ||
|
||
function cb(err, stdout) { | ||
expect(stdout).to.contain('rules for \'unknown\' not found'); | ||
done(); | ||
}); | ||
} | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
'use strict'; | ||
var gulp = require('gulp'); | ||
|
||
function noop(cb) { | ||
function logGulpfilePath(cb) { | ||
console.log(__filename); | ||
return cb(); | ||
} | ||
|
||
gulp.task('default', gulp.series(noop)); | ||
gulp.task('default', gulp.series(logGulpfilePath)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,64 @@ | ||
'use strict'; | ||
|
||
var lab = exports.lab = require('lab').script(); | ||
var code = require('code'); | ||
|
||
var child = require('child_process'); | ||
var expect = require('code').expect; | ||
var runner = require('gulp-test-tools').gulpRunner; | ||
var eraseTime = require('gulp-test-tools').eraseTime; | ||
var eraseLapse = require('gulp-test-tools').eraseLapse; | ||
var skipLines = require('gulp-test-tools').skipLines; | ||
var headLines = require('gulp-test-tools').headLines; | ||
|
||
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/gulpfiles', 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\''); | ||
runner({ verbose: false }) | ||
.gulp('test4', '--continue', '--cwd ./test/fixtures/gulpfiles') | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
expect(err).to.be.not.null(); | ||
|
||
stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); | ||
expect(stdout).to.equal( | ||
'Starting \'test4\'...\n' + | ||
'Starting \'errorFunction\'...\n' + | ||
'Starting \'anon\'...\n' + | ||
'Finished \'anon\' after ?\n' + | ||
'' | ||
); | ||
|
||
stderr = eraseLapse(eraseTime(headLines(stderr, 2))); | ||
expect(stderr).to.equal( | ||
'\'errorFunction\' errored after ?\n' + | ||
'Error: Error!' | ||
); | ||
done(); | ||
}); | ||
} | ||
}); | ||
|
||
lab.test('stops execution when flag is not set', function(done) { | ||
child.exec('node ' + __dirname + '/../bin/gulp.js test4 --cwd ./test/fixtures/gulpfiles', 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\''); | ||
runner({ verbose: false }) | ||
.gulp('test4', '--cwd ./test/fixtures/gulpfiles') | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
expect(err).to.be.not.null(); | ||
|
||
expect(stdout).to.not.contain('Starting \'anon\''); | ||
stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); | ||
expect(stdout).to.equal( | ||
'Starting \'test4\'...\n' + | ||
'Starting \'errorFunction\'...\n' + | ||
'' | ||
); | ||
|
||
stderr = eraseLapse(eraseTime(headLines(stderr, 2))); | ||
expect(stderr).to.equal( | ||
'\'errorFunction\' errored after ?\n' + | ||
'Error: Error!' | ||
); | ||
done(); | ||
}); | ||
} | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
'use strict'; | ||
|
||
var lab = exports.lab = require('lab').script(); | ||
var code = require('code'); | ||
|
||
var child = require('child_process'); | ||
var expect = require('code').expect; | ||
var runner = require('gulp-test-tools').gulpRunner; | ||
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 path = require('path'); | ||
|
||
lab.experiment('flag: --gulpfile', function() { | ||
|
||
lab.test('Manually set path of gulpfile', function(done) { | ||
child.exec('node ' + __dirname + '/../bin/gulp.js --gulpfile "./test/fixtures/gulpfiles/gulpfile-2.js"', function(err, stdout) { | ||
stdout = stdout.replace(/\\/g, '/').split('\n'); | ||
code.expect(stdout[1]).to.contain('test/fixtures/gulpfiles/gulpfile-2.js'); | ||
code.expect(stdout[5]).to.contain('Finished \'default\''); | ||
var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; | ||
|
||
runner({ verbose: false }) | ||
.gulp('--gulpfile', gulpfilePath) | ||
.run(cb); | ||
|
||
function cb(err, stdout) { | ||
var chgWorkdirLog = headLines(stdout, 1); | ||
var workdir = path.dirname(gulpfilePath).replace(/\//g, path.sep); | ||
expect(chgWorkdirLog).to.contain('Working directory changed to '); | ||
expect(chgWorkdirLog).to.contain(workdir); | ||
|
||
stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); | ||
expect(stdout).to.equal( | ||
'Starting \'default\'...\n' + | ||
'Starting \'logGulpfilePath\'...\n' + | ||
path.resolve(gulpfilePath) + '\n' + | ||
'Finished \'logGulpfilePath\' after ?\n' + | ||
'Finished \'default\' after ?\n' + | ||
'' | ||
); | ||
done(err); | ||
}); | ||
} | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
'use strict'; | ||
|
||
var lab = exports.lab = require('lab').script(); | ||
var code = require('code'); | ||
|
||
var fs = require('fs-extra'); | ||
var child = require('child_process'); | ||
var expect = require('code').expect; | ||
var runner = require('gulp-test-tools').gulpRunner; | ||
|
||
var path = require('path'); | ||
var outfile = path.resolve(__dirname, 'output/flags-help.out'); | ||
|
||
var output = fs.readFileSync(__dirname + '/expected/flags-help.txt', 'utf8').replace(/(\r\n|\n|\r)\s?/gm,'\n'); | ||
var fs = require('fs'); | ||
|
||
lab.experiment('flag: --help', function() { | ||
// Erases a first space inserted by `chalk`. | ||
function eraseFirstSpace(s) { | ||
return s.replace(/^(\r\n|\n|\r)\s?/g, '\n'); | ||
} | ||
|
||
lab.before(function(done) { | ||
fs.mkdirpSync(path.resolve(__dirname, 'output')); | ||
done(); | ||
}); | ||
var outputFile = path.join(__dirname, 'expected/flags-help.txt'); | ||
var outputText = fs.readFileSync(outputFile, 'utf8'); | ||
|
||
lab.after(function(done) { | ||
fs.removeSync(path.resolve(__dirname, 'output')); | ||
done(); | ||
}); | ||
lab.experiment('flag: --help', function() { | ||
|
||
lab.test('shows help using --help', function(done) { | ||
child.exec('node ' + __dirname + '/../bin/gulp.js --help --cwd ./test/fixtures/gulpfiles > ' + outfile, function(err) { | ||
var stdout = fs.readFileSync(outfile, { encoding: 'utf8' }); | ||
code.expect(stdout.replace(/(\r\n|\n|\r)\s?/gm,'\n')).to.equals(output); | ||
runner({ verbose: false }) | ||
.gulp('--help', '--cwd ./test/fixtures/gulpfiles') | ||
.run(cb); | ||
|
||
function cb(err, stdout) { | ||
stdout = eraseFirstSpace(stdout); | ||
expect(stdout).to.equal(outputText); | ||
done(err); | ||
}); | ||
} | ||
}); | ||
|
||
lab.test('shows help using short --h', function(done) { | ||
child.exec('node ' + __dirname + '/../bin/gulp.js --h --cwd ./test/fixtures/gulpfiles > ' + outfile, function(err) { | ||
var stdout = fs.readFileSync(outfile, { encoding: 'utf8' }); | ||
code.expect(stdout.replace(/(\r\n|\n|\r)\s?/gm,'\n')).to.equals(output); | ||
runner({ verbose: false }) | ||
.gulp('--h', '--cwd ./test/fixtures/gulpfiles') | ||
.run(cb); | ||
|
||
function cb(err, stdout) { | ||
stdout = eraseFirstSpace(stdout); | ||
expect(stdout).to.equal(outputText); | ||
done(err); | ||
}); | ||
} | ||
}); | ||
|
||
}); |
Oops, something went wrong.