next-affected
Version:
CLI tool to list Next.js pages affected by changes
46 lines (45 loc) • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const graph_1 = require("./graph");
const utils_1 = require("./utils");
jest.mock("fs");
jest.mock("madge");
jest.mock("path");
jest.mock("typescript");
jest.mock("./utils");
describe("findAffectedPages", () => {
const mockDependencyGraph = {
"file1.ts": ["file2.ts"],
"file2.ts": [],
};
const mockConfig = {
pagesDirectories: ["pages"],
excludedExtensions: [".css"],
excludedPaths: [],
};
const mockProjectDir = "/path/to/project";
const mockChangedComponent = "file1.ts";
beforeEach(() => {
jest.clearAllMocks();
utils_1.normalizePath.mockImplementation((path) => path);
utils_1.shouldExcludeModule.mockReturnValue(false);
utils_1.isPage.mockReturnValue(false);
});
it("should find affected pages based on the dependency graph", () => {
utils_1.isPage.mockReturnValueOnce(true);
utils_1.getRouteFromPage.mockReturnValue("/mockedRoute");
const affectedPages = (0, graph_1.findAffectedPages)(mockDependencyGraph, mockChangedComponent, mockProjectDir, mockConfig, Infinity);
expect(utils_1.normalizePath).toHaveBeenCalled();
expect(affectedPages).toEqual(["/mockedRoute"]);
});
it("should not traverse beyond the maxDepth", () => {
const affectedPages = (0, graph_1.findAffectedPages)(mockDependencyGraph, mockChangedComponent, mockProjectDir, mockConfig, 1);
expect(affectedPages).toEqual([]);
});
it("should exclude modules if shouldExcludeModule returns true", () => {
utils_1.shouldExcludeModule.mockReturnValue(true);
const affectedPages = (0, graph_1.findAffectedPages)(mockDependencyGraph, mockChangedComponent, mockProjectDir, mockConfig, Infinity);
expect(affectedPages).toEqual([]);
expect(utils_1.shouldExcludeModule).toHaveBeenCalled();
});
});