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 May 17, 2016
1 parent 7b66aab commit 7d40dfb
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 52 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
sudo: false

language: node_js

node_js:
- '0.10'
- '6'
- '5'
- '4'
- '0.12'
- 'stable'
- '0.10'
after_script:
- npm run coveralls
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
"LICENSE"
],
"scripts": {
"lint": "eslint . && jscs *.js test/",
"test": "lab -cv"
"lint": "eslint . && jscs index.js test/",
"pretest": "npm run lint",
"test": "mocha --async-only",
"cover": "istanbul cover _mocha --report lcovonly",
"coveralls": "npm run cover && istanbul-coveralls"
},
"dependencies": {
"end-of-stream": "^1.1.0",
Expand All @@ -29,12 +32,14 @@
"stream-exhaust": "^1.0.1"
},
"devDependencies": {
"code": "^1.4.1",
"eslint": "^1.7.3",
"eslint-config-gulp": "^2.0.0",
"expect": "^1.19.0",
"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",
"rx": "^4.0.6",
"through2": "^2.0.0",
"when": "^3.7.3"
Expand Down
9 changes: 3 additions & 6 deletions test/arguments.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

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

Expand All @@ -15,8 +12,8 @@ describe('arguments', function() {

it('passes all arguments to the completion callback', function(done) {
asyncDone(twoArg, function(err, arg1, arg2) {
expect(arg1).to.equal(1);
expect(arg2).to.equal(2);
expect(arg1).toEqual(1);
expect(arg2).toEqual(2);
done(err);
});
});
Expand Down
11 changes: 4 additions & 7 deletions test/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

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

Expand All @@ -23,14 +20,14 @@ describe('callbacks', function() {

it('should handle a successful callback', function(done) {
asyncDone(success, function(err, result) {
expect(result).to.equal(2);
expect(result).toEqual(2);
done(err);
});
});

it('should handle an errored callback', function(done) {
asyncDone(failure, function(err) {
expect(err).to.be.instanceof(Error);
expect(err).toBeAn(Error);
done();
});
});
Expand All @@ -48,7 +45,7 @@ describe('callbacks', function() {
it('should not handle error if something throws inside the callback', function(done) {
var d = require('domain').create();
d.on('error', function(err) {
expect(err).to.be.instanceof(Error);
expect(err).toBeAn(Error);
done();
});

Expand Down
13 changes: 5 additions & 8 deletions test/child_processes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

var cp = require('child_process');
var asyncDone = require('../');
Expand All @@ -28,28 +25,28 @@ function spawnFail() {
describe('child processes', function() {
it('should handle successful exec', function(done) {
asyncDone(execSuccess, function(err) {
expect(err).to.not.be.instanceof(Error);
expect(err).toNotBeAn(Error);
done();
});
});

it('should handle failing exec', function(done) {
asyncDone(execFail, function(err) {
expect(err).to.be.an.instanceof(Error);
expect(err).toBeAn(Error);
done();
});
});

it('should handle successful spawn', function(done) {
asyncDone(spawnSuccess, function(err) {
expect(err).to.not.be.instanceof(Error);
expect(err).toNotBeAn(Error);
done();
});
});

it('should handle failing spawn', function(done) {
asyncDone(spawnFail, function(err) {
expect(err).to.be.an.instanceof(Error);
expect(err).toBeAn(Error);
done();
});
});
Expand Down
11 changes: 4 additions & 7 deletions test/observables.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

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

Expand All @@ -25,21 +22,21 @@ describe('observables', function() {

it('should handle a finished observable', function(done) {
asyncDone(success, function(err, result) {
expect(result).to.equal(undefined);
expect(result).toEqual(undefined);
done(err);
});
});

it('should handle a finished observable with value', function(done) {
asyncDone(successValue, function(err, result) {
expect(result).to.equal(42);
expect(result).toEqual(42);
done(err);
});
});

it('should handle an errored observable', function(done) {
asyncDone(failure, function(err) {
expect(err).to.be.instanceof(Error);
expect(err).toBeAn(Error);
done();
});
});
Expand Down
9 changes: 3 additions & 6 deletions test/promises.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

var when = require('when');

Expand All @@ -21,14 +18,14 @@ describe('promises', function() {

it('should handle a resolved promise', function(done) {
asyncDone(success, function(err, result) {
expect(result).to.equal(2);
expect(result).toEqual(2);
done(err);
});
});

it('should handle a rejected promise', function(done) {
asyncDone(failure, function(err) {
expect(err).to.be.instanceof(Error);
expect(err).toBeAn(Error);
done();
});
});
Expand Down
16 changes: 6 additions & 10 deletions test/streams.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
'use strict';

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

var fs = require('fs');
var cp = require('child_process');
var path = require('path');
var through = require('through2');

Expand Down Expand Up @@ -40,14 +36,14 @@ function unpiped() {
describe('streams', function() {
it('should handle a successful stream', function(done) {
asyncDone(success, function(err) {
expect(err).to.not.be.instanceof(Error);
expect(err).toNotBeAn(Error);
done();
});
});

it('should handle an errored stream', function(done) {
asyncDone(failure, function(err) {
expect(err).to.be.instanceof(Error);
expect(err).toBeAn(Error);
done();
});
});
Expand All @@ -58,15 +54,15 @@ describe('streams', function() {
cb(null, 3);
});
}, function(err, result) {
expect(err).to.not.be.instanceof(Error);
expect(result).to.equal(3); // To know we called the callback
expect(err).toNotBeAn(Error);
expect(result).toEqual(3); // To know we called the callback
done();
});
});

it('consumes an unpiped readable stream', function(done) {
asyncDone(unpiped, function(err) {
expect(err).to.not.be.instanceof(Error);
expect(err).toNotBeAn(Error);
done();
});
});
Expand Down

0 comments on commit 7d40dfb

Please sign in to comment.