Skip to content

Commit

Permalink
Update: Switch to mocha + expect for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jun 23, 2016
1 parent 67fd02c commit e3901ed
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 137 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
sudo: false
language: node_js
node_js:
- 'stable'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
after_script:
- npm run coveralls
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
"lib"
],
"scripts": {
"lint": "eslint . && jscs *.js lib/ test/",
"test": "lab -cv --ignore store@sparkles"
"lint": "eslint . && jscs index.js test/",
"test": "mocha --async-only",
"cover": "istanbul cover _mocha --report lcovonly",
"coveralls": "npm run cover && istanbul-coveralls"
},
"dependencies": {
"bach": "^0.5.0",
Expand All @@ -33,14 +35,16 @@
},
"devDependencies": {
"async-once": "^1.0.0",
"code": "^1.2.1",
"del": "^2.0.2",
"eslint": "^1.7.3",
"eslint-config-gulp": "^2.0.0",
"expect": "^1.19.0",
"gulp-jshint": "^1.8.4",
"istanbul": "^0.4.3",
"istanbul-coveralls": "^1.0.3",
"jscs": "^2.3.5",
"jscs-preset-gulp": "^1.0.0",
"lab": "^6.2.0",
"mocha": "^2.4.5",
"once": "^1.3.1",
"through2": "^2.0.0",
"undertaker-common-tasks": "^1.0.0",
Expand Down
13 changes: 4 additions & 9 deletions test/integration.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;

var describe = lab.describe;
var it = lab.it;
var beforeEach = lab.beforeEach;
var expect = require('expect');

var fs = require('fs');
var path = require('path');
Expand Down Expand Up @@ -82,7 +77,7 @@ describe('integrations', function() {
));

taker.parallel('build')(function(err) {
expect(count).to.equal(1);
expect(count).toEqual(1);
done(err);
});
});
Expand All @@ -108,7 +103,7 @@ describe('integrations', function() {
));

taker.parallel('build')(function(err) {
expect(count).to.equal(1);
expect(count).toEqual(1);
done(err);
});
});
Expand Down Expand Up @@ -144,7 +139,7 @@ describe('integrations', function() {
}

taker.series(setup, 'build', userWait, userEdit, countEditedFiles, function(cb) {
expect(count).to.be.equal(1);
expect(count).toEqual(1);
cb();
})(done);
});
Expand Down
40 changes: 16 additions & 24 deletions test/last-run.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;

var describe = lab.describe;
var it = lab.it;
var beforeEach = lab.beforeEach;
var afterEach = lab.afterEach;
var expect = require('expect');

var Undertaker = require('../');

Expand Down Expand Up @@ -57,44 +51,42 @@ describe('lastRun', function() {
};
taker.task('test', test);
taker.parallel('test')(function(err) {
expect(ts).to.be.undefined();
expect(ts).toEqual(undefined);
done(err);
});
});

it('should record tasks time execution', function(done) {
var since = Date.now();
taker.parallel('test1')(function(err) {
expect(taker.lastRun('test1')).to.exist();
expect(taker.lastRun('test1')).to.be.within(since, Date.now());
expect(taker.lastRun(test2)).to.not.exist();
expect(taker.lastRun(function() {})).to.not.exist();
expect(taker.lastRun.bind(taker, 'notexists')).to.throw(Error);
expect(taker.lastRun('test1')).toExist();
expect(taker.lastRun('test1')).toBeLessThanOrEqualTo(Date.now());
expect(taker.lastRun(test2)).toNotExist();
expect(taker.lastRun(function() {})).toNotExist();
expect(taker.lastRun.bind(taker, 'notexists')).toThrow(Error);
done(err);
});
});

it('should record all tasks time execution', function(done) {
var since = Date.now();
taker.parallel('test1', test2)(function(err) {
expect(taker.lastRun('test1')).to.exist();
expect(taker.lastRun('test1')).to.be.within(since, Date.now());
expect(taker.lastRun(test2)).to.exist();
expect(taker.lastRun(test2)).to.be.within(since, Date.now());
expect(taker.lastRun('test1')).toExist();
expect(taker.lastRun('test1')).toBeLessThanOrEqualTo(Date.now());
expect(taker.lastRun(test2)).toExist();
expect(taker.lastRun(test2)).toBeLessThanOrEqualTo(Date.now());
done(err);
});
});

