Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use jest instead of mocha #9

Merged
merged 11 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,21 @@
"scripts": {
"build": "npm run clean && tsc",
"clean": "rimraf -rf lib",
"test": "cross-env NODE_ENV=test nyc mocha test/*.spec.ts --exit --timeout 10000",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"test": "jest",
"coverage": "jest && codecov",
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"@types/jest": "^23.3.12",
"@types/node": "^10.9.4",
"chai": "^4.1.2",
"codecov": "^3.1.0",
"cross-env": "^5.2.0",
"husky": "^1.2.1",
"mocha": "^5.2.0",
"jest": "^23.6.0",
"moment": "^2.23.0",
"nyc": "^13.0.1",
"rimraf": "^2.6.2",
"source-map-support": "^0.5.9",
"ts-jest": "^23.10.5",
"ts-node": "^7.0.1",
"tslint": "^5.10.0",
"tslint-eslint-rules": "^5.3.1",
Expand All @@ -60,20 +58,37 @@
"pre-commit": "npm test"
}
},
"nyc": {
"check-coverage": true,
"include": [
"src/*.ts"
"jest": {
"roots": [
"test"
],
"extension": [
".ts"
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "test/.*\\.spec\\.(ts|tsx)$",
"moduleDirectories": [
"node_modules",
"src"
],
"require": [
"ts-node/register",
"source-map-support/register"
"moduleFileExtensions": [
"ts",
"tsx",
"js",
whatwewant marked this conversation as resolved.
Show resolved Hide resolved
"jsx"
],
"sourceMap": true,
"instrument": true
"coverageDirectory": "./coverage/",
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.{ts,tsx}"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 90,
"lines": 90,
"statements": -10
}
}
},
"publishConfig": {
"access": "public"
Expand Down
73 changes: 35 additions & 38 deletions test/add.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { expect } from 'chai';
import * as moment from 'moment';
import { Moment } from '../src';

Expand All @@ -9,177 +8,175 @@ describe('add', () => {

it('year', () => {
expect(momentjs(now).add(5, 'year').valueOf())
.to.be.equal(moment(now).add(5, 'year').valueOf());
.toBe(moment(now).add(5, 'year').valueOf());
});

it('month: 3', () => {
expect(momentjs(now).add(3, 'month').valueOf())
.to.be.equal(moment(now).add(3, 'month').valueOf());
.toBe(moment(now).add(3, 'month').valueOf());
});

it('month: 18', () => {
expect(momentjs(now).add(18, 'month').valueOf())
.to.be.equal(moment(now).add(18, 'month').valueOf());
.toBe(moment(now).add(18, 'month').valueOf());
});

it('month: 128', () => {
expect(momentjs(now).add(128, 'month').valueOf())
.to.be.equal(moment(now).add(128, 'month').valueOf());
.toBe(moment(now).add(128, 'month').valueOf());
});

it('day: 1', () => {
console.log(momentjs(now).add(1, 'day').valueOf());
console.log(moment(now).add(1, 'day').valueOf());
expect(momentjs(now).add(1, 'day').valueOf())
.to.be.equal(moment(now).add(1, 'day').valueOf());
.toBe(moment(now).add(1, 'day').valueOf());
});

it('day: 8', () => {
expect(momentjs(now).add(8, 'day').valueOf())
.to.be.equal(moment(now).add(8, 'day').valueOf());
.toBe(moment(now).add(8, 'day').valueOf());
});

it('day: 88', () => {
expect(momentjs(now).add(88, 'day').valueOf())
.to.be.equal(moment(now).add(88, 'day').valueOf());
.toBe(moment(now).add(88, 'day').valueOf());
});

it('day: 888', () => {
expect(momentjs(now).add(888, 'day').valueOf())
.to.be.equal(moment(now).add(888, 'day').valueOf());
.toBe(moment(now).add(888, 'day').valueOf());
});

it('day: 8888', () => {
expect(momentjs(now).add(8888, 'day').valueOf())
.to.be.equal(moment(now).add(8888, 'day').valueOf());
.toBe(moment(now).add(8888, 'day').valueOf());
});

it('hour: 1', () => {
expect(momentjs(now).add(1, 'hour').valueOf())
.to.be.equal(moment(now).add(1, 'hour').valueOf());
.toBe(moment(now).add(1, 'hour').valueOf());
});

it('hour: 8', () => {
expect(momentjs(now).add(8, 'hour').valueOf())
.to.be.equal(moment(now).add(8, 'hour').valueOf());
.toBe(moment(now).add(8, 'hour').valueOf());
});

it('hour: 88', () => {
expect(momentjs(now).add(88, 'hour').valueOf())
.to.be.equal(moment(now).add(88, 'hour').valueOf());
.toBe(moment(now).add(88, 'hour').valueOf());
});

it('hour: 888', () => {
expect(momentjs(now).add(888, 'hour').valueOf())
.to.be.equal(moment(now).add(888, 'hour').valueOf());
.toBe(moment(now).add(888, 'hour').valueOf());
});

it('hour: 8888', () => {
expect(momentjs(now).add(8888, 'hour').valueOf())
.to.be.equal(moment(now).add(8888, 'hour').valueOf());
.toBe(moment(now).add(8888, 'hour').valueOf());
});

it('minute: 1', () => {
expect(momentjs(now).add(1, 'minute').valueOf())
.to.be.equal(moment(now).add(1, 'minute').valueOf());
.toBe(moment(now).add(1, 'minute').valueOf());
});

it('minute: 8', () => {
expect(momentjs(now).add(8, 'minute').valueOf())
.to.be.equal(moment(now).add(8, 'minute').valueOf());
.toBe(moment(now).add(8, 'minute').valueOf());
});

it('minute: 88', () => {
expect(momentjs(now).add(88, 'minute').valueOf())
.to.be.equal(moment(now).add(88, 'minute').valueOf());
.toBe(moment(now).add(88, 'minute').valueOf());
});

it('minute: 888', () => {
expect(momentjs(now).add(888, 'minute').valueOf())
.to.be.equal(moment(now).add(888, 'minute').valueOf());
.toBe(moment(now).add(888, 'minute').valueOf());
});

it('minute: 8888', () => {
expect(momentjs(now).add(8888, 'minute').valueOf())
.to.be.equal(moment(now).add(8888, 'minute').valueOf());
.toBe(moment(now).add(8888, 'minute').valueOf());
});

it('second: 1', () => {
expect(momentjs(now).add(1, 'second').valueOf())
.to.be.equal(moment(now).add(1, 'second').valueOf());
.toBe(moment(now).add(1, 'second').valueOf());
});

it('second: 8', () => {
expect(momentjs(now).add(8, 'second').valueOf())
.to.be.equal(moment(now).add(8, 'second').valueOf());
.toBe(moment(now).add(8, 'second').valueOf());
});

it('second: 88', () => {
expect(momentjs(now).add(88, 'second').valueOf())
.to.be.equal(moment(now).add(88, 'second').valueOf());
.toBe(moment(now).add(88, 'second').valueOf());
});

it('second: 888', () => {
expect(momentjs(now).add(888, 'second').valueOf())
.to.be.equal(moment(now).add(888, 'second').valueOf());
.toBe(moment(now).add(888, 'second').valueOf());
});

it('second: 8888', () => {
expect(momentjs(now).add(8888, 'second').valueOf())
.to.be.equal(moment(now).add(8888, 'second').valueOf());
.toBe(moment(now).add(8888, 'second').valueOf());
});

it('millisecond: 1', () => {
expect(momentjs(now).add(1, 'millisecond').valueOf())
.to.be.equal(moment(now).add(1, 'millisecond').valueOf());
.toBe(moment(now).add(1, 'millisecond').valueOf());
});

it('millisecond: 8', () => {
expect(momentjs(now).add(8, 'millisecond').valueOf())
.to.be.equal(moment(now).add(8, 'millisecond').valueOf());
.toBe(moment(now).add(8, 'millisecond').valueOf());
});

it('millisecond: 88', () => {
expect(momentjs(now).add(88, 'millisecond').valueOf())
.to.be.equal(moment(now).add(88, 'millisecond').valueOf());
.toBe(moment(now).add(88, 'millisecond').valueOf());
});

it('millisecond: 888', () => {
expect(momentjs(now).add(888, 'millisecond').valueOf())
.to.be.equal(moment(now).add(888, 'millisecond').valueOf());
.toBe(moment(now).add(888, 'millisecond').valueOf());
});

it('millisecond: 8888', () => {
expect(momentjs(now).add(8888, 'millisecond').valueOf())
.to.be.equal(moment(now).add(8888, 'millisecond').valueOf());
.toBe(moment(now).add(8888, 'millisecond').valueOf());
});

it('week: 1', () => {
expect(momentjs(now).add(1, 'week').valueOf())
.to.be.equal(moment(now).add(1, 'week').valueOf());
.toBe(moment(now).add(1, 'week').valueOf());
});

it('week: 8', () => {
expect(momentjs(now).add(8, 'week').valueOf())
.to.be.equal(moment(now).add(8, 'week').valueOf());
.toBe(moment(now).add(8, 'week').valueOf());
});

it('week: 88', () => {
expect(momentjs(now).add(88, 'week').valueOf())
.to.be.equal(moment(now).add(88, 'week').valueOf());
.toBe(moment(now).add(88, 'week').valueOf());
});

it('week: 888', () => {
expect(momentjs(now).add(888, 'week').valueOf())
.to.be.equal(moment(now).add(888, 'week').valueOf());
.toBe(moment(now).add(888, 'week').valueOf());
});

it('week: 8888', () => {
expect(momentjs(now).add(8888, 'week').valueOf())
.to.be.equal(moment(now).add(8888, 'week').valueOf());
.toBe(moment(now).add(8888, 'week').valueOf());
});

it('special: 20111031 + 1 month should be 20111130', () => {
expect(momentjs('20111031').add(1, 'month').valueOf()).to.be.equal(moment('20111031').add(1, 'month').valueOf())
expect(momentjs('20111031').add(1, 'month').valueOf()).toBe(moment('20111031').add(1, 'month').valueOf())
});
});
16 changes: 7 additions & 9 deletions test/endOf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { expect } from 'chai';

import { Moment } from '../src';
import { resolve } from '../src/utils';

Expand All @@ -13,54 +11,54 @@ describe('endOf', () => {
const md = momentjs(date);
const dates = md.toArray();
expect(md.endOf('year').valueOf())
.to.be.equal(+new Date(dates[0], 11, 31, 23, 59, 59, 999));
.toBe(+new Date(dates[0], 11, 31, 23, 59, 59, 999));
});

it('month', () => {
const date = new Date();
const md = momentjs(date);
const dates = md.toArray();
expect(md.endOf('month').valueOf())
.to.be.equal(+new Date(dates[0], dates[1] + 1, 0, 23, 59, 59, 999));
.toBe(+new Date(dates[0], dates[1] + 1, 0, 23, 59, 59, 999));
});

it('day', () => {
const date = new Date();
const md = momentjs(date);
const dates = md.toArray();
expect(md.endOf('day').valueOf())
.to.be.equal(+new Date(dates[0], dates[1], dates[2], 23, 59, 59, 999));
.toBe(+new Date(dates[0], dates[1], dates[2], 23, 59, 59, 999));
});

it('week', () => {
const date = new Date();
const md = momentjs(date);
const dates = md.toArray();
expect(md.endOf('week').valueOf())
.to.be.equal(+new Date(dates[0], dates[1], dates[2] - resolve(date).week + 6, 23, 59, 59, 999));
.toBe(+new Date(dates[0], dates[1], dates[2] - resolve(date).week + 6, 23, 59, 59, 999));
});

it('hour', () => {
const date = new Date();
const md = momentjs(date);
const dates = md.toArray();
expect(md.endOf('hour').valueOf())
.to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3], 59, 59, 999));
.toBe(+new Date(dates[0], dates[1], dates[2], dates[3], 59, 59, 999));
});

it('minute', () => {
const date = new Date();
const md = momentjs(date);
const dates = md.toArray();
expect(md.endOf('minute').valueOf())
.to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], 59, 999));
.toBe(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], 59, 999));
});

it('second', () => {
const date = new Date();
const md = momentjs(date);
const dates = md.toArray();
expect(md.endOf('second').valueOf())
.to.be.equal(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], dates[5], 999));
.toBe(+new Date(dates[0], dates[1], dates[2], dates[3], dates[4], dates[5], 999));
});
});
Loading