Skip to content

Commit

Permalink
Removed browser testing
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Mar 19, 2017
1 parent c9b1fd3 commit e818c35
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 225 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"scripts": {
"precommit": "lint-staged",
"lint": "eslint lib/* bin/*",
"test": "mocha test/index.js",
"test-browser": "serve ./test"
"test": "mocha test.js"
},
"eslintConfig": {
"extends": "eslint:recommended",
Expand All @@ -33,7 +32,6 @@
"expect.js": "0.3.1",
"husky": "0.13.2",
"lint-staged": "3.4.0",
"mocha": "3.0.2",
"serve": "5.0.4"
"mocha": "3.0.2"
}
}
221 changes: 221 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/* eslint-disable no-undef */
/**
* Dependencies.
*/

if (typeof require !== 'undefined') {
expect = require('expect.js');
ms = require('./');
}

// strings

describe('ms(string)', function() {
it('should not throw an error', function() {
expect(function() {
ms('1m');
}).to.not.throwError();
});

it('should preserve ms', function() {
expect(ms('100')).to.be(100);
});

it('should convert from m to ms', function() {
expect(ms('1m')).to.be(60000);
});

it('should convert from h to ms', function() {
expect(ms('1h')).to.be(3600000);
});

it('should convert d to ms', function() {
expect(ms('2d')).to.be(172800000);
});

it('should convert s to ms', function() {
expect(ms('1s')).to.be(1000);
});

it('should convert ms to ms', function() {
expect(ms('100ms')).to.be(100);
});

it('should work with decimals', function() {
expect(ms('1.5h')).to.be(5400000);
});

it('should work with multiple spaces', function() {
expect(ms('1 s')).to.be(1000);
});

it('should return NaN if invalid', function() {
expect(isNaN(ms('☃'))).to.be(true);
});

it('should be case-insensitive', function() {
expect(ms('1.5H')).to.be(5400000);
});

it('should work with numbers starting with .', function() {
expect(ms('.5ms')).to.be(0.5);
});
});

// long strings

describe('ms(long string)', function() {
it('should not throw an error', function() {
expect(function() {
ms('53 milliseconds');
}).to.not.throwError();
});

it('should convert milliseconds to ms', function() {
expect(ms('53 milliseconds')).to.be(53);
});

it('should convert msecs to ms', function() {
expect(ms('17 msecs')).to.be(17);
});

it('should convert sec to ms', function() {
expect(ms('1 sec')).to.be(1000);
});

it('should convert from min to ms', function() {
expect(ms('1 min')).to.be(60000);
});

it('should convert from hr to ms', function() {
expect(ms('1 hr')).to.be(3600000);
});

it('should convert days to ms', function() {
expect(ms('2 days')).to.be(172800000);
});

it('should work with decimals', function() {
expect(ms('1.5 hours')).to.be(5400000);
});
});

// numbers

describe('ms(number, { long: true })', function() {
it('should not throw an error', function() {
expect(function() {
ms(500, { long: true });
}).to.not.throwError();
});

it('should support milliseconds', function() {
expect(ms(500, { long: true })).to.be('500 ms');
});

it('should support seconds', function() {
expect(ms(1000, { long: true })).to.be('1 second');
expect(ms(1200, { long: true })).to.be('1 second');
expect(ms(10000, { long: true })).to.be('10 seconds');
});

it('should support minutes', function() {
expect(ms(60 * 1000, { long: true })).to.be('1 minute');
expect(ms(60 * 1200, { long: true })).to.be('1 minute');
expect(ms(60 * 10000, { long: true })).to.be('10 minutes');
});

it('should support hours', function() {
expect(ms(60 * 60 * 1000, { long: true })).to.be('1 hour');
expect(ms(60 * 60 * 1200, { long: true })).to.be('1 hour');
expect(ms(60 * 60 * 10000, { long: true })).to.be('10 hours');
});

it('should support days', function() {
expect(ms(24 * 60 * 60 * 1000, { long: true })).to.be('1 day');
expect(ms(24 * 60 * 60 * 1200, { long: true })).to.be('1 day');
expect(ms(24 * 60 * 60 * 10000, { long: true })).to.be('10 days');
});

it('should round', function() {
expect(ms(234234234, { long: true })).to.be('3 days');
});
});

// numbers

describe('ms(number)', function() {
it('should not throw an error', function() {
expect(function() {
ms(500);
}).to.not.throwError();
});

it('should support milliseconds', function() {
expect(ms(500)).to.be('500ms');
});

it('should support seconds', function() {
expect(ms(1000)).to.be('1s');
expect(ms(10000)).to.be('10s');
});

it('should support minutes', function() {
expect(ms(60 * 1000)).to.be('1m');
expect(ms(60 * 10000)).to.be('10m');
});

it('should support hours', function() {
expect(ms(60 * 60 * 1000)).to.be('1h');
expect(ms(60 * 60 * 10000)).to.be('10h');
});

it('should support days', function() {
expect(ms(24 * 60 * 60 * 1000)).to.be('1d');
expect(ms(24 * 60 * 60 * 10000)).to.be('10d');
});

it('should round', function() {
expect(ms(234234234)).to.be('3d');
});
});

// invalid inputs

describe('ms(invalid inputs)', function() {
it('should throw an error, when ms("")', function() {
expect(function() {
ms('');
}).to.throwError();
});

it('should throw an error, when ms(undefined)', function() {
expect(function() {
ms(undefined);
}).to.throwError();
});

it('should throw an error, when ms(null)', function() {
expect(function() {
ms(null);
}).to.throwError();
});

it('should throw an error, when ms([])', function() {
expect(function() {
ms([]);
}).to.throwError();
});

it('should throw an error, when ms({})', function() {
expect(function() {
ms({});
}).to.throwError();
});

it('should throw an error, when ms(NaN)', function() {
expect(function() {
ms(NaN);
}).to.throwError();
});
});
Loading

0 comments on commit e818c35

Please sign in to comment.