From ae6a562a3c0ee3aefd8cd937aa6ab8d6141b9277 Mon Sep 17 00:00:00 2001 From: hustcc Date: Sun, 21 Apr 2024 09:50:47 +0800 Subject: [PATCH] fix: performance now (#32) * fix: performance now * chore: update node version * chore: update test --- .github/workflows/build.yml | 13 ++++++++++++- __tests__/index.js | 16 ---------------- package.json | 2 +- src/index.js | 2 -- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 710a33c..1bb7e60 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,6 +9,17 @@ 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 @@ -16,7 +27,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v3 with: - node-version: 13 + node-version: ${{ matrix.node-version }} - name: Install Dependencies run: npm install diff --git a/__tests__/index.js b/__tests__/index.js index f6c2174..4a0b196 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -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); @@ -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); diff --git a/package.json b/package.json index 77d102d..ae1c74c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index 9a8c2a0..3be0e7a 100644 --- a/src/index.js +++ b/src/index.js @@ -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__;