From f6b039426cbf8775c4c05973e8356b34640decd5 Mon Sep 17 00:00:00 2001 From: Ilya Radchenko Date: Thu, 5 Feb 2015 16:18:44 -0500 Subject: [PATCH] Update to use tape Funny behavior with the mocha test runner, globals not so good.. --- package.json | 14 +++--- test/index.js | 5 ++ test/interval.js | 121 ++++++++++++++++++++++++++++------------------- test/math.js | 21 ++++---- 4 files changed, 98 insertions(+), 63 deletions(-) create mode 100644 test/index.js diff --git a/package.json b/package.json index 8a5a176..1c14c5d 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,11 @@ "name": "interval", "version": "0.0.9", "description": "Converts common units of time to milliseconds", + "author": "J. Jordan ", + "main": "./lib/interval.js", + "scripts": { + "test": "node test | tap-spec" + }, "keywords": [ "interval", "timespan", @@ -21,14 +26,9 @@ "lib": "./lib", "test": "./test" }, - "author": "J. Jordan ", - "main": "./lib/interval.js", - "scripts": { - "test": "mocha" - }, "devDependencies": { - "mocha": "*", - "expect.js": "*" + "tap-spec": "^2.2.0", + "tape": "^3.5.0" }, "engines": { "node": ">= 0.4.0", diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..3ba916c --- /dev/null +++ b/test/index.js @@ -0,0 +1,5 @@ +'use strict'; + +// run tests +require('./interval'); +require('./math'); diff --git a/test/interval.js b/test/interval.js index 6c032c1..dc262b7 100644 --- a/test/interval.js +++ b/test/interval.js @@ -1,91 +1,116 @@ -var expect = require('expect.js'); -var interval = require('../'); - -describe('interval', function() { +'use strict'; - // zero undefined properties - function create(i) { - var props = ['days', 'hours', 'minutes', 'seconds', 'milliseconds']; - props.forEach(function(prop) { - if (!i[prop]) { - i[prop] = 0; - } - }); - return i; - } +var test = require('tape'); +var interval = require('../'); - it('should convert days property to milliseconds', function() { - expect(interval({ days: 4 })).to.be(4 * 24 * 60 * 60 * 1000); +test('interval', function (t) { + t.test('should convert days property to milliseconds', function (n) { + n.equal(interval({ days: 4 }), 4 * 24 * 60 * 60 * 1000); + n.end(); }); - it('should convert hours property to milliseconds', function() { - expect(interval({ hours: 2 })).to.be(2 * 60 * 60 * 1000); + t.test('should convert hours property to milliseconds', function (n) { + n.equal(interval({ hours: 2 }), 2 * 60 * 60 * 1000); + n.end(); }); - it('should convert minutes property to milliseconds', function() { - expect(interval({ minutes: 6 })).to.be(6 * 60 * 1000); + t.test('should convert minutes property to milliseconds', function (n) { + n.equal(interval({ minutes: 6 }), 6 * 60 * 1000); + n.end(); }); - it('should convert seconds property to milliseconds', function() { - expect(interval({ seconds: 25 })).to.be(25 * 1000); + t.test('should convert seconds property to milliseconds', function (n) { + n.equal(interval({ seconds: 25 }), 25 * 1000); + n.end(); }); - it('should convert milliseconds property to milliseconds', function() { - expect(interval({ milliseconds: 25 })).to.be(25); + t.test('should convert milliseconds property to milliseconds', function (n) { + n.equal(interval({ milliseconds: 25 }), 25); + n.end(); }); - it('should convert composite units to milliseconds', function() { + t.test('should convert composite units to milliseconds', function (n) { var actual = interval({ hours: 7, milliseconds: 43 }); - expect(actual).to.be(7 * 60 * 60 * 1000 + 43); + + n.equal(actual, 7 * 60 * 60 * 1000 + 43); + n.end(); }); - it('should return numeric parameter as milliseconds', function() { - expect(interval(852)).to.be(852); + t.test('should return numeric parameter as milliseconds', function (n) { + n.equal(interval(852), 852); + n.end(); }); - it('should stringify hours', function() { - expect(interval.stringify({ hours: 1 })).to.be('1 hours'); + t.test('should stringify hours', function (n) { + n.equal(interval.stringify({ hours: 1 }), '1 hours'); + n.end(); }); - it('should stringify minutes', function() { - expect(interval.stringify({ minutes: 1 })).to.be('1 minutes'); + t.test('should stringify minutes', function (n) { + n.equal(interval.stringify({ minutes: 1 }), '1 minutes'); + n.end(); }); - it('should build object from milliseconds', function() { + t.test('should build object from milliseconds', function (n) { var actual = interval.fromMilliseconds((50 * 1000) + 40); var expected = create({ seconds: 50, milliseconds: 40 }); - expect(actual).to.eql(expected); + + n.same(actual, expected); + n.end(); }); - it('should normalize over accounted units', function() { + t.test('should normalize over accounted units', function (n) { var source = { seconds: 75 }; var expected = create({ minutes: 1, seconds: 15 }); - expect(interval.normalize(source)).to.eql(expected); + + n.same(interval.normalize(source), expected); + n.end(); }); - it('should add interval to date', function() { + t.test('should add interval to date', function (n) { var date = new Date(2000, 1, 2); - var actual = interval.add(date, {days: 1}); + var actual = interval.add(date, { days: 1 }); var expected = new Date(2000, 1, 3); - expect(actual).to.eql(expected); + + n.same(actual, expected); + n.end(); }); - it('should add negative interval to date', function() { + t.test('should add negative interval to date', function (n) { var date = new Date(2000, 1, 2); - var actual = interval.add(date, {days: -1}); + var actual = interval.add(date, { days: -1 }); var expected = new Date(2000, 1, 1); - expect(actual).to.eql(expected); + + n.same(actual, expected); + n.end(); }); - it('should subtract interval from date', function() { + t.test('should subtract interval from date', function (n) { var date = new Date(2100, 5, 10); - var actual = interval.subtract(date, {days: 7}); + var actual = interval.subtract(date, { days: 7 }); var expected = new Date(2100, 5, 3); - expect(actual).to.eql(expected); + + n.same(actual, expected); + n.end(); }); - it('should add intervals', function() { - var actual = interval.add({hours: 5}, {days: 7}); - expect(actual).to.eql(interval({hours: 5, days: 7})); + t.test('should add intervals', function (n) { + var actual = interval.add({ hours: 5 }, { days: 7 }); + + n.equal(actual, interval({ hours: 5, days: 7 })); + n.end(); }); }); + +// zero undefined properties +function create(i) { + var props = ['days', 'hours', 'minutes', 'seconds', 'milliseconds']; + + props.forEach(function(prop) { + if (!i[prop]) { + i[prop] = 0; + } + }); + + return i; +} diff --git a/test/math.js b/test/math.js index 078e5ed..ee01664 100644 --- a/test/math.js +++ b/test/math.js @@ -1,15 +1,20 @@ -var expect = require('expect.js'); -var math = require('../lib/math'); +'use strict'; -describe('math', function () { +var test = require('tape'); +var math = require('../lib/math'); - it('should divide evenly', function () { +test('math', function (t) { + t.test('should divide evenly', function (n) { var result = math.integerDivision(100, 10); - expect(result).to.eql({ quotient: 10, remainder: 0}); + + n.same(result, { quotient: 10, remainder: 0 }); + n.end(); }); - - it('should have remainder', function () { + + t.test('should have remainder', function (n) { var result = math.integerDivision(15, 10); - expect(result).to.eql({ quotient: 1, remainder: 5}); + + n.same(result, { quotient: 1, remainder: 5 }); + n.end(); }); });