diff --git a/package.json b/package.json index 1ad2368..76a6e28 100644 --- a/package.json +++ b/package.json @@ -63,12 +63,10 @@ "@openally/config.eslint": "^1.0.0", "@openally/config.typescript": "^1.0.3", "@types/lodash.set": "^4.3.9", - "@types/mock-fs": "^4.13.4", "@types/node": "^22.3.0", "@types/pluralize": "^0.0.33", "@types/sade": "^1.7.8", "glob": "^11.0.0", - "mock-fs": "^5.2.0", "rimraf": "^6.0.1", "tsx": "^4.17.0", "typescript": "^5.0.4" diff --git a/src/configuration/external/nodesecure/index.spec.ts b/src/configuration/external/nodesecure/index.spec.ts index c6e27be..f07a990 100644 --- a/src/configuration/external/nodesecure/index.spec.ts +++ b/src/configuration/external/nodesecure/index.spec.ts @@ -1,14 +1,11 @@ // Import Node.js Dependencies import assert from "node:assert"; import { describe, it } from "node:test"; - -// Third-party Dependencies -import mock from "mock-fs"; +import fs from "node:fs/promises"; // Internal Dependencies import { IgnorePatterns, IgnoreWarningsPatterns } from "./ignore-file.js"; - -import { getIgnoreFile, kIgnoreFilePath } from "./index.js"; +import { getIgnoreFile } from "./index.js"; describe("getIgnoreFile", () => { const kDefaultIgnoreFileContent = IgnorePatterns.default(); @@ -19,70 +16,53 @@ describe("getIgnoreFile", () => { assert.deepEqual(result, kDefaultIgnoreFileContent); }); - it("should return empty object if file format is invalid", async() => { + it("should return empty object if file format is invalid", async(ctx) => { const invalidIgnoreFile = { foo: "bar" }; - createFakeIgnoreFile(JSON.stringify(invalidIgnoreFile)); + ctx.mock.method(fs, "readFile", () => Promise.resolve(JSON.stringify(invalidIgnoreFile))); const result = await getIgnoreFile(); assert.deepEqual(result, kDefaultIgnoreFileContent); - mock.restore(); }); - it("should return the ignore file if it's valid", async() => { + it("should return the ignore file if it's valid", async(ctx) => { const validIgnoreFile = { warnings: { "unsafe-regex": ["negotiator"] } }; - createFakeIgnoreFile(JSON.stringify(validIgnoreFile)); + ctx.mock.method(fs, "readFile", () => Promise.resolve(JSON.stringify(validIgnoreFile))); const result = await getIgnoreFile(); assert.ok(result instanceof IgnorePatterns); assert.notDeepEqual(result, {}); - mock.restore(); }); - it("should return an IgnorePatterns warnings property", async() => { + it("should return an IgnorePatterns warnings property", async(ctx) => { const validIgnoreFile = { warnings: { "unsafe-regex": ["negotiator"] } }; - createFakeIgnoreFile(JSON.stringify(validIgnoreFile)); + ctx.mock.method(fs, "readFile", () => Promise.resolve(JSON.stringify(validIgnoreFile))); const { warnings } = await getIgnoreFile(); assert.ok(warnings instanceof IgnoreWarningsPatterns); - mock.restore(); }); - it("should return an helper to check if a warning exist for a given pkg", async() => { + it("should return an helper to check if a warning exist for a given pkg", async(ctx) => { const validIgnoreFile = { warnings: { "unsafe-regex": ["negotiator"] } }; - createFakeIgnoreFile(JSON.stringify(validIgnoreFile)); + ctx.mock.method(fs, "readFile", () => Promise.resolve(JSON.stringify(validIgnoreFile))); const result = await getIgnoreFile(); assert.equal(result.warnings.has("unsafe-regex", "negotiator"), true); assert.equal(result.warnings.has("unsafe-regex", "express"), false); - mock.restore(); }); }); - -/** - * HELPERS - */ - -function createFakeIgnoreFile(fileContent: string): void { - mock( - { - [kIgnoreFilePath]: Buffer.from(fileContent) - }, - {} as any - ); -} diff --git a/src/configuration/external/nodesecure/index.ts b/src/configuration/external/nodesecure/index.ts index 5fcedcc..7b4d1d6 100644 --- a/src/configuration/external/nodesecure/index.ts +++ b/src/configuration/external/nodesecure/index.ts @@ -1,5 +1,5 @@ // Node.Js Dependencies -import { readFile } from "fs/promises"; +import fs from "fs/promises"; import { join } from "path"; // Import Third-party Dependencies @@ -93,7 +93,7 @@ export async function getNodeSecureConfig(): Promise< export async function getIgnoreFile(): Promise { const highlightedFilename = log.highlight(".nodesecureignore").message; try { - const ignoreFile = await readFile(kIgnoreFilePath, "utf8"); + const ignoreFile = await fs.readFile(kIgnoreFilePath, "utf8"); const ignoreObject = JSON.parse(ignoreFile); const { isValid, error } = validateIgnoreFile(ignoreObject); if (!isValid) {