-
-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support for NodeJS 15, fixes #732
- Loading branch information
Showing
7 changed files
with
48 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getPerformance } from './performance' | ||
|
||
describe('performance', () => { | ||
let globalPerformance: Performance | ||
beforeEach(() => { | ||
globalPerformance = global.performance | ||
}) | ||
afterEach(() => { | ||
global.performance = globalPerformance | ||
delete (global as any).window | ||
}) | ||
it('should use global.performance if exist', () => { | ||
const performance = {} as any as Performance | ||
global.performance = performance | ||
expect(getPerformance()).toEqual(performance) | ||
}) | ||
it('should use window.performance if exist', () => { | ||
const performance = {} as any as Performance | ||
delete (global as any).performance | ||
global.window = { performance } as any | ||
expect(getPerformance()).toEqual(performance) | ||
}) | ||
it('should use polyfill if no window/global.performance', () => { | ||
delete (global as any).performance | ||
const now = getPerformance().now() | ||
expect(Number.isInteger(now)).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
interface LiquidPerformance { | ||
now: () => number | ||
} | ||
|
||
const polyfill: LiquidPerformance = { | ||
now: () => Date.now() | ||
} | ||
|
||
export function getPerformance (): LiquidPerformance { | ||
return (typeof global === 'object' && global.performance) || | ||
(typeof window === 'object' && window.performance) || | ||
polyfill | ||
} |