it('should record same tasks time execution for a string task and its original', function(done) {
taker.series(test2)(function(err) {
expect(taker.lastRun(test2)).to.equal(taker.lastRun('test2'));
expect(taker.lastRun(test2)).toEqual(taker.lastRun('test2'));
done(err);
});
});

it('should record tasks time execution for an aliased task', function(done) {
taker.series('alias')(function(err) {
expect(taker.lastRun('alias')).to.equal(taker.lastRun('test1'));
expect(taker.lastRun('alias')).toEqual(taker.lastRun('test1'));
done(err);
});
});
Expand All @@ -105,7 +97,7 @@ describe('lastRun', function() {
var expected = since - (since % resolution);

taker.series('test1')(function() {
expect(taker.lastRun('test1', resolution)).to.equal(expected);
expect(taker.lastRun('test1', resolution)).toEqual(expected);
done();
});
});
Expand All @@ -115,8 +107,8 @@ describe('lastRun', function() {
// To keep the test from catching the emitted errors
});
taker.series('error')(function(err) {
expect(err).to.exist();
expect(taker.lastRun('error')).to.not.exist();
expect(err).toExist();
expect(taker.lastRun('error')).toNotExist();
done();
});
});
Expand Down
25 changes: 10 additions & 15 deletions test/parallel.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;

var describe = lab.describe;
var it = lab.it;
var beforeEach = lab.beforeEach;
var expect = require('expect');

var Undertaker = require('../');

Expand Down Expand Up @@ -41,29 +36,29 @@ describe('parallel', function() {

it('should take all string names', function(done) {
taker.parallel('test1', 'test2', 'test3')(function(err, results) {
expect(results).to.deep.equal([1, 2, 3]);
expect(results).toEqual([1, 2, 3]);
done(err);
});
});

it('should take all functions', function(done) {
taker.parallel(fn1, fn2, fn3)(function(err, results) {
expect(results).to.deep.equal([1, 2, 3]);
expect(results).toEqual([1, 2, 3]);
done(err);
});
});

it('should take string names and functions', function(done) {
taker.parallel('test1', fn2, 'test3')(function(err, results) {
expect(results).to.deep.equal([1, 2, 3]);
expect(results).toEqual([1, 2, 3]);
done(err);
});
});

it('should take nested parallel', function(done) {
var parallel1 = taker.parallel('test1', 'test2', 'test3');
taker.parallel('test1', parallel1, 'test3')(function(err, results) {
expect(results).to.deep.equal([1, [1, 2, 3], 3]);
expect(results).toEqual([1, [1, 2, 3], 3]);
done(err);
});
});
Expand All @@ -73,8 +68,8 @@ describe('parallel', function() {
// To keep the test from catching the emitted errors
});
taker.parallel('test1', 'error', 'test3')(function(err, results) {
expect(err).to.be.an.instanceof(Error);
expect(results).to.deep.equal([1, undefined, undefined]);
expect(err).toBeAn(Error);
expect(results).toEqual([1, undefined, undefined]);
done();
});
});
Expand All @@ -84,7 +79,7 @@ describe('parallel', function() {
taker.parallel('unregistered');
}

expect(unregistered).to.throw('Task never defined: unregistered');
expect(unregistered).toThrow('Task never defined: unregistered');
done();
});

Expand All @@ -94,8 +89,8 @@ describe('parallel', function() {
});
taker._settle = true;
taker.parallel(taker.parallel('test1', 'error'), 'test3')(function(err, results) {
expect(err[0][0]).to.be.an.instanceof(Error);
expect(results).to.deep.equal([3]);
expect(err[0][0]).toBeAn(Error);
expect(results).toEqual([3]);
done();
});
});
Expand Down
Loading

0 comments on commit e3901ed

Please sign in to comment.