andyearnshaw / Intl.js

Compatibility implementation of the ECMAScript Internationalization API (ECMA-402) for JavaScript -- UNMAINTAINED
Other
1.7k stars 215 forks source link

Fix the RegExp restoration tests #316

Open ghostd opened 6 years ago

ghostd commented 6 years ago

I chose to copy the results before the assertions. Another fix would be to disable this code by setting the NODE_DISABLE_COLORS variable. But IMHO that'd still be flaky.

luiz commented 5 years ago

Hi, @ghostd! Thanks for this PR. I've tested it here and it fixes a test that was failing, but still fails another.

Normally, RegExp.lastMatch should be cached and restored
 > ERROR: expected value foo but the actual value is xterm-256

I found that a similar fix has to be applied at tests/disableregexprestore.js.

--- a/tests/disableregexprestore.js
+++ b/tests/disableregexprestore.js
@@ -26,8 +26,10 @@ new IntlPolyfill.NumberFormat('en-US', {
     currency: 'GBP',
     minimumFractionDigits: 2,
 });
-assertEqual(RegExp.input, 'a foo test', 'Normally, RegExp.input should be cached and restored');
-assertEqual(RegExp.lastMatch, 'foo', 'Normally, RegExp.lastMatch should be cached and restored');
+var actualInput = RegExp.input;
+var actualLastMatch = RegExp.lastMatch;
+assertEqual(actualInput, 'a foo test', 'Normally, RegExp.input should be cached and restored');
+assertEqual(actualLastMatch, 'foo', 'Normally, RegExp.lastMatch should be cached and restored');

 // Issues #231
 /function[\s\S]+(})/.exec('function defineProperty\\(\\) \\{\n    \\[native code\\]\n\\}');
@@ -36,8 +38,10 @@ new IntlPolyfill.NumberFormat('en-US', {
     currency: 'GBP',
     minimumFractionDigits: 2,
 });
-assertEqual(RegExp.input, 'function defineProperty\\(\\) \\{\n    \\[native code\\]\n\\}', 'Normally, RegExp.input should be cached and restored');
-assertEqual(RegExp.lastMatch, 'function defineProperty\\(\\) \\{\n    \\[native code\\]\n\\}', 'Normally, RegExp.lastMatch should be cached and restored');
+actualInput = RegExp.input;
+actualLastMatch = RegExp.lastMatch;
+assertEqual(actualInput, 'function defineProperty\\(\\) \\{\n    \\[native code\\]\n\\}', 'Normally, RegExp.input should be cached and restored');
+assertEqual(actualLastMatch, 'function defineProperty\\(\\) \\{\n    \\[native code\\]\n\\}', 'Normally, RegExp.lastMatch should be cached and restored');

 IntlPolyfill.__disableRegExpRestore();
 /foo/.exec('a foo test');