-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding more sanity check to testing the polyfilling process in browsers
- Loading branch information
Showing
3 changed files
with
43 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const vm = require('vm'); | ||
|
||
function assert(value, expected, message) { | ||
console.log(message); | ||
if (value !== expected) { | ||
console.error(' > ERROR: expected value ' + expected + ' but the actual value is ' + value); | ||
process.exit(1); | ||
} else { | ||
console.log(' > PASSED'); | ||
} | ||
} | ||
|
||
const context = new vm.createContext(); | ||
var script = new vm.Script('this'); | ||
const window = script.runInContext(context); | ||
|
||
const fs = require('fs'); | ||
const code = fs.readFileSync(__dirname + '/../dist/Intl.js', 'utf8'); | ||
|
||
// first evaluation | ||
window.window = window; // circular, in case the polyfill uses window | ||
var originalIntl = window.Intl; | ||
var script = new vm.Script(code); | ||
script.runInContext(context); | ||
assert(typeof global.Intl, 'object', 'for this test to function, global.Intl is required'); | ||
assert(typeof window.IntlPolyfill, 'object', 'polyfill should always add the custom global IntlPolyfill'); | ||
assert(window.Intl, originalIntl, 'validating that the polyfilling process does not touch the original Intl value'); | ||
|
||
// second evaluation | ||
window.window = window; // circular, in case the polyfill uses window | ||
window.Intl = undefined; // disabling Intl | ||
var script = new vm.Script(code); | ||
script.runInContext(context); | ||
assert(window.Intl, window.IntlPolyfill, 'validating that the polyfilling process does patch Intl if it does not exist'); |
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 |
---|---|---|
@@ -1,24 +1,27 @@ | ||
var IntlPolyfill = require('../'); | ||
|
||
function assert(value, expected) { | ||
function assert(value, expected, message) { | ||
console.log(message); | ||
if (value !== expected) { | ||
console.log('expected value ' + expected + ' but the actual value is ' + value); | ||
console.error(' > ERROR: expected value ' + expected + ' but the actual value is ' + value); | ||
process.exit(1); | ||
} else { | ||
console.log(' > PASSED'); | ||
} | ||
} | ||
|
||
assert(new IntlPolyfill.NumberFormat('de-DE', { | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2 | ||
}).format(0.015), "0,02"); | ||
}).format(0.015), "0,02", 'fractional digits'); | ||
|
||
assert(new IntlPolyfill.NumberFormat('en-US', { | ||
style: 'currency', | ||
currency: 'GBP', | ||
minimumFractionDigits: 2, | ||
}).format(59.88), '£59.88'); | ||
}).format(59.88), '£59.88', 'currency with fragtional digits'); | ||
|
||
assert(new IntlPolyfill.DateTimeFormat('en', { | ||
month:'numeric', | ||
day: 'numeric' | ||
}).format(new Date('2016/05/16')), '5/16'); | ||
}).format(new Date('2016/05/16')), '5/16', 'month and day'); |