|
| 1 | +const vm = require('vm'); |
| 2 | + |
| 3 | +function assert(value, expected, message) { |
| 4 | + console.log(message); |
| 5 | + if (value !== expected) { |
| 6 | + console.error(' > ERROR: expected value ' + expected + ' but the actual value is ' + value); |
| 7 | + process.exit(1); |
| 8 | + } else { |
| 9 | + console.log(' > PASSED'); |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +const context = new vm.createContext(); |
| 14 | +var script = new vm.Script('this'); |
| 15 | +const window = script.runInContext(context); |
| 16 | + |
| 17 | +const fs = require('fs'); |
| 18 | +const code = fs.readFileSync(__dirname + '/../dist/Intl.js', 'utf8'); |
| 19 | + |
| 20 | +// first evaluation |
| 21 | +window.window = window; // circular, in case the polyfill uses window |
| 22 | +var originalIntl = window.Intl; |
| 23 | +var script = new vm.Script(code); |
| 24 | +script.runInContext(context); |
| 25 | +assert(typeof global.Intl, 'object', 'for this test to function, global.Intl is required'); |
| 26 | +assert(typeof window.IntlPolyfill, 'object', 'polyfill should always add the custom global IntlPolyfill'); |
| 27 | +assert(window.Intl, originalIntl, 'validating that the polyfilling process does not touch the original Intl value'); |
| 28 | + |
| 29 | +// second evaluation |
| 30 | +window.window = window; // circular, in case the polyfill uses window |
| 31 | +window.Intl = undefined; // disabling Intl |
| 32 | +var script = new vm.Script(code); |
| 33 | +script.runInContext(context); |
| 34 | +assert(window.Intl, window.IntlPolyfill, 'validating that the polyfilling process does patch Intl if it does not exist'); |
0 commit comments