Created
April 7, 2015 04:43
-
-
Save dj1020/6e39f5e8c5310d1d75e1 to your computer and use it in GitHub Desktop.
Run codeception test with gulp and automatically open report when test fails
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
var gulp = require('gulp'); | |
var notify = require('gulp-notify'); | |
var codecept = require('gulp-codeception'); | |
var changed = require('gulp-changed'); | |
var open = require('gulp-open'); | |
var watch = require('gulp-watch'); | |
var debug = require('gulp-debug'); | |
var _ = require('lodash'); | |
gulp.task('runtest', function() { | |
var options = testCodeceptOptions('functional', 'userApiCest'); | |
gulp.src('codeception.yml') | |
.pipe(codecept('./vendor/bin/codecept', options)) | |
.on('error', function(files) { | |
notify.onError(testNotification('fail', 'codeception')); | |
gulp.run('autoOpenReport'); | |
}) | |
.pipe(notify(testNotification('pass', 'codeception'))); | |
}); | |
function testCodeceptOptions(suite, flags) { | |
var flags = flags || ''; | |
var options = { | |
debug: false, | |
clear: true, | |
testSuite: suite, | |
notify: true, | |
flags: "--colors " + flags | |
}; | |
return options; | |
} | |
function testNotification(status, pluginName, override) { | |
var options = { | |
sound: false, | |
title: (status == 'pass') ? 'Tests Passed' : 'Tests Failed', | |
message: (status == 'pass') ? '\n\nAll tests have passed!\n\n' : '\n\nOne or more tests failed...\n\n', | |
icon: __dirname + '/node_modules/gulp-' + pluginName + '/assets/test-' + status + '.png' | |
}; | |
options = _.merge(options, override); | |
return options; | |
} | |
gulp.task('buildCompare', function(){ | |
gulp.src('tests/_output/*.*') | |
.pipe(debug({title: 'buildCompare: '})) | |
.pipe(gulp.dest('tests/_output/html')); | |
}); | |
gulp.task('autoOpenReport', function(){ | |
gulp.src('tests/_output/*.*') | |
.pipe(changed('tests/_output/html')) | |
// .pipe(changed('tests/_output/html', {hasChanged: changed.compareLastModifiedTime})) | |
.pipe(debug({title: 'autoOpenReport'})) | |
.pipe(gulp.dest('tests/_output/html')) | |
.pipe(open('<%file.path%>')); | |
}); | |
gulp.task('watch', function () { | |
gulp.watch(['tests/**/*.php', 'app/**/*.php'], ['runtest']); | |
}); | |
gulp.task('default', ['buildCompare', 'runtest', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment