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

Polyfill Number.isFinite() to support PhantomJS #1575

Merged
merged 1 commit into from
Apr 19, 2018
Merged

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Apr 17, 2018

Description

When running npm test of loopback locally, I noticed a test failure when running on PhantomJS browser:

PhantomJS 2.1.1 (Mac OS X 0.0.0) app 
  "before each" hook for "can be read via `app.get(key)`" FAILED
	undefined is not a constructor (evaluating 'Number.isFinite(rank)')

This change is fixing the problem by adding a polyfill for Number.isFinite() function. The API was introduced as part of ES6/ES2015 spec and is not supported by PhantomJS.

Related issues

  • n/a

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos Nice catch, just one comment...

@@ -451,6 +451,10 @@ function deepMergeProperty(base, extras) {
return mergedProperty;
}

const numberIsFinite = Number.isFinite || function(value) {
return typeof value === 'number' && isFinite(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos where is the isFinite() function from? You may need to import it from somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFinite() is a global function provided by JavaScript since ES3, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite

Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bajtos bajtos merged commit c213352 into master Apr 19, 2018
@bajtos bajtos deleted the fix/phantomjs branch April 19, 2018 06:34
@bajtos bajtos removed the #review label Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants