Skip to content

Commit a99ba34

Browse files
committed
refactor: replace legacy __dirname with import.meta.dirname
1 parent fef0bca commit a99ba34

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

test/extractor/index.unit.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Import Node.js Dependencies
22
import path from "node:path";
3-
import { fileURLToPath } from "node:url";
43
import { test } from "node:test";
54
import assert from "node:assert";
65

@@ -11,7 +10,7 @@ import {
1110
} from "../../src/extractor/index.ts";
1211

1312
// CONSTANTS
14-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
13+
const __dirname = import.meta.dirname;
1514
const kFixturesDir = path.join(__dirname, "..", "fixtures");
1615
const kExtractorFixture = path.join(kFixturesDir, "extractor");
1716

@@ -36,14 +35,24 @@ test("NodeDependencyExtractor: extract() does not include the root package", asy
3635
const extractor = new NodeDependencyExtractor();
3736
const packages = await extractor.extract(kExtractorFixture);
3837

39-
const rootEntry = packages.find((pkg) => pkg.name === "test-extractor-project");
40-
assert.strictEqual(rootEntry, undefined, "the root package must not appear in results");
38+
const rootEntry = packages.find(
39+
(pkg) => pkg.name === "test-extractor-project"
40+
);
41+
assert.strictEqual(
42+
rootEntry,
43+
undefined,
44+
"the root package must not appear in results"
45+
);
4146
});
4247

4348
test("NodeDependencyExtractor: extract() returns no duplicate name@version pairs", async() => {
4449
const extractor = new NodeDependencyExtractor();
4550
const packages = await extractor.extract(kExtractorFixture);
4651

4752
const specs = new Set(packages.map((pkg) => `${pkg.name}@${pkg.version}`));
48-
assert.strictEqual(specs.size, packages.length, "must not contain duplicate name@version entries");
53+
assert.strictEqual(
54+
specs.size,
55+
packages.length,
56+
"must not contain duplicate name@version entries"
57+
);
4958
});

test/strategies/github_advisory_npm/index.integration.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Import Node.js Dependencies
22
import path from "node:path";
3-
import { fileURLToPath } from "node:url";
43
import { test } from "node:test";
54
import assert from "node:assert";
65

@@ -14,7 +13,7 @@ import {
1413
} from "../utils.ts";
1514

1615
// CONSTANTS
17-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
16+
const __dirname = import.meta.dirname;
1817
const kFixturesDir = path.join(__dirname, "..", "..", "fixtures");
1918

2019
function expectNpmAuditVulnToBeGithubAdvisory(vuln: NpmAuditAdvisory) {

test/strategies/github_advisory_pnpm/index.integration.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Import Node.js Dependencies
22
import path from "node:path";
3-
import { fileURLToPath } from "node:url";
43
import { test } from "node:test";
54
import assert from "node:assert";
65

@@ -12,7 +11,7 @@ import {
1211
import { expectVulnToBeNodeSecureStandardCompliant } from "../utils.ts";
1312

1413
// CONSTANTS
15-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
14+
const __dirname = import.meta.dirname;
1615
const kFixturesDir = path.join(__dirname, "..", "..", "fixtures");
1716

1817
function expectNpmVulnToBePnpmAdvisory(vuln: PnpmAuditAdvisory) {

0 commit comments

Comments
 (0)