Skip to content

Commit

Permalink
fix tests in node 20
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Griffiths committed Aug 25, 2024
1 parent 60cf637 commit 767018b
Show file tree
Hide file tree
Showing 4 changed files with 1,084 additions and 764 deletions.
23 changes: 15 additions & 8 deletions __tests__/rules.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mockFilesystem from "mock-fs";
import { vol, fs } from "memfs";

import { getConfig } from "../src/utils/getConfig";
import { isCorrectRuleType } from "../src/utils/isCorrectRuleType";
Expand All @@ -8,14 +8,19 @@ import { getSubsequentPaths } from "../src/utils/getSubsequentPaths";
/**
* Prevent process.exit calls from killing jest
*/
jest.spyOn(process, "exit").mockImplementation((code: number): never => {
jest.spyOn(process, "exit").mockImplementation((code): never => {
return null as never;
});

afterEach(mockFilesystem.restore);
jest.mock("fs", () => fs);
jest.mock("fs/promises", () => fs.promises);

afterEach(() => {
vol.reset();
});

it("can take a path rule and get all subsequent paths", async () => {
mockFilesystem({
vol.fromNestedJSON({
"components/really/long/_/path/structure/Example.tsx": "",
});

Expand All @@ -33,7 +38,7 @@ it("can take a path rule and get all subsequent paths", async () => {
});

it("can check if a path matches the rule type", async () => {
mockFilesystem({
vol.fromNestedJSON({
"components/button/Button.tsx": "",
});

Expand Down Expand Up @@ -70,14 +75,16 @@ it("can parse the config file", async () => {
rules: ["components/**/*.ts"],
};

mockFilesystem({
vol.fromNestedJSON({
".structurelintrc": JSON.stringify(config),
});

expect(getConfig()).toStrictEqual(config);
});

mockFilesystem({
".wrongfilename": JSON.stringify(config),
it("exists when the lint file does not exist", async () => {
vol.fromNestedJSON({
".wrongfilename": JSON.stringify({}),
});

getConfig();
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "tsc",
"pretest": "tsc --noEmit",
"test": "jest --collectCoverage",
"start": "esno src/index.ts"
"start": "tsx src/index.ts"
},
"bin": {
"structure-lint": "./dist/index.js"
Expand All @@ -37,17 +37,17 @@
"url": "git://github.com/Daniel-Griffiths/structure-lint.git"
},
"dependencies": {
"esno": "^0.15.0",
"fast-glob": "^3.2.11",
"minimatch": "^5.0.1",
"typescript": "^4.6.4"
"fast-glob": "^3.3.2",
"minimatch": "^10.0.1",
"tsx": "^4.18.0",
"typescript": "^5.5.4"
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/jest": "^27.5.0",
"@types/mock-fs": "^4.13.1",
"jest": "^28.1.0",
"mock-fs": "^5.1.2",
"ts-jest": "^28.0.2"
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.12",
"@types/mock-fs": "^4.13.4",
"jest": "^29.7.0",
"memfs": "^4.11.1",
"ts-jest": "^29.2.5"
}
}
2 changes: 1 addition & 1 deletion src/utils/getInvalidPaths.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import glob from "fast-glob";
import minimatch from "minimatch";
import { minimatch } from "minimatch";

import { IConfig } from "../interfaces/IConfig";
import { isCorrectRuleType } from "./isCorrectRuleType";
Expand Down
Loading

0 comments on commit 767018b

Please sign in to comment.