Skip to content

Commit

Permalink
feat(assert): use strictEqual and deepStrictEqual (#9)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: assertion is strict by default

fix #6
  • Loading branch information
azu committed Aug 24, 2019
1 parent 3989a0b commit 85a4bed
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 25 deletions.
10 changes: 5 additions & 5 deletions packages/comment-to-assert/src/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ export function wrapAssert(actualNode: any, expectedNode: any): any {
ARGS
});
} else if (isIdentifier(expectedNode) && expectedNode.name === "NaN") {
return template`assert(isNaN(ACTUAL_NODE));`({
return template`assert.ok(isNaN(ACTUAL_NODE));`({
ACTUAL_NODE
});
} else if (isNullLiteral(expectedNode)) {
return template`assert.equal(ACTUAL_NODE, null)`({
return template`assert.strictEqual(ACTUAL_NODE, null)`({
ACTUAL_NODE
});
} else if (isIdentifier(expectedNode) && expectedNode.name === "undefined") {
return template`assert.equal(ACTUAL_NODE, undefined)`({
return template`assert.strictEqual(ACTUAL_NODE, undefined)`({
ACTUAL_NODE
});
} else if (isLiteral(expectedNode)) {
return template`assert.equal(ACTUAL_NODE, EXPECTED_NODE)`({
return template`assert.strictEqual(ACTUAL_NODE, EXPECTED_NODE)`({
ACTUAL_NODE,
EXPECTED_NODE
});
} else {
return template`assert.deepEqual(ACTUAL_NODE, EXPECTED_NODE)`({
return template`assert.deepStrictEqual(ACTUAL_NODE, EXPECTED_NODE)`({
ACTUAL_NODE,
EXPECTED_NODE
});
Expand Down
9 changes: 9 additions & 0 deletions packages/comment-to-assert/test/snapshot-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs";
import * as path from "path";
import * as assert from "assert";
import * as vm from "vm";
import { toAssertFromSource } from "../src/comment-to-assert";

const fixturesDir = path.join(__dirname, "snapshots");
Expand Down Expand Up @@ -28,6 +29,14 @@ ${fixtureDir}
${JSON.stringify(actual)}
`
);
if (typeof actual === "string") {
vm.runInContext(
actual,
vm.createContext({
assert
})
);
}
});
});
});
2 changes: 1 addition & 1 deletion packages/comment-to-assert/test/snapshots/Array/output.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var a = [1];
assert.deepEqual(a, [1]); // => [1]
assert.deepStrictEqual(a, [1]); // => [1]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var a = function() {
return 1;
};
a + 1; // => 2
a() + 1; // => 2
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ var a = function () {
return 1;
};

assert.equal(a + 1, 2); // => 2
assert.strictEqual(a() + 1, 2); // => 2
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
assert.equal(1, 1);
assert.strictEqual(1, 1);
/* => 1 */
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ var a = function () {
return 1;
};

assert.equal(a(), 1); // => 1
assert.strictEqual(a(), 1); // => 1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
assert.equal(null, null); // => null
assert.strictEqual(null, null); // => null

assert.equal(1, 1); // => 1
assert.strictEqual(1, 1); // => 1

const a = "str";
assert.equal(a, "str"); // => "str"
assert.strictEqual(a, "str"); // => "str"
2 changes: 1 addition & 1 deletion packages/comment-to-assert/test/snapshots/NaN/output.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
assert(isNaN(NaN)); // => NaN
assert.ok(isNaN(NaN)); // => NaN
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Promise.resolve(Promise.resolve(1)).then(v => {
assert.equal(v, 1);
assert.strictEqual(v, 1);
return v;
}); // => Promise: 1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Promise.resolve(Promise.resolve(1)).then(v => {
assert.equal(v, 1);
assert.strictEqual(v, 1);
return v;
}); // => Promise: 1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
assert.equal(1, 1); // => 1
assert.strictEqual(1, 1); // => 1

assert.equal(2, 2); // => 2
assert.strictEqual(2, 2); // => 2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
assert.equal(null, null); // => null
assert.strictEqual(null, null); // => null
Original file line number Diff line number Diff line change
@@ -1 +1 @@
assert.equal(1, 1); // => 1
assert.strictEqual(1, 1); // => 1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// avoid to directive literal
assert.equal("str", "str"); // =>"str"
assert.strictEqual("str", "str"); // =>"str"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
this; // => undefined
undefined; // => undefined
Original file line number Diff line number Diff line change
@@ -1 +1 @@
assert.equal(this, undefined); // => undefined
assert.strictEqual(undefined, undefined); // => undefined
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var a = {
a: 1
};
assert.deepEqual(a, {
assert.deepStrictEqual(a, {
a: 1
}); // => { a : 1 }
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const a = 1;
assert.equal(a, 1); // => 1
assert.strictEqual(a, 1); // => 1

0 comments on commit 85a4bed

Please sign in to comment.