Skip to content

Commit

Permalink
Make tests compatible with Node.js 12 and prerelease versions (#197)
Browse files Browse the repository at this point in the history
* make version check work with prerelease versions

semver.satisfies does not match a prerelease version against a
non-prerelease one, e.g. 12.0.0-pre does not match >= 10. Use a regex
match to workaround this fact.

* make tests compatible with Node.js 12

In Node.js 12, the formatting of console arguments will change slightly.
Previously, a string other than the first argument was formatted using
single quotes if the first argument was non-string. Now, quotes are
never added regardless of position of a string argument.

To make test compatible in all Node.js versions, I work around by
ensuring the first argument to console.log is a string which prevents
the quotes from being added on older versions of Node.js.

Ref: nodejs/node#23162

* restart travis
  • Loading branch information
silverwind authored and fabiosantoscode committed Dec 19, 2018
1 parent 77b9b29 commit 6602668
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
12 changes: 6 additions & 6 deletions test/compress/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1406,12 +1406,12 @@ self_comparison_1: {
}
input: {
var o = { n: NaN };
console.log(o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n, typeof o.n);
console.log(typeof o.n, o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n);
}
expect: {
console.log(false, false, true, true, "number");
console.log("number", false, false, true, true);
}
expect_stdout: "false false true true 'number'"
expect_stdout: "number false false true true"
}

self_comparison_2: {
Expand All @@ -1426,12 +1426,12 @@ self_comparison_2: {
}
input: {
var o = { n: NaN };
console.log(o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n, typeof o.n);
console.log(typeof o.n, o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n);
}
expect: {
console.log(false, false, true, true, "number");
console.log("number", false, false, true, true);
}
expect_stdout: "false false true true 'number'"
expect_stdout: "number false false true true"
}

issue_2535_1: {
Expand Down
6 changes: 3 additions & 3 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -2724,19 +2724,19 @@ issue_1814_2: {
!function() {
var b = a + 1;
!function(a) {
console.log(a++, b);
console.log(b, a++);
}(0);
}();
}
expect: {
const a = "32";
!function() {
!function(a) {
console.log(a++, "321");
console.log("321", a++);
}(0);
}();
}
expect_stdout: "0 '321'"
expect_stdout: "321 0"
}

try_abort: {
Expand Down
6 changes: 3 additions & 3 deletions test/compress/string-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ issue_1929: {
return s.split(/[\\/]/);
}
var r = f("A/B\\C\\D/E\\F");
console.log(r.length, r[5], r[4], r[3], r[2], r[1], r[0]);
console.log(r[5], r[4], r[3], r[2], r[1], r[0], r.length);
}
expect: {
function f(s) {
return s.split(/[\\/]/);
}
var r = f("A/B\\C\\D/E\\F");
console.log(r.length, r[5], r[4], r[3], r[2], r[1], r[0]);
console.log(r[5], r[4], r[3], r[2], r[1], r[0], r.length);
}
expect_stdout: "6 'F' 'E' 'D' 'C' 'B' 'A'"
expect_stdout: "F E D C B A 6"
}
4 changes: 1 addition & 3 deletions tools/colorless-console.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use strict"

var semver = require("semver");

if (semver.satisfies(process.version, ">=10")) {
if (Number((/([0-9]+)\./.exec(process.version) || [])[1]) >= 10) {
var Console = require("console").Console;
global.console = new Console({
stdout: process.stdout,
Expand Down

0 comments on commit 6602668

Please sign in to comment.