forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More tests around _runTask() and _readyToRunTask()
- Loading branch information
Showing
5 changed files
with
222 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*jshint node:true */ | ||
/*global describe:false, it:false, beforeEach:false, afterEach:false */ | ||
|
||
"use strict"; | ||
|
||
var gulp = require('../'); | ||
require('should'); | ||
require('mocha'); | ||
|
||
describe('gulp task is ready when dependencies are resolved', function() { | ||
// Don't bleed previous test into subsequent test | ||
beforeEach(gulp.reset); | ||
afterEach(gulp.reset); | ||
describe('_readyToRunTask()', function() { | ||
it('should be ready if no dependencies', function(done) { | ||
var task, expected, actual; | ||
expected = true; | ||
task = { | ||
name: 'a', | ||
dep: [] | ||
}; | ||
gulp.tasks = { a: task }; | ||
|
||
actual = gulp._readyToRunTask(task); | ||
|
||
actual.should.equal(expected); | ||
done(); | ||
}); | ||
it('should be ready if dependency is done', function(done) { | ||
var task, dep, expected, actual; | ||
expected = true; | ||
task = { | ||
name: 'a', | ||
dep: ['b'] | ||
}; | ||
dep = { | ||
name: 'b', | ||
dep: [], | ||
done: true | ||
}; | ||
gulp.tasks = { a: task, b: dep }; | ||
|
||
actual = gulp._readyToRunTask(task); | ||
|
||
actual.should.equal(expected); | ||
done(); | ||
}); | ||
it('should not be ready if dependency is not done', function(done) { | ||
var task, dep, expected, actual; | ||
expected = false; | ||
task = { | ||
name: 'a', | ||
dep: ['b'] | ||
}; | ||
dep = { | ||
name: 'b', | ||
dep: [] | ||
//done: lack of var is falsey | ||
}; | ||
gulp.tasks = { a: task, b: dep }; | ||
|
||
actual = gulp._readyToRunTask(task); | ||
|
||
actual.should.equal(expected); | ||
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/*jshint node:true */ | ||
/*global describe:false, it:false, beforeEach:false, afterEach:false, before:false, after:false */ | ||
|
||
"use strict"; | ||
|
||
var gulp = require('../'); | ||
var Q = require('q'); | ||
var should = require('should'); | ||
require('mocha'); | ||
|
||
describe('gulp tasks execute as expected', function() { | ||
// Don't bleed previous test into subsequent test | ||
var real_runStep; | ||
var hasRunStep = false; | ||
before(function () { | ||
real_runStep = gulp._runStep; | ||
gulp._runStep = function () { | ||
hasRunStep = true; | ||
}; | ||
}); | ||
after(function () { | ||
gulp._runStep = real_runStep; | ||
}); | ||
beforeEach(function () { | ||
hasRunStep = false; | ||
gulp.reset(); | ||
}); | ||
afterEach(gulp.reset); | ||
describe('_runTask()', function() { | ||
it('calls task function', function(done) { | ||
var a, task; | ||
a = 0; | ||
task = { | ||
name: 'test', | ||
fn: function() { | ||
++a; | ||
} | ||
}; | ||
gulp._runTask(task); | ||
a.should.equal(1); | ||
done(); | ||
}); | ||
it('sets .running correctly', function(done) { | ||
var task; | ||
task = { | ||
name: 'test', | ||
fn: function() { | ||
should.exist(task.running); | ||
task.running.should.equal(true); | ||
} | ||
}; | ||
gulp._runTask(task); | ||
should.exist(task.running); | ||
task.running.should.equal(false); | ||
done(); | ||
}); | ||
it('sync task sets done after calling function', function(done) { | ||
var task; | ||
task = { | ||
name: 'test', | ||
fn: function() { | ||
should.not.exist(task.done); | ||
} | ||
}; | ||
gulp._runTask(task); | ||
should.exist(task.done); | ||
task.done.should.equal(true); | ||
hasRunStep.should.equal(false); | ||
done(); | ||
}); | ||
it('async task sets done after task resolves', function(done) { | ||
var task, timeout = 5; | ||
task = { | ||
name: 'test', | ||
fn: function() { | ||
var deferred = Q.defer(); | ||
setTimeout(function () { | ||
should.not.exist(task.done); | ||
deferred.resolve(); | ||
}, timeout); | ||
return deferred.promise; | ||
} | ||
}; | ||
gulp._runTask(task); | ||
should.not.exist(task.done); | ||
setTimeout(function () { | ||
should.exist(task.done); | ||
task.done.should.equal(true); | ||
hasRunStep.should.equal(true); | ||
done(); | ||
}, timeout*2); | ||
}); | ||
}); | ||
}); |
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