Skip to content

Commit

Permalink
refactor(test): import from project entry file to avoid issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken committed May 18, 2024
1 parent 69272f6 commit 777ed54
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
34 changes: 17 additions & 17 deletions test/AstAnalyser.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable max-nested-callbacks */
// Import Node.js Dependencies
import { describe, it } from "node:test";
import assert from "node:assert";
import { readFileSync } from "node:fs";

// Import Internal Dependencies
import { AstAnalyser } from "../src/AstAnalyser.js";
import { JsSourceParser } from "../src/JsSourceParser.js";
import { AstAnalyser, JsSourceParser } from "../index.js";
import { SourceFile } from "../src/SourceFile.js";
import {
customProbes,
Expand Down Expand Up @@ -255,7 +255,7 @@ describe("AstAnalyser", (t) => {
});

describe("analyseFile", () => {
it("remove the packageName from the dependencies list", async () => {
it("remove the packageName from the dependencies list", async() => {
const result = await getAnalyser().analyseFile(
new URL("depName.js", FIXTURE_URL),
{ module: false, packageName: "foobar" }
Expand All @@ -268,7 +268,7 @@ describe("AstAnalyser", (t) => {
);
});

it("should fail with a parsing error", async () => {
it("should fail with a parsing error", async() => {
const result = await getAnalyser().analyseFile(
new URL("parsingError.js", FIXTURE_URL),
{ module: false, packageName: "foobar" }
Expand All @@ -286,18 +286,18 @@ describe("AstAnalyser", (t) => {
const url = new URL("depName.js", FIXTURE_URL);

describe("initialize", () => {
it("should throw if initialize is not a function", async () => {
it("should throw if initialize is not a function", async() => {
const res = await analyser.analyseFile(
url, {
initialize: "foo"
});
initialize: "foo"
});

assert.strictEqual(res.ok, false);
assert.strictEqual(res.warnings[0].value, "options.initialize must be a function");
assert.strictEqual(res.warnings[0].kind, "parsing-error");
});

it("should call the initialize function", async (t) => {
it("should call the initialize function", async(t) => {
const initialize = t.mock.fn();

await analyser.analyseFile(url, {
Expand All @@ -307,7 +307,7 @@ describe("AstAnalyser", (t) => {
assert.strictEqual(initialize.mock.callCount(), 1);
});

it("should pass the source file as first argument", async (t) => {
it("should pass the source file as first argument", async(t) => {
const initialize = t.mock.fn();

await analyser.analyseFile(url, {
Expand All @@ -319,18 +319,18 @@ describe("AstAnalyser", (t) => {
});

describe("finalize", () => {
it("should throw if finalize is not a function", async () => {
it("should throw if finalize is not a function", async() => {
const res = await analyser.analyseFile(
url, {
finalize: "foo"
});
finalize: "foo"
});

assert.strictEqual(res.ok, false);
assert.strictEqual(res.warnings[0].value, "options.finalize must be a function");
assert.strictEqual(res.warnings[0].kind, "parsing-error");
});

it("should call the finalize function", async (t) => {
it("should call the finalize function", async(t) => {
const finalize = t.mock.fn();

await analyser.analyseFile(url, {
Expand All @@ -340,7 +340,7 @@ describe("AstAnalyser", (t) => {
assert.strictEqual(finalize.mock.callCount(), 1);
});

it("should pass the source file as first argument", async (t) => {
it("should pass the source file as first argument", async(t) => {
const finalize = t.mock.fn();

await analyser.analyseFile(url, {
Expand All @@ -352,7 +352,7 @@ describe("AstAnalyser", (t) => {
});


it("intialize should be called before finalize", async () => {
it("intialize should be called before finalize", async() => {
const calls = [];

await analyser.analyseFile(url, {
Expand Down Expand Up @@ -411,8 +411,8 @@ describe("AstAnalyser", (t) => {
it("should remove multiple HTML comments", () => {
const preparedSource = getAnalyser().prepareSource(
"<!-- const yo = 5; -->\nconst yo = 'foo'\n<!-- const yo = 5; -->", {
removeHTMLComments: true
});
removeHTMLComments: true
});

assert.strictEqual(preparedSource, "\nconst yo = 'foo'\n");
});
Expand Down
2 changes: 1 addition & 1 deletion test/Deobfuscator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { walk } from "estree-walker";

// Import Internal Dependencies
import { Deobfuscator } from "../src/Deobfuscator.js";
import { JsSourceParser } from "../src/JsSourceParser.js";
import { JsSourceParser } from "../index.js";

describe("Deobfuscator", () => {
describe("identifiers and counters", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/JsSourceParser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { describe, it } from "node:test";

// Import Internal Dependencies
import { JsSourceParser } from "../src/JsSourceParser.js";
import { JsSourceParser } from "../index.js";

describe("JsSourceParser", () => {
describe("parse", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/NodeCounter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { walk } from "estree-walker";

// Import Internal Dependencies
import { NodeCounter } from "../src/NodeCounter.js";
import { JsSourceParser } from "../src/JsSourceParser.js";
import { isNode } from "../src/utils/index.js";
import { JsSourceParser } from "../index.js";

describe("NodeCounter", () => {
describe("constructor", () => {
Expand Down
4 changes: 1 addition & 3 deletions test/runASTAnalysis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { it } from "node:test";
import assert from "node:assert";

// Import Internal Dependencies
import { runASTAnalysis } from "../index.js";
import { AstAnalyser } from "../src/AstAnalyser.js";
import { JsSourceParser } from "../src/JsSourceParser.js";
import { runASTAnalysis, AstAnalyser, JsSourceParser } from "../index.js";
import { FakeSourceParser } from "./fixtures/FakeSourceParser.js";
import {
customProbes,
Expand Down
4 changes: 1 addition & 3 deletions test/runASTAnalysisOnFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { it } from "node:test";
import assert from "node:assert";

// Import Internal Dependencies
import { runASTAnalysisOnFile } from "../index.js";
import { AstAnalyser } from "../src/AstAnalyser.js";
import { runASTAnalysisOnFile, AstAnalyser, JsSourceParser } from "../index.js";
import { FakeSourceParser } from "./fixtures/FakeSourceParser.js";
import { JsSourceParser } from "../src/JsSourceParser.js";
import { customProbes, kWarningUnsafeDanger, kWarningUnsafeImport, kWarningUnsafeStmt } from "./utils/index.js";

// CONSTANTS
Expand Down

0 comments on commit 777ed54

Please sign in to comment.