From e3901edec6bd4a9eadcd6ef81674a783d7a68936 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 22 Jun 2016 17:24:08 -0700 Subject: [PATCH] Update: Switch to mocha + expect for testing --- .travis.yml | 5 +++- package.json | 12 ++++++--- test/integration.js | 13 +++------- test/last-run.js | 40 ++++++++++++----------------- test/parallel.js | 25 ++++++++---------- test/registry.js | 62 +++++++++++++++++++++------------------------ test/series.js | 25 ++++++++---------- test/task.js | 43 ++++++++++++++----------------- test/tree.js | 19 +++++--------- 9 files changed, 107 insertions(+), 137 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0def79..0d50ecf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,10 @@ sudo: false language: node_js node_js: - - 'stable' + - '6' + - '5' - '4' - '0.12' - '0.10' +after_script: + - npm run coveralls diff --git a/package.json b/package.json index 0709333..c4249b6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/test/integration.js b/test/integration.js index 95ca4c8..cdbbb9e 100644 --- a/test/integration.js +++ b/test/integration.js @@ -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'); @@ -82,7 +77,7 @@ describe('integrations', function() { )); taker.parallel('build')(function(err) { - expect(count).to.equal(1); + expect(count).toEqual(1); done(err); }); }); @@ -108,7 +103,7 @@ describe('integrations', function() { )); taker.parallel('build')(function(err) { - expect(count).to.equal(1); + expect(count).toEqual(1); done(err); }); }); @@ -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); }); diff --git a/test/last-run.js b/test/last-run.js index dbf2497..415cf55 100644 --- a/test/last-run.js +++ b/test/last-run.js @@ -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('../'); @@ -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); }); }); @@ -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(); }); }); @@ -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(); }); }); diff --git a/test/parallel.js b/test/parallel.js index e4aef8a..ac7461b 100644 --- a/test/parallel.js +++ b/test/parallel.js @@ -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('../'); @@ -41,21 +36,21 @@ 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); }); }); @@ -63,7 +58,7 @@ describe('parallel', function() { 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); }); }); @@ -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(); }); }); @@ -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(); }); @@ -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(); }); }); diff --git a/test/registry.js b/test/registry.js index 1280b13..80bd317 100644 --- a/test/registry.js +++ b/test/registry.js @@ -1,10 +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 expect = require('expect'); var Undertaker = require('../'); @@ -40,7 +36,7 @@ describe('registry', function() { it('should return the current registry when no arguments are given', function(done) { var taker = new Undertaker(); - expect(taker.registry()).to.equal(taker._registry); + expect(taker.registry()).toEqual(taker._registry); done(); }); @@ -48,7 +44,7 @@ describe('registry', function() { var taker = new Undertaker(); var customRegistry = new CustomRegistry(); taker.registry(customRegistry); - expect(taker.registry()).to.equal(customRegistry); + expect(taker.registry()).toEqual(customRegistry); done(); }); @@ -60,7 +56,7 @@ describe('registry', function() { taker.registry(invalid); } - expect(invalidSet).to.throw(Error, 'Custom registry must have `get` function'); + expect(invalidSet).toThrow('Custom registry must have `get` function'); done(); }); @@ -69,8 +65,8 @@ describe('registry', function() { var customRegistry = new DefaultRegistry(); taker.registry(customRegistry); - expect(taker.task('clean')).to.be.a.function(); - expect(taker.task('serve')).to.be.a.function(); + expect(taker.task('clean')).toBeA('function'); + expect(taker.task('serve')).toBeA('function'); done(); }); @@ -78,21 +74,21 @@ describe('registry', function() { var taker = new Undertaker(); taker.registry(new CommonRegistry()); - expect(taker.task('clean')).to.be.a.function(); - expect(taker.task('serve')).to.be.a.function(); + expect(taker.task('clean')).toBeA('function'); + expect(taker.task('serve')).toBeA('function'); taker.registry(new MetadataRegistry()); taker.task('context', function(cb) { - expect(this).to.deep.equal({ name: 'context' }); + expect(this).toEqual({ name: 'context' }); cb(); done(); }); taker.registry(new DefaultRegistry()); - expect(taker.task('clean')).to.be.a.function(); - expect(taker.task('serve')).to.be.a.function(); - expect(taker.task('context')).to.be.a.function(); + expect(taker.task('clean')).toBeA('function'); + expect(taker.task('serve')).toBeA('function'); + expect(taker.task('context')).toBeA('function'); taker.series('context')(); }); @@ -104,7 +100,7 @@ describe('registry', function() { taker.registry(CommonRegistry); } - expect(ctor).to.throw(Error, 'Custom registries must be instantiated, but it looks like you passed a constructor'); + expect(ctor).toThrow('Custom registries must be instantiated, but it looks like you passed a constructor'); done(); }); @@ -114,9 +110,9 @@ describe('registry', function() { var ogInit = DefaultRegistry.prototype.init; DefaultRegistry.prototype.init = function(inst) { - expect(inst).to.equal(taker); - expect(inst.task('clean')).to.be.a.function(); - expect(inst.task('serve')).to.be.a.function(); + expect(inst).toEqual(taker); + expect(inst.task('clean')).toBeA('function'); + expect(inst.task('serve')).toBeA('function'); }; taker.registry(new DefaultRegistry()); @@ -129,24 +125,24 @@ describe('registry', function() { describe('constructor', function() { it('should take a custom registry on instantiation', function(done) { var taker = new Undertaker(new CustomRegistry()); - expect(taker.registry()).to.be.an.instanceof(CustomRegistry); - expect(taker.registry()).to.not.be.an.instanceof(DefaultRegistry); + expect(taker.registry()).toBeA(CustomRegistry); + expect(taker.registry()).toNotBeA(DefaultRegistry); done(); }); it('should default to undertaker-registry if not constructed with custom registry', function(done) { var taker = new Undertaker(); - expect(taker.registry()).to.be.an.instanceof(DefaultRegistry); - expect(taker.registry()).to.not.be.an.instanceof(CustomRegistry); + expect(taker.registry()).toBeA(DefaultRegistry); + expect(taker.registry()).toNotBeA(CustomRegistry); done(); }); it('should take a registry that pre-defines tasks', function(done) { var taker = new Undertaker(new CommonRegistry()); - expect(taker.registry()).to.be.an.instanceof(CommonRegistry); - expect(taker.registry()).to.be.an.instanceof(DefaultRegistry); - expect(taker.task('clean')).to.be.a.function(); - expect(taker.task('serve')).to.be.a.function(); + expect(taker.registry()).toBeA(CommonRegistry); + expect(taker.registry()).toBeA(DefaultRegistry); + expect(taker.task('clean')).toBeA('function'); + expect(taker.task('serve')).toBeA('function'); done(); }); @@ -158,28 +154,28 @@ describe('registry', function() { taker = new Undertaker(new InvalidRegistry()); } - expect(noGet).to.throw(Error, 'Custom registry must have `get` function'); + expect(noGet).toThrow('Custom registry must have `get` function'); InvalidRegistry.prototype.get = noop; function noSet() { taker = new Undertaker(new InvalidRegistry()); } - expect(noSet).to.throw(Error, 'Custom registry must have `set` function'); + expect(noSet).toThrow('Custom registry must have `set` function'); InvalidRegistry.prototype.set = noop; function noInit() { taker = new Undertaker(new InvalidRegistry()); } - expect(noInit).to.throw(Error, 'Custom registry must have `init` function'); + expect(noInit).toThrow('Custom registry must have `init` function'); InvalidRegistry.prototype.init = noop; function noTasks() { taker = new Undertaker(new InvalidRegistry()); } - expect(noTasks).to.throw(Error, 'Custom registry must have `tasks` function'); + expect(noTasks).toThrow('Custom registry must have `tasks` function'); InvalidRegistry.prototype.tasks = noop; taker = new Undertaker(new InvalidRegistry()); @@ -192,7 +188,7 @@ describe('registry', function() { taker.registry(new SetNoReturnRegistry()); taker.task('test', noop); taker.on('start', function(data) { - expect(data.name).to.equal('test'); + expect(data.name).toEqual('test'); done(); }); taker.series('test')(); diff --git a/test/series.js b/test/series.js index 4ed07d5..6b1e23b 100644 --- a/test/series.js +++ b/test/series.js @@ -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('../'); @@ -41,21 +36,21 @@ describe('series', function() { it('should take all string names', function(done) { taker.series('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.series(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.series('test1', fn2, 'test3')(function(err, results) { - expect(results).to.deep.equal([1, 2, 3]); + expect(results).toEqual([1, 2, 3]); done(err); }); }); @@ -63,7 +58,7 @@ describe('series', function() { it('should take nested series', function(done) { var series1 = taker.series('test1', 'test2', 'test3'); taker.series('test1', series1, 'test3')(function(err, results) { - expect(results).to.deep.equal([1, [1, 2, 3], 3]); + expect(results).toEqual([1, [1, 2, 3], 3]); done(err); }); }); @@ -73,8 +68,8 @@ describe('series', function() { // To keep the test from catching the emitted errors }); taker.series('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(); }); }); @@ -84,7 +79,7 @@ describe('series', function() { taker.series('unregistered'); } - expect(unregistered).to.throw('Task never defined: unregistered'); + expect(unregistered).toThrow('Task never defined: unregistered'); done(); }); @@ -94,8 +89,8 @@ describe('series', function() { }); taker._settle = true; taker.series(taker.series('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(); }); }); diff --git a/test/task.js b/test/task.js index 7c590f9..57e9abd 100644 --- a/test/task.js +++ b/test/task.js @@ -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('../'); @@ -25,20 +20,20 @@ describe('task', function() { it('should register a named function', function(done) { taker.task(noop); - expect(taker.task('noop').unwrap()).to.equal(noop); + expect(taker.task('noop').unwrap()).toEqual(noop); done(); }); it('should register an anonymous function by string name', function(done) { taker.task('test1', anon); - expect(taker.task('test1').unwrap()).to.equal(anon); + expect(taker.task('test1').unwrap()).toEqual(anon); done(); }); it('should register an anonymous function by displayName property', function(done) { anon.displayName = ''; taker.task(anon); - expect(taker.task('').unwrap()).to.equal(anon); + expect(taker.task('').unwrap()).toEqual(anon); delete anon.displayName; done(); }); @@ -48,45 +43,45 @@ describe('task', function() { taker.task(anon); } - expect(noName).to.throw(Error, 'Task name must be specified'); + expect(noName).toThrow('Task name must be specified'); done(); }); it('should register a named function by string name', function(done) { taker.task('test1', noop); - expect(taker.task('test1').unwrap()).to.equal(noop); + expect(taker.task('test1').unwrap()).toEqual(noop); done(); }); it('should not get a task that was not registered', function(done) { - expect(taker.task('test1')).to.be.undefined(); + expect(taker.task('test1')).toEqual(undefined); done(); }); it('should get a task that was registered', function(done) { taker.task('test1', noop); - expect(taker.task('test1').unwrap()).to.equal(noop); + expect(taker.task('test1').unwrap()).toEqual(noop); done(); }); it('should get the wrapped task, not original function', function(done) { var registry = taker.registry(); taker.task('test1', noop); - expect(taker.task('test1').unwrap).to.be.a.function(); - expect(taker.task('test1')).to.equal(registry.get('test1')); + expect(taker.task('test1').unwrap).toBeA('function'); + expect(taker.task('test1')).toEqual(registry.get('test1')); done(); }); it('provides an `unwrap` method to get the original function', function(done) { taker.task('test1', noop); - expect(taker.task('test1').unwrap).to.be.a.function(); - expect(taker.task('test1').unwrap()).to.equal(noop); + expect(taker.task('test1').unwrap).toBeA('function'); + expect(taker.task('test1').unwrap()).toEqual(noop); done(); }); it('should return a function that was registered in some other way', function(done) { taker.registry()._tasks.test1 = noop; - expect(taker.task('test1')).to.equal(noop); + expect(taker.task('test1')).toEqual(noop); done(); }); @@ -94,7 +89,7 @@ describe('task', function() { function fn() {} fn.displayName = 'test1'; taker.task(fn); - expect(taker.task('test1').unwrap()).to.equal(fn); + expect(taker.task('test1').unwrap()).toEqual(fn); done(); }); @@ -102,7 +97,7 @@ describe('task', function() { function fn() {} taker.task('foo', fn); taker.task('bar', fn); - expect(taker.task('foo').unwrap()).to.equal(taker.task('bar').unwrap()); + expect(taker.task('foo').unwrap()).toEqual(taker.task('bar').unwrap()); done(); }); @@ -117,13 +112,13 @@ describe('task', function() { taker.task('bar', fn); taker.series('foo', 'bar', function(cb) { - expect(count).to.equal(2); + expect(count).toEqual(2); cb(); }); taker.parallel('foo', 'bar', function(cb) { setTimeout(function(){ - expect(count).to.equal(4); + expect(count).toEqual(4); cb(); }, 500); }); @@ -149,13 +144,13 @@ describe('task', function() { taker.task('bar', taker.task('par')); taker.series('foo', function(cb) { - expect(count).to.equal(3); + expect(count).toEqual(3); cb(); }); taker.series('bar', function(cb) { setTimeout(function(){ - expect(count).to.equal(6); + expect(count).toEqual(6); cb(); }, 500); diff --git a/test/tree.js b/test/tree.js index 11a5500..63b75a1 100644 --- a/test/tree.js +++ b/test/tree.js @@ -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('../'); @@ -57,7 +52,7 @@ describe('tree', function() { var tree = taker.tree(); - expect(tree).to.deep.equal(simple); + expect(tree).toEqual(simple); done(); }); @@ -71,7 +66,7 @@ describe('tree', function() { var tree = taker.tree({ deep: true }); - expect(tree).to.deep.equal(singleLevel); + expect(tree).toEqual(singleLevel); done(); }); @@ -86,7 +81,7 @@ describe('tree', function() { var tree = taker.tree({ deep: true }); - expect(tree).to.deep.equal(doubleLevel); + expect(tree).toEqual(doubleLevel); done(); }); @@ -100,7 +95,7 @@ describe('tree', function() { var tree = taker.tree({ deep: true }); - expect(tree).to.deep.equal(tripleLevel); + expect(tree).toEqual(tripleLevel); done(); }); @@ -116,7 +111,7 @@ describe('tree', function() { var tree = taker.tree({ deep: true }); - expect(tree).to.deep.equal(aliasSimple); + expect(tree).toEqual(aliasSimple); done(); }); @@ -133,7 +128,7 @@ describe('tree', function() { var tree = taker.tree({ deep: true }); - expect(tree).to.deep.equal(aliasNested); + expect(tree).toEqual(aliasNested); done(); });