Skip to content

Commit

Permalink
added tests for @match validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oaphi committed Aug 10, 2021
1 parent f66dbdc commit 611a516
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ describe("main", () => {
"notify",
];

const directCommon: GeneratorOptions<TampermonkeyGrantOptions> = {
...common,
direct: true,
};

describe("CLI Options", async function () {
this.timeout(5e3);

Expand Down Expand Up @@ -173,14 +178,29 @@ describe("main", () => {
});
});

describe("common", () => {
it("should skip invalid match headers", async () => {
const invalid = ["oranges", "42!"];
const matches = ["<all_urls>", "urn:*", ...invalid];

const content = await generate("tampermonkey", {
...directCommon,
matches,
});

matches
.map((m) => m.replace(/(\*)/, "\\$1"))
.forEach((m) => {
const status = new RegExp(`\\s+${m}$`, "m").test(content);
expect(status !== invalid.includes(m), `failure at ${m}`).to
.be.true;
});
});
});

describe("Tampermonkey", async () => {
const artefacts: string[] = [];

const directCommon: GeneratorOptions<TampermonkeyGrantOptions> = {
...common,
direct: true,
};

//make sure test output will be cleared
beforeEach(() => artefacts.push(output));

Expand Down

0 comments on commit 611a516

Please # to comment.