Skip to content

Commit 2d0c507

Browse files
committed
Merge pull request #67 from startersacademy/issue65-gulp-integration-tests-on-win
Issue #65: Get casper integration tests to run properly on both windows and mac
2 parents 154d7ab + 3e5017e commit 2d0c507

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

gulpfile.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,35 @@ gulp.task('server:stop', function(done){
3535
});
3636

3737

38+
// Spawns a process on windows
39+
function windowsSpawn(executable, args, options){
40+
return spawn('cmd.exe', ['/c', executable].concat(args), options);
41+
}
42+
3843
// Runs integration tests with casperjs and phantomjs
44+
// Using casper with gulp and windows is not intuitive. Change this at your own
45+
// risk.
3946
gulp.task('test:integration', function (done) {
4047
var tests = ['spec/integration'];
41-
var isWindows = process.platform === 'win32';
42-
var casperCmd = 'casperjs';
48+
var casperChild;
4349
var onError = function(code){
4450
done(code);
4551
// Gulp doesn't handle the error properly so clean up properly
4652
stopServer(1);
4753
};
4854

49-
if(isWindows){
50-
casperCmd = 'casperjs.cmd';
55+
if(process.platform === 'win32'){
56+
// Don't inherit stdio here since it causes problems
57+
casperChild = windowsSpawn('casperjs', ['test'].concat(tests));
58+
// Must handle data here for the tests to execute within the task
59+
// Handle this only for windows
60+
casperChild.stdout.on('data', function(data){
61+
gutil.log('CasperJS:', data.toString().slice(0, -1)); // remove \n
62+
});
63+
} else {
64+
casperChild = spawn('casperjs', ['test'].concat(tests), {stdio: 'inherit'});
5165
}
5266

53-
var casperChild = spawn(casperCmd, ['test'].concat(tests),
54-
{stdio: 'inherit'});
55-
5667
casperChild.on('close', function (code) {
5768
if (code) {
5869
// If there is an error, format the error object for gulp
@@ -102,7 +113,7 @@ gulp.task('test:unit:tdd', function (done) {
102113

103114

104115
// Runs server unit tests with jasmine 2.1
105-
gulp.task('test:server-unit', function () {
116+
gulp.task('test:unit:server', function () {
106117
return gulp.src('server/**/*.spec.js')
107118
.pipe(jasmine());
108119
});
@@ -124,7 +135,8 @@ gulp.task('test:all',
124135
gulpSequence(
125136
'server:start',
126137
'test:lint',
127-
'test:server-unit',
138+
'test:unit',
139+
'test:unit:server',
128140
'test:api',
129141
'test:integration',
130142
'server:stop'));

0 commit comments

Comments
 (0)