Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/__tests__/unit/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from "../../helper.js";
import {
GOV_DEPENDENCIES,
GOV_DEPENDENCIES_PYPI,
normalizePyPIName,
USWDS,
USWDS_COMPILE,
CMS_DESIGN_SYSTEM,
Expand All @@ -15,6 +17,11 @@ import {
import { createMockDeps, createMockOctokit } from "../fixtures/mock-deps.js";
import { Dependencies } from "../../types/Dependencies.js";

const CUMULUS_MESSAGE_ADAPTER = {
name: "cumulus-message-adapter (NASA)",
URL: "https://github.com/nasa/cumulus-message-adapter",
};

// returns a readFile mock that serves content by filepath and rejects otherwise
function readFileFrom(files: Record<string, string>) {
return jest.fn<any>((filepath: string) =>
Expand Down Expand Up @@ -290,11 +297,15 @@ describe("createHelpers - detectReusedCode", () => {
it("matches a known gov dependency from requirements.txt", async () => {
const deps = createMockDeps({
readFile: readFileFrom({
"/github/workspace/requirements.txt": "uswds==3.0.0\nrequests==2.0",
// underscore/mixed-case name should normalize to the hyphenated PyPI key
"/github/workspace/requirements.txt":
"Cumulus_Message_Adapter==2.0\nrequests==2.0",
}),
});

expect(await createHelpers(deps).detectReusedCode()).toEqual([USWDS]);
expect(await createHelpers(deps).detectReusedCode()).toEqual([
CUMULUS_MESSAGE_ADAPTER,
]);
});

it("matches multiple distinct gov dependencies in one manifest", async () => {
Expand Down Expand Up @@ -470,7 +481,6 @@ describe("mergeReusedCode", () => {
expect(mergeReusedCode(undefined as any, [USWDS])).toEqual([USWDS]);
});
});

describe("GOV_DEPENDENCIES integrity", () => {
Comment thread
haseebmalik18 marked this conversation as resolved.
const entries = Object.entries(GOV_DEPENDENCIES);

Expand All @@ -480,3 +490,16 @@ describe("GOV_DEPENDENCIES integrity", () => {
expect(entry.URL).toMatch(/^https:\/\//);
});
});

describe("GOV_DEPENDENCIES_PYPI integrity", () => {
const entries = Object.entries(GOV_DEPENDENCIES_PYPI);

it.each(entries)(
"%s has a normalized key and a valid entry",
(key, entry) => {
expect(key).toBe(normalizePyPIName(key));
expect(entry.name.trim()).not.toBe("");
expect(entry.URL).toMatch(/^https:\/\//);
},
);
});
Loading
Loading