From 929c275468f28638eec452bfd01a1331ad061866 Mon Sep 17 00:00:00 2001 From: FredGuiou <99122562+FredGuiou@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:06:08 +0100 Subject: [PATCH] refactor(estree-ast-utils/test): migrate to test_runner (#251) * refactor(estree-ast-utils/test): migrate to test_runner * chore(package.json): delete unused dependencies --- package.json | 5 +- workspaces/estree-ast-utils/package.json | 2 +- .../VariableTracer/VariableTracer.spec.js | 86 ++++++++---------- .../test/VariableTracer/assignments.spec.js | 87 ++++++++----------- .../VariableTracer/cryptoCreateHash.spec.js | 85 ++++++++---------- .../test/arrayExpressionToString.spec.js | 36 ++++---- .../test/concatBinaryExpression.spec.js | 40 ++++----- .../test/extractLogicalExpression.spec.js | 35 ++++---- .../test/getCallExpressionIdentifier.spec.js | 35 ++++---- .../getMemberExpressionIdentifier.spec.js | 36 ++++---- .../test/isLiteralRegex.spec.js | 15 ++-- .../getSubMemberExpressionSegments.spec.js | 12 +-- .../test/utils/isEvilIdentifierPath.spec.js | 17 ++-- .../test/utils/notNullOrUndefined.spec.js | 19 ++-- 14 files changed, 224 insertions(+), 286 deletions(-) diff --git a/package.json b/package.json index 7fbfe7d..5a7058e 100644 --- a/package.json +++ b/package.json @@ -55,15 +55,12 @@ }, "devDependencies": { "@nodesecure/eslint-config": "^1.6.0", - "@small-tech/esm-tape-runner": "^2.0.0", - "@small-tech/tap-monkey": "^1.4.0", "@types/node": "^20.6.2", "c8": "^9.0.0", "cross-env": "^7.0.3", "eslint": "^8.31.0", "glob": "^10.3.4", "iterator-matcher": "^2.1.0", - "pkg-ok": "^3.0.0", - "tape": "^5.7.2" + "pkg-ok": "^3.0.0" } } diff --git a/workspaces/estree-ast-utils/package.json b/workspaces/estree-ast-utils/package.json index d9b4275..ce3d1cd 100644 --- a/workspaces/estree-ast-utils/package.json +++ b/workspaces/estree-ast-utils/package.json @@ -8,7 +8,7 @@ "scripts": { "lint": "eslint src test", "prepublishOnly": "pkg-ok", - "test": "cross-env esm-tape-runner 'test/**/*.spec.js' | tap-monkey", + "test": "node --test", "check": "cross-env npm run lint && npm run test", "coverage": "c8 -r html npm test" }, diff --git a/workspaces/estree-ast-utils/test/VariableTracer/VariableTracer.spec.js b/workspaces/estree-ast-utils/test/VariableTracer/VariableTracer.spec.js index 41f9ce5..732e663 100644 --- a/workspaces/estree-ast-utils/test/VariableTracer/VariableTracer.spec.js +++ b/workspaces/estree-ast-utils/test/VariableTracer/VariableTracer.spec.js @@ -1,19 +1,19 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import { createTracer } from "../utils.js"; -test("getDataFromIdentifier must return primitive null is there is no kwown traced identifier", (tape) => { +test("getDataFromIdentifier must return primitive null is there is no kwown traced identifier", () => { const helpers = createTracer(true); const result = helpers.tracer.getDataFromIdentifier("foobar"); - tape.strictEqual(result, null); - tape.end(); + assert.strictEqual(result, null); }); -test("it should be able to Trace a malicious code with Global, BinaryExpr, Assignments and Hexadecimal", (tape) => { +test("it should be able to Trace a malicious code with Global, BinaryExpr, Assignments and Hexadecimal", () => { const helpers = createTracer(true); const assignments = helpers.getAssignmentArray(); @@ -27,24 +27,22 @@ test("it should be able to Trace a malicious code with Global, BinaryExpr, Assig `); const evil = helpers.tracer.getDataFromIdentifier("evil"); - tape.deepEqual(evil, { + assert.deepEqual(evil, { name: "require", identifierOrMemberExpr: "process.mainModule.require", assignmentMemory: ["p", "evil"] }); - tape.strictEqual(assignments.length, 2); + assert.strictEqual(assignments.length, 2); const [eventOne, eventTwo] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "process"); - tape.strictEqual(eventOne.id, "p"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "process"); + assert.strictEqual(eventOne.id, "p"); - tape.strictEqual(eventTwo.identifierOrMemberExpr, "process.mainModule.require"); - tape.strictEqual(eventTwo.id, "evil"); - - tape.end(); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "process.mainModule.require"); + assert.strictEqual(eventTwo.id, "evil"); }); -test("it should be able to Trace a malicious CallExpression by recombining segments of the MemberExpression", (tape) => { +test("it should be able to Trace a malicious CallExpression by recombining segments of the MemberExpression", () => { const helpers = createTracer(true); const assignments = helpers.getAssignmentArray(); @@ -57,36 +55,32 @@ test("it should be able to Trace a malicious CallExpression by recombining segme `); const evil = helpers.tracer.getDataFromIdentifier("r.require"); - tape.deepEqual(evil, { + assert.deepEqual(evil, { name: "require", identifierOrMemberExpr: "process.mainModule.require", assignmentMemory: ["g", "r", "c"] }); - tape.strictEqual(assignments.length, 3); + assert.strictEqual(assignments.length, 3); const [eventOne, eventTwo, eventThree] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "process"); - tape.strictEqual(eventOne.id, "g"); - - tape.strictEqual(eventTwo.identifierOrMemberExpr, "process.mainModule"); - tape.strictEqual(eventTwo.id, "r"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "process"); + assert.strictEqual(eventOne.id, "g"); - tape.strictEqual(eventThree.identifierOrMemberExpr, "process.mainModule.require"); - tape.strictEqual(eventThree.id, "c"); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "process.mainModule"); + assert.strictEqual(eventTwo.id, "r"); - tape.end(); + assert.strictEqual(eventThree.identifierOrMemberExpr, "process.mainModule.require"); + assert.strictEqual(eventThree.id, "c"); }); -test("given a MemberExpression segment that doesn't match anything then it should return null", (tape) => { +test("given a MemberExpression segment that doesn't match anything then it should return null", () => { const helpers = createTracer(true); const result = helpers.tracer.getDataFromIdentifier("foo.bar"); - tape.strictEqual(result, null); - - tape.end(); + assert.strictEqual(result, null); }); -test("it should be able to Trace a require using Function.prototype.call", (tape) => { +test("it should be able to Trace a require using Function.prototype.call", () => { const helpers = createTracer(); helpers.tracer.trace("http"); const assignments = helpers.getAssignmentArray(); @@ -97,17 +91,15 @@ test("it should be able to Trace a require using Function.prototype.call", (tape const proto = helpers.tracer.getDataFromIdentifier("proto"); - tape.strictEqual(proto, null); - tape.strictEqual(assignments.length, 1); + assert.strictEqual(proto, null); + assert.strictEqual(assignments.length, 1); const [eventOne] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "http"); - tape.strictEqual(eventOne.id, "proto"); - - tape.end(); + assert.strictEqual(eventOne.identifierOrMemberExpr, "http"); + assert.strictEqual(eventOne.id, "proto"); }); -test("it should be able to Trace an unsafe crypto.createHash using Function.prototype.call reassignment", (tape) => { +test("it should be able to Trace an unsafe crypto.createHash using Function.prototype.call reassignment", () => { const helpers = createTracer(true); helpers.tracer.trace("crypto.createHash", { followConsecutiveAssignment: true }); const assignments = helpers.getAssignmentArray(); @@ -122,24 +114,22 @@ test("it should be able to Trace an unsafe crypto.createHash using Function.prot `); const createHashBis = helpers.tracer.getDataFromIdentifier("createHashBis"); - tape.deepEqual(createHashBis, { + assert.deepEqual(createHashBis, { name: "crypto.createHash", identifierOrMemberExpr: "crypto.createHash", assignmentMemory: ["crr", "createHashBis"] }); - tape.strictEqual(helpers.tracer.importedModules.has("crypto"), true); - tape.strictEqual(assignments.length, 3); + assert.strictEqual(helpers.tracer.importedModules.has("crypto"), true); + assert.strictEqual(assignments.length, 3); const [eventOne, eventTwo, eventThree] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "require"); - tape.strictEqual(eventOne.id, "bB"); - - tape.strictEqual(eventTwo.identifierOrMemberExpr, "crypto"); - tape.strictEqual(eventTwo.id, "crr"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "require"); + assert.strictEqual(eventOne.id, "bB"); - tape.strictEqual(eventThree.identifierOrMemberExpr, "crypto.createHash"); - tape.strictEqual(eventThree.id, "createHashBis"); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "crypto"); + assert.strictEqual(eventTwo.id, "crr"); - tape.end(); + assert.strictEqual(eventThree.identifierOrMemberExpr, "crypto.createHash"); + assert.strictEqual(eventThree.id, "createHashBis"); }); diff --git a/workspaces/estree-ast-utils/test/VariableTracer/assignments.spec.js b/workspaces/estree-ast-utils/test/VariableTracer/assignments.spec.js index 70b7e74..90586f7 100644 --- a/workspaces/estree-ast-utils/test/VariableTracer/assignments.spec.js +++ b/workspaces/estree-ast-utils/test/VariableTracer/assignments.spec.js @@ -1,10 +1,11 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import { createTracer } from "../utils.js"; -test("it should be able to Trace a require Assignment (using a global variable)", (tape) => { +test("it should be able to Trace a require Assignment (using a global variable)", () => { const helpers = createTracer(true); const assignments = helpers.getAssignmentArray(); @@ -15,21 +16,19 @@ test("it should be able to Trace a require Assignment (using a global variable)" `); const foo = helpers.tracer.getDataFromIdentifier("foo"); - tape.deepEqual(foo, { + assert.deepEqual(foo, { name: "require", identifierOrMemberExpr: "require", assignmentMemory: ["foo"] }); - tape.strictEqual(assignments.length, 1); + assert.strictEqual(assignments.length, 1); const [eventOne] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "require"); - tape.strictEqual(eventOne.id, "foo"); - - tape.end(); + assert.strictEqual(eventOne.identifierOrMemberExpr, "require"); + assert.strictEqual(eventOne.id, "foo"); }); -test("it should be able to Trace a require Assignment (using a MemberExpression)", (tape) => { +test("it should be able to Trace a require Assignment (using a MemberExpression)", () => { const helpers = createTracer(true); const assignments = helpers.getAssignmentArray(); @@ -39,21 +38,19 @@ test("it should be able to Trace a require Assignment (using a MemberExpression) `); const foo = helpers.tracer.getDataFromIdentifier("foo"); - tape.deepEqual(foo, { + assert.deepEqual(foo, { name: "require", identifierOrMemberExpr: "require.resolve", assignmentMemory: ["foo"] }); - tape.strictEqual(assignments.length, 1); + assert.strictEqual(assignments.length, 1); const [eventOne] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "require.resolve"); - tape.strictEqual(eventOne.id, "foo"); - - tape.end(); + assert.strictEqual(eventOne.identifierOrMemberExpr, "require.resolve"); + assert.strictEqual(eventOne.id, "foo"); }); -test("it should be able to Trace a global Assignment using an ESTree ObjectPattern", (tape) => { +test("it should be able to Trace a global Assignment using an ESTree ObjectPattern", () => { const helpers = createTracer(true); const assignments = helpers.getAssignmentArray(); @@ -65,24 +62,22 @@ test("it should be able to Trace a global Assignment using an ESTree ObjectPatte const boo = helpers.tracer.getDataFromIdentifier("boo"); - tape.deepEqual(boo, { + assert.deepEqual(boo, { name: "require", identifierOrMemberExpr: "process.mainModule.require", assignmentMemory: ["yoo", "boo"] }); - tape.strictEqual(assignments.length, 2); + assert.strictEqual(assignments.length, 2); const [eventOne, eventTwo] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "process"); - tape.strictEqual(eventOne.id, "yoo"); - - tape.strictEqual(eventTwo.identifierOrMemberExpr, "process.mainModule.require"); - tape.strictEqual(eventTwo.id, "boo"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "process"); + assert.strictEqual(eventOne.id, "yoo"); - tape.end(); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "process.mainModule.require"); + assert.strictEqual(eventTwo.id, "boo"); }); -test("it should be able to Trace an Unsafe Function() Assignment using an ESTree ObjectPattern", (tape) => { +test("it should be able to Trace an Unsafe Function() Assignment using an ESTree ObjectPattern", () => { const helpers = createTracer(true); const assignments = helpers.getAssignmentArray(); @@ -94,24 +89,22 @@ test("it should be able to Trace an Unsafe Function() Assignment using an ESTree const boo = helpers.tracer.getDataFromIdentifier("boo"); - tape.deepEqual(boo, { + assert.deepEqual(boo, { name: "require", identifierOrMemberExpr: "process.mainModule.require", assignmentMemory: ["yoo", "boo"] }); - tape.strictEqual(assignments.length, 2); + assert.strictEqual(assignments.length, 2); const [eventOne, eventTwo] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "process"); - tape.strictEqual(eventOne.id, "yoo"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "process"); + assert.strictEqual(eventOne.id, "yoo"); - tape.strictEqual(eventTwo.identifierOrMemberExpr, "process.mainModule.require"); - tape.strictEqual(eventTwo.id, "boo"); - - tape.end(); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "process.mainModule.require"); + assert.strictEqual(eventTwo.id, "boo"); }); -test("it should be able to Trace a require Assignment with atob", (tape) => { +test("it should be able to Trace a require Assignment with atob", () => { const helpers = createTracer(true); const assignments = helpers.getAssignmentArray(); @@ -120,19 +113,17 @@ test("it should be able to Trace a require Assignment with atob", (tape) => { const yo = 'b3M='; const ff = xo(yo); `); - tape.strictEqual(assignments.length, 1); + assert.strictEqual(assignments.length, 1); const [eventOne] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "atob"); - tape.strictEqual(eventOne.id, "xo"); - - tape.true(helpers.tracer.literalIdentifiers.has("ff")); - tape.strictEqual(helpers.tracer.literalIdentifiers.get("ff"), "os"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "atob"); + assert.strictEqual(eventOne.id, "xo"); - tape.end(); + assert.ok(helpers.tracer.literalIdentifiers.has("ff")); + assert.strictEqual(helpers.tracer.literalIdentifiers.get("ff"), "os"); }); -test("it should be able to Trace a global assignment using a LogicalExpression", (tape) => { +test("it should be able to Trace a global assignment using a LogicalExpression", () => { const helpers = createTracer(true); const assignments = helpers.getAssignmentArray(); @@ -142,16 +133,14 @@ test("it should be able to Trace a global assignment using a LogicalExpression", foo("http"); `); const foo = helpers.tracer.getDataFromIdentifier("foo"); - tape.deepEqual(foo, { + assert.deepEqual(foo, { name: "require", identifierOrMemberExpr: "require", assignmentMemory: ["foo"] }); - tape.strictEqual(assignments.length, 1); + assert.strictEqual(assignments.length, 1); const [eventOne] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "require"); - tape.strictEqual(eventOne.id, "foo"); - - tape.end(); + assert.strictEqual(eventOne.identifierOrMemberExpr, "require"); + assert.strictEqual(eventOne.id, "foo"); }); diff --git a/workspaces/estree-ast-utils/test/VariableTracer/cryptoCreateHash.spec.js b/workspaces/estree-ast-utils/test/VariableTracer/cryptoCreateHash.spec.js index 55f01bf..0a75a62 100644 --- a/workspaces/estree-ast-utils/test/VariableTracer/cryptoCreateHash.spec.js +++ b/workspaces/estree-ast-utils/test/VariableTracer/cryptoCreateHash.spec.js @@ -1,10 +1,11 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import { createTracer } from "../utils.js"; -test("it should be able to Trace crypto.createHash when imported with an ESTree ImportNamespaceSpecifier (ESM)", (tape) => { +test("it should be able to Trace crypto.createHash when imported with an ESTree ImportNamespaceSpecifier (ESM)", () => { const helpers = createTracer(); helpers.tracer.trace("crypto.createHash", { followConsecutiveAssignment: true, @@ -22,24 +23,22 @@ test("it should be able to Trace crypto.createHash when imported with an ESTree const createHashBis = helpers.tracer.getDataFromIdentifier("createHashBis"); - tape.deepEqual(createHashBis, { + assert.deepEqual(createHashBis, { name: "crypto.createHash", identifierOrMemberExpr: "crypto.createHash", assignmentMemory: ["cryptoBis", "createHashBis"] }); - tape.strictEqual(assignments.length, 2); + assert.strictEqual(assignments.length, 2); const [eventOne, eventTwo] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "crypto"); - tape.strictEqual(eventOne.id, "cryptoBis"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "crypto"); + assert.strictEqual(eventOne.id, "cryptoBis"); - tape.strictEqual(eventTwo.identifierOrMemberExpr, "crypto.createHash"); - tape.strictEqual(eventTwo.id, "createHashBis"); - - tape.end(); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "crypto.createHash"); + assert.strictEqual(eventTwo.id, "createHashBis"); }); -test("it should be able to Trace createHash when required (CommonJS) and destructured with an ESTree ObjectPattern", (tape) => { +test("it should be able to Trace createHash when required (CommonJS) and destructured with an ESTree ObjectPattern", () => { const helpers = createTracer(); helpers.tracer.trace("crypto.createHash", { followConsecutiveAssignment: true, @@ -60,24 +59,22 @@ test("it should be able to Trace createHash when required (CommonJS) and destruc const createHashBis = helpers.tracer.getDataFromIdentifier("createHashBis"); - tape.deepEqual(createHashBis, { + assert.deepEqual(createHashBis, { name: "crypto.createHash", identifierOrMemberExpr: "crypto.createHash", assignmentMemory: ["createHash", "createHashBis"] }); - tape.strictEqual(assignments.length, 2); + assert.strictEqual(assignments.length, 2); const [eventOne, eventTwo] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "crypto.createHash"); - tape.strictEqual(eventOne.id, "createHash"); - - tape.strictEqual(eventTwo.identifierOrMemberExpr, "crypto.createHash"); - tape.strictEqual(eventTwo.id, "createHashBis"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "crypto.createHash"); + assert.strictEqual(eventOne.id, "createHash"); - tape.end(); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "crypto.createHash"); + assert.strictEqual(eventTwo.id, "createHashBis"); }); -test("it should be able to Trace crypto.createHash when imported with an ESTree ImportSpecifier (ESM)", (tape) => { +test("it should be able to Trace crypto.createHash when imported with an ESTree ImportSpecifier (ESM)", () => { const helpers = createTracer(); helpers.tracer.trace("crypto.createHash", { followConsecutiveAssignment: true, @@ -94,24 +91,22 @@ test("it should be able to Trace crypto.createHash when imported with an ESTree const createHashBis = helpers.tracer.getDataFromIdentifier("createHashBis"); - tape.deepEqual(createHashBis, { + assert.deepEqual(createHashBis, { name: "crypto.createHash", identifierOrMemberExpr: "crypto.createHash", assignmentMemory: ["createHash", "createHashBis"] }); - tape.strictEqual(assignments.length, 2); + assert.strictEqual(assignments.length, 2); const [eventOne, eventTwo] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "crypto.createHash"); - tape.strictEqual(eventOne.id, "createHash"); - - tape.strictEqual(eventTwo.identifierOrMemberExpr, "crypto.createHash"); - tape.strictEqual(eventTwo.id, "createHashBis"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "crypto.createHash"); + assert.strictEqual(eventOne.id, "createHash"); - tape.end(); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "crypto.createHash"); + assert.strictEqual(eventTwo.id, "createHashBis"); }); -test("it should be able to Trace crypto.createHash with CommonJS require and with a computed method with a Literal", (tape) => { +test("it should be able to Trace crypto.createHash with CommonJS require and with a computed method with a Literal", () => { const helpers = createTracer(); helpers.tracer.trace("crypto.createHash", { followConsecutiveAssignment: true, @@ -128,28 +123,26 @@ test("it should be able to Trace crypto.createHash with CommonJS require and wit createHashBis("md5"); `); - tape.strictEqual(helpers.tracer.importedModules.has("crypto"), true); + assert.strictEqual(helpers.tracer.importedModules.has("crypto"), true); const createHashBis = helpers.tracer.getDataFromIdentifier("createHashBis"); - tape.deepEqual(createHashBis, { + assert.deepEqual(createHashBis, { name: "crypto.createHash", identifierOrMemberExpr: "crypto.createHash", assignmentMemory: ["createHashBis"] }); - tape.strictEqual(assignments.length, 2); + assert.strictEqual(assignments.length, 2); const [eventOne, eventTwo] = assignments; - tape.strictEqual(eventOne.identifierOrMemberExpr, "crypto"); - tape.strictEqual(eventOne.id, "crypto"); + assert.strictEqual(eventOne.identifierOrMemberExpr, "crypto"); + assert.strictEqual(eventOne.id, "crypto"); - tape.strictEqual(eventTwo.identifierOrMemberExpr, "crypto.createHash"); - tape.strictEqual(eventTwo.id, "createHashBis"); - - tape.end(); + assert.strictEqual(eventTwo.identifierOrMemberExpr, "crypto.createHash"); + assert.strictEqual(eventTwo.id, "createHashBis"); }); -test("it should not detect variable assignment since the crypto module is not imported", (tape) => { +test("it should not detect variable assignment since the crypto module is not imported", () => { const helpers = createTracer(); helpers.tracer.trace("crypto.createHash", { followConsecutiveAssignment: true, @@ -166,13 +159,11 @@ test("it should not detect variable assignment since the crypto module is not im _t("md5"); `); - tape.strictEqual(helpers.tracer.importedModules.has("crypto"), false); - tape.strictEqual(assignments.length, 0); - - tape.end(); + assert.strictEqual(helpers.tracer.importedModules.has("crypto"), false); + assert.strictEqual(assignments.length, 0); }); -test("it should return null because crypto.createHash is not imported from a module", (tape) => { +test("it should return null because crypto.createHash is not imported from a module", () => { const helpers = createTracer(true); helpers.tracer.trace("crypto.createHash", { followConsecutiveAssignment: true, @@ -188,7 +179,5 @@ test("it should return null because crypto.createHash is not imported from a mod `); const result = helpers.tracer.getDataFromIdentifier("crypto.createHash"); - tape.strictEqual(result, null); - - tape.end(); + assert.strictEqual(result, null); }); diff --git a/workspaces/estree-ast-utils/test/arrayExpressionToString.spec.js b/workspaces/estree-ast-utils/test/arrayExpressionToString.spec.js index 7de5156..2af64c1 100644 --- a/workspaces/estree-ast-utils/test/arrayExpressionToString.spec.js +++ b/workspaces/estree-ast-utils/test/arrayExpressionToString.spec.js @@ -1,12 +1,15 @@ +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; + // Import Third-party Dependencies -import test from "tape"; import { IteratorMatcher } from "iterator-matcher"; // Import Internal Dependencies import { arrayExpressionToString } from "../src/index.js"; import { codeToAst, getExpressionFromStatement, createTracer } from "./utils.js"; -test("given an ArrayExpression with two Literals then the iterable must return them one by one", (tape) => { +test("given an ArrayExpression with two Literals then the iterable must return them one by one", () => { const [astNode] = codeToAst("['foo', 'bar']"); const iter = arrayExpressionToString(getExpressionFromStatement(astNode)); @@ -15,12 +18,11 @@ test("given an ArrayExpression with two Literals then the iterable must return t .expect("bar") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 2); - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 2); }); -test("given an ArrayExpression with two Identifiers then the iterable must return value from the Tracer", (tape) => { +test("given an ArrayExpression with two Identifiers then the iterable must return value from the Tracer", () => { const { tracer } = createTracer(); tracer.literalIdentifiers.set("foo", "1"); tracer.literalIdentifiers.set("bar", "2"); @@ -33,14 +35,13 @@ test("given an ArrayExpression with two Identifiers then the iterable must retur .expect("2") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 2); - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 2); }); test(`given an ArrayExpression with two numbers then the function must convert them as char code - and return them in the iterable`, (tape) => { + and return them in the iterable`, () => { const [astNode] = codeToAst("[65, 66]"); const iter = arrayExpressionToString(getExpressionFromStatement(astNode)); @@ -49,27 +50,24 @@ test(`given an ArrayExpression with two numbers .expect("B") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 2); - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 2); }); -test("given an ArrayExpression with empty Literals then the iterable must return no values", (tape) => { +test("given an ArrayExpression with empty Literals then the iterable must return no values", () => { const [astNode] = codeToAst("['', '']"); const iter = arrayExpressionToString(getExpressionFromStatement(astNode)); const iterResult = [...iter]; - tape.strictEqual(iterResult.length, 0); - tape.end(); + assert.strictEqual(iterResult.length, 0); }); -test("given an AST that is not an ArrayExpression then it must return immediately", (tape) => { +test("given an AST that is not an ArrayExpression then it must return immediately", () => { const [astNode] = codeToAst("const foo = 5;"); const iter = arrayExpressionToString(astNode); const iterResult = [...iter]; - tape.strictEqual(iterResult.length, 0); - tape.end(); + assert.strictEqual(iterResult.length, 0); }); diff --git a/workspaces/estree-ast-utils/test/concatBinaryExpression.spec.js b/workspaces/estree-ast-utils/test/concatBinaryExpression.spec.js index 630d5a9..1508ad0 100644 --- a/workspaces/estree-ast-utils/test/concatBinaryExpression.spec.js +++ b/workspaces/estree-ast-utils/test/concatBinaryExpression.spec.js @@ -1,12 +1,15 @@ +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; + // Import Third-party Dependencies -import test from "tape"; import { IteratorMatcher } from "iterator-matcher"; // Import Internal Dependencies import { concatBinaryExpression } from "../src/index.js"; import { codeToAst, getExpressionFromStatement, createTracer } from "./utils.js"; -test("given a BinaryExpression of two literals then the iterable must return Literal values", (tape) => { +test("given a BinaryExpression of two literals then the iterable must return Literal values", () => { const [astNode] = codeToAst("'foo' + 'bar' + 'xd'"); const iter = concatBinaryExpression(getExpressionFromStatement(astNode)); @@ -16,12 +19,11 @@ test("given a BinaryExpression of two literals then the iterable must return Lit .expect("xd") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 3); - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 3); }); -test("given a BinaryExpression of two ArrayExpression then the iterable must return Array values as string", (tape) => { +test("given a BinaryExpression of two ArrayExpression then the iterable must return Array values as string", () => { const [astNode] = codeToAst("['A'] + ['B']"); const iter = concatBinaryExpression(getExpressionFromStatement(astNode)); @@ -30,12 +32,11 @@ test("given a BinaryExpression of two ArrayExpression then the iterable must ret .expect("B") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 2); - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 2); }); -test("given a BinaryExpression of two Identifiers then the iterable must the tracer values", (tape) => { +test("given a BinaryExpression of two Identifiers then the iterable must the tracer values", () => { const { tracer } = createTracer(); tracer.literalIdentifiers.set("foo", "A"); tracer.literalIdentifiers.set("bar", "B"); @@ -48,13 +49,11 @@ test("given a BinaryExpression of two Identifiers then the iterable must the tra .expect("B") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 2); - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 2); }); -test("given a one level BinaryExpression with an unsupported node it should throw an Error", (tape) => { - tape.plan(1); +test("given a one level BinaryExpression with an unsupported node it should throw an Error", () => { const { tracer } = createTracer(); const [astNode] = codeToAst("evil() + 's'"); @@ -66,14 +65,11 @@ test("given a one level BinaryExpression with an unsupported node it should thro iter.next(); } catch (error) { - tape.strictEqual(error.message, "concatBinaryExpression:: Unsupported node detected"); + assert.strictEqual(error.message, "concatBinaryExpression:: Unsupported node detected"); } - - tape.end(); }); -test("given a Deep BinaryExpression with an unsupported node it should throw an Error", (tape) => { - tape.plan(1); +test("given a Deep BinaryExpression with an unsupported node it should throw an Error", () => { const { tracer } = createTracer(); const [astNode] = codeToAst("'a' + evil() + 's'"); @@ -85,8 +81,6 @@ test("given a Deep BinaryExpression with an unsupported node it should throw an iter.next(); } catch (error) { - tape.strictEqual(error.message, "concatBinaryExpression:: Unsupported node detected"); + assert.strictEqual(error.message, "concatBinaryExpression:: Unsupported node detected"); } - - tape.end(); }); diff --git a/workspaces/estree-ast-utils/test/extractLogicalExpression.spec.js b/workspaces/estree-ast-utils/test/extractLogicalExpression.spec.js index 22d6443..143c991 100644 --- a/workspaces/estree-ast-utils/test/extractLogicalExpression.spec.js +++ b/workspaces/estree-ast-utils/test/extractLogicalExpression.spec.js @@ -1,31 +1,30 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import { extractLogicalExpression } from "../src/index.js"; import { codeToAst, getExpressionFromStatement } from "./utils.js"; -test("it should extract two Nodes from a LogicalExpression with two operands", (tape) => { +test("it should extract two Nodes from a LogicalExpression with two operands", () => { const [astNode] = codeToAst("5 || 10"); const iter = extractLogicalExpression( getExpressionFromStatement(astNode) ); const iterResult = [...iter]; - tape.strictEqual(iterResult.length, 2); + assert.strictEqual(iterResult.length, 2); - tape.strictEqual(iterResult[0].operator, "||"); - tape.strictEqual(iterResult[0].node.type, "Literal"); - tape.strictEqual(iterResult[0].node.value, 5); + assert.strictEqual(iterResult[0].operator, "||"); + assert.strictEqual(iterResult[0].node.type, "Literal"); + assert.strictEqual(iterResult[0].node.value, 5); - tape.strictEqual(iterResult[1].operator, "||"); - tape.strictEqual(iterResult[1].node.type, "Literal"); - tape.strictEqual(iterResult[1].node.value, 10); - - tape.end(); + assert.strictEqual(iterResult[1].operator, "||"); + assert.strictEqual(iterResult[1].node.type, "Literal"); + assert.strictEqual(iterResult[1].node.value, 10); }); -test("it should extract all nodes and add up all Literal values", (tape) => { +test("it should extract all nodes and add up all Literal values", () => { const [astNode] = codeToAst("5 || 10 || 15 || 20"); const iter = extractLogicalExpression( getExpressionFromStatement(astNode) @@ -33,12 +32,10 @@ test("it should extract all nodes and add up all Literal values", (tape) => { const total = [...iter] .reduce((previous, { node }) => previous + node.value, 0); - tape.strictEqual(total, 50); - - tape.end(); + assert.strictEqual(total, 50); }); -test("it should extract all Nodes but with different operators and a LogicalExpr on the right", (tape) => { +test("it should extract all Nodes but with different operators and a LogicalExpr on the right", () => { const [astNode] = codeToAst("5 || 10 && 55"); const iter = extractLogicalExpression( getExpressionFromStatement(astNode) @@ -47,7 +44,5 @@ test("it should extract all Nodes but with different operators and a LogicalExpr const operators = new Set( [...iter].map(({ operator }) => operator) ); - tape.deepEqual([...operators], ["||", "&&"]); - - tape.end(); + assert.deepEqual([...operators], ["||", "&&"]); }); diff --git a/workspaces/estree-ast-utils/test/getCallExpressionIdentifier.spec.js b/workspaces/estree-ast-utils/test/getCallExpressionIdentifier.spec.js index 67778f0..2e98a84 100644 --- a/workspaces/estree-ast-utils/test/getCallExpressionIdentifier.spec.js +++ b/workspaces/estree-ast-utils/test/getCallExpressionIdentifier.spec.js @@ -1,66 +1,61 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import { getCallExpressionIdentifier } from "../src/index.js"; import { codeToAst, getExpressionFromStatement } from "./utils.js"; -test("given a JavaScript eval CallExpression then it must return eval", (tape) => { +test("given a JavaScript eval CallExpression then it must return eval", () => { const [astNode] = codeToAst("eval(\"this\");"); const nodeIdentifier = getCallExpressionIdentifier(getExpressionFromStatement(astNode)); - tape.strictEqual(nodeIdentifier, "eval"); - tape.end(); + assert.strictEqual(nodeIdentifier, "eval"); }); -test("given a Function(`...`)() Double CallExpression then it must return the Function literal identifier", (tape) => { +test("given a Function(`...`)() Double CallExpression then it must return the Function literal identifier", () => { const [astNode] = codeToAst("Function(\"return this\")();"); const nodeIdentifier = getCallExpressionIdentifier(getExpressionFromStatement(astNode)); - tape.strictEqual(nodeIdentifier, "Function"); - tape.end(); + assert.strictEqual(nodeIdentifier, "Function"); }); test(`given a Function("...")() Double CallExpression with resolveCallExpression options disabled -then it must return null`, (tape) => { +then it must return null`, () => { const [astNode] = codeToAst("Function(\"return this\")();"); const nodeIdentifier = getCallExpressionIdentifier( getExpressionFromStatement(astNode), { resolveCallExpression: false } ); - tape.strictEqual(nodeIdentifier, null); - tape.end(); + assert.strictEqual(nodeIdentifier, null); }); -test("given a JavaScript AssignmentExpression then it must return null", (tape) => { +test("given a JavaScript AssignmentExpression then it must return null", () => { const [astNode] = codeToAst("foo = 10;"); const nodeIdentifier = getCallExpressionIdentifier(getExpressionFromStatement(astNode)); - tape.strictEqual(nodeIdentifier, null); - tape.end(); + assert.strictEqual(nodeIdentifier, null); }); test(`given a require statement immediatly invoked with resolveCallExpression options enabled -then it must return require literal identifier`, (tape) => { +then it must return require literal identifier`, () => { const [astNode] = codeToAst("require('foo')();"); const nodeIdentifier = getCallExpressionIdentifier( getExpressionFromStatement(astNode), { resolveCallExpression: true } ); - tape.strictEqual(nodeIdentifier, "require"); - tape.end(); + assert.strictEqual(nodeIdentifier, "require"); }); test(`given a require statement immediatly invoked with resolveCallExpression options disabled -then it must return null`, (tape) => { +then it must return null`, () => { const [astNode] = codeToAst("require('foo')();"); const nodeIdentifier = getCallExpressionIdentifier( getExpressionFromStatement(astNode), { resolveCallExpression: false } ); - tape.strictEqual(nodeIdentifier, null); - tape.end(); + assert.strictEqual(nodeIdentifier, null); }); diff --git a/workspaces/estree-ast-utils/test/getMemberExpressionIdentifier.spec.js b/workspaces/estree-ast-utils/test/getMemberExpressionIdentifier.spec.js index 8761e78..d9f33fd 100644 --- a/workspaces/estree-ast-utils/test/getMemberExpressionIdentifier.spec.js +++ b/workspaces/estree-ast-utils/test/getMemberExpressionIdentifier.spec.js @@ -1,12 +1,15 @@ +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; + // Import Third-party Dependencies -import test from "tape"; import { IteratorMatcher } from "iterator-matcher"; // Import Internal Dependencies import { getMemberExpressionIdentifier } from "../src/index.js"; import { codeToAst, createTracer, getExpressionFromStatement } from "./utils.js"; -test("it must return all literals part of the given MemberExpression", (tape) => { +test("it must return all literals part of the given MemberExpression", () => { const [astNode] = codeToAst("foo.bar.xd"); const iter = getMemberExpressionIdentifier( getExpressionFromStatement(astNode) @@ -18,12 +21,11 @@ test("it must return all literals part of the given MemberExpression", (tape) => .expect("xd") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 3); - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 3); }); -test("it must return all computed properties of the given MemberExpression", (tape) => { +test("it must return all computed properties of the given MemberExpression", () => { const [astNode] = codeToAst("foo['bar']['xd']"); const iter = getMemberExpressionIdentifier( getExpressionFromStatement(astNode) @@ -35,14 +37,12 @@ test("it must return all computed properties of the given MemberExpression", (ta .expect("xd") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 3); - - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 3); }); test(`given a MemberExpression with a computed property containing a deep tree of BinaryExpression - then it must return all literals parts even the last one which is the concatenation of the BinaryExpr`, (tape) => { + then it must return all literals parts even the last one which is the concatenation of the BinaryExpr`, () => { const [astNode] = codeToAst("foo.bar[\"k\" + \"e\" + \"y\"]"); const iter = getMemberExpressionIdentifier( getExpressionFromStatement(astNode) @@ -54,14 +54,12 @@ test(`given a MemberExpression with a computed property containing a deep tree o .expect("key") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 3); - - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 3); }); test(`given a MemberExpression with computed properties containing identifiers - then it must return all literals values from the tracer`, (tape) => { + then it must return all literals values from the tracer`, () => { const { tracer } = createTracer(); tracer.literalIdentifiers.set("foo", "hello"); tracer.literalIdentifiers.set("yo", "bar"); @@ -77,8 +75,6 @@ test(`given a MemberExpression with computed properties containing identifiers .expect("bar") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 3); - - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 3); }); diff --git a/workspaces/estree-ast-utils/test/isLiteralRegex.spec.js b/workspaces/estree-ast-utils/test/isLiteralRegex.spec.js index 97dd7be..4f0434c 100644 --- a/workspaces/estree-ast-utils/test/isLiteralRegex.spec.js +++ b/workspaces/estree-ast-utils/test/isLiteralRegex.spec.js @@ -1,22 +1,21 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import { isLiteralRegex } from "../src/index.js"; import { codeToAst, getExpressionFromStatement } from "./utils.js"; -test("given a Literal Regex Node it should return true", (tape) => { +test("given a Literal Regex Node it should return true", () => { const [astNode] = codeToAst("/^a/g"); const isLRegex = isLiteralRegex(getExpressionFromStatement(astNode)); - tape.strictEqual(isLRegex, true); - tape.end(); + assert.strictEqual(isLRegex, true); }); -test("given a RegexObject Node it should return false", (tape) => { +test("given a RegexObject Node it should return false", () => { const [astNode] = codeToAst("new RegExp('^hello')"); const isLRegex = isLiteralRegex(getExpressionFromStatement(astNode)); - tape.strictEqual(isLRegex, false); - tape.end(); + assert.strictEqual(isLRegex, false); }); diff --git a/workspaces/estree-ast-utils/test/utils/getSubMemberExpressionSegments.spec.js b/workspaces/estree-ast-utils/test/utils/getSubMemberExpressionSegments.spec.js index bab8c93..0182815 100644 --- a/workspaces/estree-ast-utils/test/utils/getSubMemberExpressionSegments.spec.js +++ b/workspaces/estree-ast-utils/test/utils/getSubMemberExpressionSegments.spec.js @@ -1,11 +1,14 @@ +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; + // Import Third-party Dependencies -import test from "tape"; import { IteratorMatcher } from "iterator-matcher"; // Import Internal Dependencies import { getSubMemberExpressionSegments } from "../../src/utils/index.js"; -test("given a MemberExpression then it should return each segments (except the last one)", (tape) => { +test("given a MemberExpression then it should return each segments (except the last one)", () => { const iter = getSubMemberExpressionSegments("foo.bar.xd"); const iterResult = new IteratorMatcher() @@ -13,7 +16,6 @@ test("given a MemberExpression then it should return each segments (except the l .expect("foo.bar") .execute(iter, { allowNoMatchingValues: false }); - tape.strictEqual(iterResult.isMatching, true); - tape.strictEqual(iterResult.elapsedSteps, 2); - tape.end(); + assert.strictEqual(iterResult.isMatching, true); + assert.strictEqual(iterResult.elapsedSteps, 2); }); diff --git a/workspaces/estree-ast-utils/test/utils/isEvilIdentifierPath.spec.js b/workspaces/estree-ast-utils/test/utils/isEvilIdentifierPath.spec.js index 9affdf9..8e260d1 100644 --- a/workspaces/estree-ast-utils/test/utils/isEvilIdentifierPath.spec.js +++ b/workspaces/estree-ast-utils/test/utils/isEvilIdentifierPath.spec.js @@ -1,28 +1,25 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import { isEvilIdentifierPath } from "../../src/utils/index.js"; -test("given a random prototype method name then it should return false", (tape) => { +test("given a random prototype method name then it should return false", () => { const result = isEvilIdentifierPath( "Function.prototype.foo" ); - tape.strictEqual(result, false); - - tape.end(); + assert.strictEqual(result, false); }); -test("given a list of evil identifiers it should always return true", (tape) => { +test("given a list of evil identifiers it should always return true", () => { const evilIdentifiers = [ "Function.prototype.bind", "Function.prototype.call", "Function.prototype.apply" ]; for (const identifier of evilIdentifiers) { - tape.strictEqual(isEvilIdentifierPath(identifier), true); + assert.strictEqual(isEvilIdentifierPath(identifier), true); } - - tape.end(); }); diff --git a/workspaces/estree-ast-utils/test/utils/notNullOrUndefined.spec.js b/workspaces/estree-ast-utils/test/utils/notNullOrUndefined.spec.js index 4f7c031..33d55a9 100644 --- a/workspaces/estree-ast-utils/test/utils/notNullOrUndefined.spec.js +++ b/workspaces/estree-ast-utils/test/utils/notNullOrUndefined.spec.js @@ -1,21 +1,18 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { test } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import { notNullOrUndefined } from "../../src/utils/index.js"; -test("given a null or undefined primitive value then it must always return false", (tape) => { - tape.strictEqual(notNullOrUndefined(null), false, "null primitive value should return false"); - tape.strictEqual(notNullOrUndefined(void 0), false, "undefined primitive value should return false"); - - tape.end(); +test("given a null or undefined primitive value then it must always return false", () => { + assert.strictEqual(notNullOrUndefined(null), false, "null primitive value should return false"); + assert.strictEqual(notNullOrUndefined(void 0), false, "undefined primitive value should return false"); }); -test("given values (primitive or objects) that are not null or undefined then it must always return true", (tape) => { +test("given values (primitive or objects) that are not null or undefined then it must always return true", () => { const valuesToAssert = ["", 1, true, Symbol("foo"), {}, [], /^xd/g]; for (const value of valuesToAssert) { - tape.strictEqual(notNullOrUndefined(value), true); + assert.strictEqual(notNullOrUndefined(value), true); } - - tape.end(); });