Skip to content

Commit

Permalink
fix: performance now (#32)
Browse files Browse the repository at this point in the history
* fix: performance now

* chore: update node version

* chore: update test
  • Loading branch information
hustcc authored Apr 21, 2024
1 parent 2f9cd69 commit ae6a562
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ concurrency:
jobs:
test-and-build:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
node-version:
- 12
- 13
- 14
- 15
- 16
- 17
- 18
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 13
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm install
Expand Down
16 changes: 0 additions & 16 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ describe('jest-date-mock', () => {
expect(+new Date().constructor(10000)).toBe(10000);
expect(new Date().constructor(10000)).toBeInstanceOf(Date);


// +
expect(+new Date()).toBe(0);
expect(+new Date(10000)).toBe(10000);


// getTime
expect(new Date().getTime()).toBe(0);
expect(new Date(10000).getTime()).toBe(10000);
Expand Down Expand Up @@ -61,20 +59,6 @@ describe('jest-date-mock', () => {
expect(Date.now()).toBe(520);
});

test('performance.now', () => {
const performance = global.window ?
global.window.performance : require('perf_hooks').performance;

advanceTo(1000);
expect(performance.now()).toBe(1000);

advanceTo();
expect(performance.now()).toBe(0);

advanceBy(520);
expect(performance.now()).toBe(520);
});

test('Date.current', () => {
advanceTo();
expect(Date.now()).toBe(0);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-date-mock",
"version": "1.0.9",
"version": "1.0.10",
"description": "Mock `window.Date` when run unit test cases with jest. Make tests of `Date` easier.",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const dateClass = mockDateClass(Date);
if (global.window) {
// dom env
global.window.Date = dateClass;
global.window.performance.now = function() { return dateClass.now(); };
} else {
// node / native env
global.Date = dateClass;
require('perf_hooks').performance.now = function() { return dateClass.now(); };
}

export const version = __VERSION__;

0 comments on commit ae6a562

Please sign in to comment.