From e818c3581aca3119c00d81901bfe8fe653bcfda4 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:34:08 +0100 Subject: [PATCH] Removed browser testing --- package.json | 6 +- test.js | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/index.js | 221 -------------------------------------------------- 3 files changed, 223 insertions(+), 225 deletions(-) create mode 100644 test.js delete mode 100644 test/index.js diff --git a/package.json b/package.json index 8b508e3..4d03b7a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/test.js b/test.js new file mode 100644 index 0000000..9b437f4 --- /dev/null +++ b/test.js @@ -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(); + }); +}); diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 31b23f9..0000000 --- a/test/index.js +++ /dev/null @@ -1,221 +0,0 @@ -/* 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() - }) -})