workaround test failures in Node.js 10 (#3102)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 26 Apr 2018 09:44:37 +0000 (17:44 +0800)
committerGitHub <noreply@github.com>
Thu, 26 Apr 2018 09:44:37 +0000 (17:44 +0800)
test/mocha/cli.js
test/run-tests.js

index 8c858bd..3b3dcab 100644 (file)
@@ -100,8 +100,8 @@ describe("bin/uglifyjs", function () {
         exec(command, function (err, stdout, stderr) {
             if (err) throw err;
 
-            var stderrLines = stderr.split('\n');
-            assert.strictEqual(stderrLines[0], 'INFO: Using input source map: test/input/issue-2082/sample.js.map');
+            var stderrLines = stderr.split("\n");
+            assert.strictEqual(stderrLines[0], "INFO: Using input source map: test/input/issue-2082/sample.js.map");
             assert.notStrictEqual(stderrLines[1], 'INFO: Using input source map: {"version": 3,"sources": ["index.js"],"mappings": ";"}');
             done();
         });
@@ -244,7 +244,8 @@ describe("bin/uglifyjs", function () {
                 "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==",
                 "",
             ].join("\n"));
-            assert.strictEqual(stderr, "WARN: inline source map not found: test/input/issue-1323/sample.js\n");
+            var stderrLines = stderr.split("\n");
+            assert.strictEqual(stderrLines[0], "WARN: inline source map not found: test/input/issue-1323/sample.js");
             done();
         });
     });
@@ -264,7 +265,8 @@ describe("bin/uglifyjs", function () {
                 "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwidGVzdC9pbnB1dC9pc3N1ZS0xMzIzL3NhbXBsZS5qcyJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFNBQUFBLE1BQWdCQyxRQUFRQyxJQUFJLEVBQUUsSUFBTyxJQUFJRixJQ0FuRCxJQUFJRyxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==",
                 "",
             ].join("\n"));
-            assert.strictEqual(stderr, "WARN: inline source map not found: test/input/issue-1323/sample.js\n");
+            var stderrLines = stderr.split("\n");
+            assert.strictEqual(stderrLines[0], "WARN: inline source map not found: test/input/issue-1323/sample.js");
             done();
         });
     });
index 3ed28df..b31c33b 100755 (executable)
@@ -172,7 +172,7 @@ function run_compress_tests() {
             }
             if (test.expect_stdout
                 && (!test.node_version || semver.satisfies(process.version, test.node_version))) {
-                var stdout = sandbox.run_code(input_code, true);
+                var stdout = run_code(input_code);
                 if (test.expect_stdout === true) {
                     test.expect_stdout = stdout;
                 }
@@ -186,7 +186,7 @@ function run_compress_tests() {
                     });
                     return false;
                 }
-                stdout = sandbox.run_code(output, true);
+                stdout = run_code(output);
                 if (!sandbox.same_stdout(test.expect_stdout, stdout)) {
                     log("!!! failed\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
                         input: input_formatted,
@@ -344,6 +344,11 @@ function evaluate(code) {
     return new Function("return(" + code + ")")();
 }
 
+function run_code(code) {
+    var result = sandbox.run_code(code, true);
+    return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
+}
+
 // Try to reminify original input with standard options
 // to see if it matches expect_stdout.
 function reminify(orig_options, input_code, input_formatted, expect_stdout) {
@@ -367,7 +372,7 @@ function reminify(orig_options, input_code, input_formatted, expect_stdout) {
             });
             return false;
         } else {
-            var stdout = sandbox.run_code(result.code, true);
+            var stdout = run_code(result.code);
             if (typeof expect_stdout != "string" && typeof stdout != "string" && expect_stdout.name == stdout.name) {
                 stdout = expect_stdout;
             }