Skip to content

Commit

Permalink
updated test suite to share @match URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Oaphi committed Jul 10, 2021
1 parent 02f3d54 commit 850009b
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ describe("main", () => {

const common: GeneratorOptions = { output, packagePath: pkg };

//@see https://developer.chrome.com/docs/extensions/mv2/match_patterns/
const allMatches: string[] = [
"http://*/*",
"http://*/foo*",
"https://*.google.com/foo*bar",
"http://example.org/foo/bar.html",
"file:///foo*",
"http://127.0.0.1/*",
"*://mail.google.com/*",
"urn:*",
"<all_urls>",
];

const grantsTM: TampermonkeyGrants[] = [
"GM_getValue",
"GM_setValue",
Expand Down Expand Up @@ -99,27 +112,14 @@ describe("main", () => {
});

it("-m options should correctly add @matches", async () => {
//@see https://developer.chrome.com/docs/extensions/mv2/match_patterns/
const matches: string[] = [
"http://*/*",
"http://*/foo*",
"https://*.google.com/foo*bar",
"http://example.org/foo/bar.html",
"file:///foo*",
"http://127.0.0.1/*",
"*://mail.google.com/*",
"urn:*",
"<all_urls>",
];

const mOpts = matches.map((m) => `-m "${m}"`).join(" ");
const mOpts = allMatches.map((m) => `-m "${m}"`).join(" ");

const { stdout } = await aexec(
`ts-node ${entry} tampermonkey ${mOpts} -p ${pkg} -o ${output} -d`
);

const matched = stdout.match(/@match\s+(.+)/g) || [];
expect(matched).length(matches.length);
expect(matched).length(allMatches.length);
});

it("-s option should control number of spaces added", async () => {
Expand Down Expand Up @@ -167,26 +167,13 @@ describe("main", () => {
});

it("@match headers should be generated", async () => {
//@see https://developer.chrome.com/docs/extensions/mv2/match_patterns/
const matches: string[] = [
"http://*/*",
"http://*/foo*",
"https://*.google.com/foo*bar",
"http://example.org/foo/bar.html",
"file:///foo*",
"http://127.0.0.1/*",
"*://mail.google.com/*",
"urn:*",
"<all_urls>",
];

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

const matched = content.match(/@match\s+(.+)/g) || [];
expect(matched).length(matches.length);
expect(matched).length(allMatches.length);
});

it("@grant headers should be generated", async () => {
Expand Down

0 comments on commit 850009b

Please # to comment.