Skip to content

Commit

Permalink
Fix tests in node 12.14.1
Browse files Browse the repository at this point in the history
Some tests were failing in node 12.14.1, because of changes (likely
improvements) to object formatting. By using `util.inspect` in tests, we
can match the strings correctly, no matter the node version.
  • Loading branch information
mroderick committed Jun 23, 2021
1 parent fde76f7 commit f9d0c82
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 64 deletions.
31 changes: 23 additions & 8 deletions lib/assertions/is-float-32-array.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var assert = require("assert");
var inspect = require("util").inspect;
var referee = require("../referee");
var captureArgs = require("../test-helper/capture-args");

Expand All @@ -10,15 +11,19 @@ describe("assert.isFloat32Array", function () {
});

it("should fail for Float64Array", function () {
const actual = new Float64Array(2);

assert.throws(
function () {
referee.assert.isFloat32Array(new Float64Array(2));
referee.assert.isFloat32Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isFloat32Array] Expected Float64Array(2) [ 0, 0 ] to be a Float32Array"
`[assert.isFloat32Array] Expected ${inspect(
actual
)} to be a Float32Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isFloat32Array");
Expand Down Expand Up @@ -83,16 +88,19 @@ describe("assert.isFloat32Array", function () {

it("should fail with custom message", function () {
var message = "b547be3f-9453-4034-a3ee-e6dfe0f26fa1";
const actual = new Float64Array(2);

assert.throws(
function () {
referee.assert.isFloat32Array(new Float64Array(2), message);
referee.assert.isFloat32Array(actual, message);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
`[assert.isFloat32Array] ${message}: Expected Float64Array(2) [ 0, 0 ] to be a Float32Array`
`[assert.isFloat32Array] ${message}: Expected ${inspect(
actual
)} to be a Float32Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isFloat32Array");
Expand All @@ -104,15 +112,19 @@ describe("assert.isFloat32Array", function () {

describe("refute.isFloat32Array", function () {
it("should fail for Float32Array", function () {
const actual = new Float32Array(2);

assert.throws(
function () {
referee.refute.isFloat32Array(new Float32Array(2));
referee.refute.isFloat32Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[refute.isFloat32Array] Expected Float32Array(2) [ 0, 0 ] not to be a Float32Array"
`[refute.isFloat32Array] Expected ${inspect(
actual
)} not to be a Float32Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isFloat32Array");
Expand All @@ -139,16 +151,19 @@ describe("refute.isFloat32Array", function () {

it("should fail with custom message", function () {
var message = "2cc86fd1-dd39-44ed-a7c6-e5b83a16e27e";
const actual = new Float32Array(2);

assert.throws(
function () {
referee.refute.isFloat32Array(new Float32Array(2), message);
referee.refute.isFloat32Array(actual, message);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
`[refute.isFloat32Array] ${message}: Expected Float32Array(2) [ 0, 0 ] not to be a Float32Array`
`[refute.isFloat32Array] ${message}: Expected ${inspect(
actual
)} not to be a Float32Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isFloat32Array");
Expand Down
31 changes: 23 additions & 8 deletions lib/assertions/is-float-64-array.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
"use strict";

var assert = require("assert");
var inspect = require("util").inspect;
var referee = require("../referee");
var captureArgs = require("../test-helper/capture-args");

describe("assert.isFloat64Array", function () {
it("should fail for Float32Array", function () {
const actual = new Float32Array(2);

assert.throws(
function () {
referee.assert.isFloat64Array(new Float32Array(2));
referee.assert.isFloat64Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isFloat64Array] Expected Float32Array(2) [ 0, 0 ] to be a Float64Array"
`[assert.isFloat64Array] Expected ${inspect(
actual
)} to be a Float64Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isFloat64Array");
Expand Down Expand Up @@ -83,16 +88,19 @@ describe("assert.isFloat64Array", function () {

it("should fail with custom message", function () {
var message = "b547be3f-9453-4034-a3ee-e6dfe0f26fa1";
const actual = new Float32Array(2);

assert.throws(
function () {
referee.assert.isFloat64Array(new Float32Array(2), message);
referee.assert.isFloat64Array(actual, message);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
`[assert.isFloat64Array] ${message}: Expected Float32Array(2) [ 0, 0 ] to be a Float64Array`
`[assert.isFloat64Array] ${message}: Expected ${inspect(
actual
)} to be a Float64Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isFloat64Array");
Expand All @@ -108,15 +116,19 @@ describe("refute.isFloat64Array", function () {
});

it("should fail for Float64Array", function () {
const actual = new Float64Array(2);

assert.throws(
function () {
referee.refute.isFloat64Array(new Float64Array(2));
referee.refute.isFloat64Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[refute.isFloat64Array] Expected Float64Array(2) [ 0, 0 ] not to be a Float64Array"
`[refute.isFloat64Array] Expected ${inspect(
actual
)} not to be a Float64Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isFloat64Array");
Expand All @@ -139,16 +151,19 @@ describe("refute.isFloat64Array", function () {

it("should fail with custom message", function () {
var message = "2cc86fd1-dd39-44ed-a7c6-e5b83a16e27e";
const actual = new Float64Array(2);

assert.throws(
function () {
referee.refute.isFloat64Array(new Float64Array(2), message);
referee.refute.isFloat64Array(actual, message);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
`[refute.isFloat64Array] ${message}: Expected Float64Array(2) [ 0, 0 ] not to be a Float64Array`
`[refute.isFloat64Array] ${message}: Expected ${inspect(
actual
)} not to be a Float64Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isFloat64Array");
Expand Down
32 changes: 24 additions & 8 deletions lib/assertions/is-int-16-array.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
"use strict";

var assert = require("assert");
var inspect = require("util").inspect;
var referee = require("../referee");
var captureArgs = require("../test-helper/capture-args");

describe("assert.isInt16Array", function () {
it("should fail for Int8Array", function () {
const actual = new Int8Array(2);

assert.throws(
function () {
referee.assert.isInt16Array(new Int8Array(2));
referee.assert.isInt16Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isInt16Array] Expected Int8Array(2) [ 0, 0 ] to be an Int16Array"
`[assert.isInt16Array] Expected ${inspect(
actual
)} to be an Int16Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isInt16Array");
Expand All @@ -28,15 +33,19 @@ describe("assert.isInt16Array", function () {
});

it("should fail for Int32Array", function () {
const actual = new Int32Array(2);

assert.throws(
function () {
referee.assert.isInt16Array(new Int32Array(2));
referee.assert.isInt16Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isInt16Array] Expected Int32Array(2) [ 0, 0 ] to be an Int16Array"
`[assert.isInt16Array] Expected ${inspect(
actual
)} to be an Int16Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isInt16Array");
Expand Down Expand Up @@ -126,15 +135,19 @@ describe("refute.isInt16Array", function () {
});

it("should fail for Int16Array", function () {
const actual = new Int16Array(2);

assert.throws(
function () {
referee.refute.isInt16Array(new Int16Array(2));
referee.refute.isInt16Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[refute.isInt16Array] Expected Int16Array(2) [ 0, 0 ] not to be an Int16Array"
`[refute.isInt16Array] Expected ${inspect(
actual
)} not to be an Int16Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isInt16Array");
Expand All @@ -161,16 +174,19 @@ describe("refute.isInt16Array", function () {

it("should fail with custom message", function () {
var message = "1cf37727-f020-4ce8-840d-acb7ffc2ac21";
const actual = new Int16Array(2);

assert.throws(
function () {
referee.refute.isInt16Array(new Int16Array(2), message);
referee.refute.isInt16Array(actual, message);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
`[refute.isInt16Array] ${message}: Expected Int16Array(2) [ 0, 0 ] not to be an Int16Array`
`[refute.isInt16Array] ${message}: Expected ${inspect(
actual
)} not to be an Int16Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isInt16Array");
Expand Down
32 changes: 24 additions & 8 deletions lib/assertions/is-int-32-array.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
"use strict";

var assert = require("assert");
var inspect = require("util").inspect;
var referee = require("../referee");
var captureArgs = require("../test-helper/capture-args");

describe("assert.isInt32Array", function () {
it("should fail for Int8Array", function () {
const actual = new Int8Array(2);

assert.throws(
function () {
referee.assert.isInt32Array(new Int8Array(2));
referee.assert.isInt32Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isInt32Array] Expected Int8Array(2) [ 0, 0 ] to be an Int32Array"
`[assert.isInt32Array] Expected ${inspect(
actual
)} to be an Int32Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isInt32Array");
Expand All @@ -24,15 +29,19 @@ describe("assert.isInt32Array", function () {
});

it("should fail for Int16Array", function () {
const actual = new Int16Array(2);

assert.throws(
function () {
referee.assert.isInt32Array(new Int16Array(2));
referee.assert.isInt32Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isInt32Array] Expected Int16Array(2) [ 0, 0 ] to be an Int32Array"
`[assert.isInt32Array] Expected ${inspect(
actual
)} to be an Int32Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isInt32Array");
Expand Down Expand Up @@ -130,15 +139,19 @@ describe("refute.isInt32Array", function () {
});

it("should fail for Int32Array", function () {
const actual = new Int32Array(2);

assert.throws(
function () {
referee.refute.isInt32Array(new Int32Array(2));
referee.refute.isInt32Array(actual);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[refute.isInt32Array] Expected Int32Array(2) [ 0, 0 ] not to be an Int32Array"
`[refute.isInt32Array] Expected ${inspect(
actual
)} not to be an Int32Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isInt32Array");
Expand All @@ -161,16 +174,19 @@ describe("refute.isInt32Array", function () {

it("should fail with custom message", function () {
var message = "82576420-8e5d-4618-b6eb-87bcf00b9170";
const actual = new Int32Array(2);

assert.throws(
function () {
referee.refute.isInt32Array(new Int32Array(2), message);
referee.refute.isInt32Array(actual, message);
},
function (error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
`[refute.isInt32Array] ${message}: Expected Int32Array(2) [ 0, 0 ] not to be an Int32Array`
`[refute.isInt32Array] ${message}: Expected ${inspect(
actual
)} not to be an Int32Array`
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isInt32Array");
Expand Down
Loading

0 comments on commit f9d0c82

Please sign in to comment.