Skip to content

Commit

Permalink
generate actual test files instead of doing dynamic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Jun 21, 2024
1 parent fae85ac commit 6b14944
Show file tree
Hide file tree
Showing 41 changed files with 775 additions and 81 deletions.
119 changes: 58 additions & 61 deletions tests/act/act.js → generate-act-tests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { fixture, html, expect } from "@open-wc/testing";
import { scan } from "../../src/scanner";
import { mkdir, writeFile, readFile } from "node:fs/promises";

const response = await fetch("/testcases.json");
const json = await response.json();
const { testcases } = JSON.parse(await readFile("./testcases.json", "utf8"));

const applicableRules = json.testcases.filter(
const applicableRules = testcases.filter(
(rule) => rule.ruleAccessibilityRequirements,
);

Expand Down Expand Up @@ -126,67 +124,66 @@ const ignoredExamples = [
"https://act-rules.github.io/testcases/qt1vmo/0ef4f516db9ed70cb25f39c99637272808b8e60f.html",
];

describe("ACT Rules", function () {
for (const rule of applicableRules) {
const {
ruleId,
ruleName,
testcaseId,
testcaseTitle,
expected,
url: exampleURL,
ruleAccessibilityRequirements,
} = rule;
for (const rule of applicableRules) {
const {
ruleId,
ruleName,
testcaseId,
testcaseTitle,
expected,
url: exampleURL,
ruleAccessibilityRequirements,
} = rule;

if (testCasesThatRedirect.includes(testcaseId)) continue;
if (ruleName.includes("DEPRECATED")) continue;
if (rulesToIgnore.includes(ruleId)) continue;
if (ignoredExamples.includes(exampleURL)) continue;
if (testCasesThatRedirect.includes(testcaseId)) continue;
if (ruleName.includes("DEPRECATED")) continue;
if (rulesToIgnore.includes(ruleId)) continue;
if (ignoredExamples.includes(exampleURL)) continue;
// Ignore inapplicable results
if (expected === "inapplicable") continue;

if (
Object.keys(ruleAccessibilityRequirements).every(
(x) => !x.startsWith("wcag"),
)
console.log({ ruleId, testcaseId });

if (
Object.keys(ruleAccessibilityRequirements).every(
(x) => !x.startsWith("wcag"),
)
continue;
)
continue;

const html = await readFile(
`./tests/act/fixtures/${testcaseId}.html`,
"utf8",
);

let assertion = undefined;
if (expected === "passed") {
assertion = "expect(results).to.be.empty;";
} else if (expected === "failed") {
assertion = "expect(results).to.not.be.empty;";
} else {
throw new Error(`Unknown expected state: ${expected}`);
}

describe(`[${ruleId}] ${ruleName}`, function () {
it(`${testcaseTitle} (${exampleURL})`, async () => {
const testResponse = await fetch(
`/tests/act/fixtures/${testcaseId}.html`,
);
if (testResponse.status !== 200) {
throw new Error("Couldn't find testcase HTML");
}
const testHTML = await testResponse.text();
await fixture(testHTML);
const suite = `import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";
const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});
describe("[${ruleId}]${ruleName}", function () {
it("${testcaseTitle} (${exampleURL})", async () => {
await fixture(\`${html}\`);
try {
if (expected === "passed") {
expect(results).to.be.empty;
} else if (expected === "failed") {
expect(results).to.not.be.empty;
} else if (expected === "inapplicable") {
// Ignore inapplicable results
} else {
throw new Error(`Unknown expected state: ${expected}`);
}
} catch (error) {
console.log("=======");
console.log(`[${ruleId}] ${ruleName}`);
console.log(testcaseTitle);
console.log(`${testcaseId}.html`);
console.log(Object.keys(ruleAccessibilityRequirements));
console.log("-------");
console.log(testHTML);
console.log("\n");
throw error;
}
});
const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});
}
${assertion}
});
});
`;
await mkdir(`./tests/act/tests/${ruleId}/`, { recursive: true });
await writeFile(
`./tests/act/tests/${ruleId}/${testcaseId}.ts`,
suite,
"utf8",
);
}
15 changes: 15 additions & 0 deletions tests/act/tests/c487ae/014295a8bd7213fdbd69bc1c8ee44c48268370ec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Passed Example 8 (https://act-rules.github.io/testcases/c487ae/014295a8bd7213fdbd69bc1c8ee44c48268370ec.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI"><img src="/test-assets/shared/w3c-logo.png" aria-labelledby="id1"/></a>
<div id="id1">Web Accessibility Initiative (WAI)</div>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.be.empty;
});
});
16 changes: 16 additions & 0 deletions tests/act/tests/c487ae/03653844ceb8f6cd95af81672123ea98323ce5c8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Passed Example 5 (https://act-rules.github.io/testcases/c487ae/03653844ceb8f6cd95af81672123ea98323ce5c8.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI" title="Web Accessibility Initiative"
><img src="/test-assets/shared/w3c-logo.png" alt=""
/></a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.be.empty;
});
});
16 changes: 16 additions & 0 deletions tests/act/tests/c487ae/0d7a7862c5b414c272f1713c341d821f5249a15d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Passed Example 4 (https://act-rules.github.io/testcases/c487ae/0d7a7862c5b414c272f1713c341d821f5249a15d.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI"
><img src="/test-assets/shared/w3c-logo.png" aria-label="Web Accessibility Initiative"
/></a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.be.empty;
});
});
14 changes: 14 additions & 0 deletions tests/act/tests/c487ae/113298e42bd5a240371affac3747a470c617610b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Failed Example 1 (https://act-rules.github.io/testcases/c487ae/113298e42bd5a240371affac3747a470c617610b.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="http://www.w3.org/WAI"></a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.not.be.empty;
});
});
18 changes: 18 additions & 0 deletions tests/act/tests/c487ae/1752fb0c94ce17c6557a7e498c6e9a87c6a943ea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Passed Example 10 (https://act-rules.github.io/testcases/c487ae/1752fb0c94ce17c6557a7e498c6e9a87c6a943ea.html)", async () => {
await fixture(`<!DOCTYPE html> <img src="/test-assets/c487ae/planets.jpg" width="145" height="126" alt="Planets" usemap="#planetmap" />
<map name="planetmap">
<area shape="rect" coords="0,0,30,100" href="sun.htm" alt="Sun" />
</map>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.be.empty;
});
});
16 changes: 16 additions & 0 deletions tests/act/tests/c487ae/2917b821f0e317de992cad191ed67aeedb9f34c9.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Passed Example 7 (https://act-rules.github.io/testcases/c487ae/2917b821f0e317de992cad191ed67aeedb9f34c9.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI"
><img src="/test-assets/shared/w3c-logo.png" alt="" />Web Accessibility Initiative (WAI)</a
>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.be.empty;
});
});
14 changes: 14 additions & 0 deletions tests/act/tests/c487ae/2bdb0351ae2e82f05cfa15198ca0a353974f6278.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Failed Example 7 (https://act-rules.github.io/testcases/c487ae/2bdb0351ae2e82f05cfa15198ca0a353974f6278.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI"><img src="/test-assets/shared/w3c-logo.png" aria-labelledby="id1"/></a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.not.be.empty;
});
});
25 changes: 25 additions & 0 deletions tests/act/tests/c487ae/2c58ea9a68f5bf34cabb07059af1a533be96c720.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Passed Example 9 (https://act-rules.github.io/testcases/c487ae/2c58ea9a68f5bf34cabb07059af1a533be96c720.html)", async () => {
await fixture(`<!DOCTYPE html> <html>
<style>
.offScreenLink {
position: absolute;
left: -9999px;
top: -9999px;
}
</style>
<body>
<a class="offScreenLink" href="https://www.w3.org/WAI">Web Accessibility Initiative (WAI)</a>
</body>
</html>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.be.empty;
});
});
14 changes: 14 additions & 0 deletions tests/act/tests/c487ae/34c82462f976ebaaa5f68fc0f3f519832614e182.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Passed Example 1 (https://act-rules.github.io/testcases/c487ae/34c82462f976ebaaa5f68fc0f3f519832614e182.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI"> Web Accessibility Initiative (WAI) </a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.be.empty;
});
});
14 changes: 14 additions & 0 deletions tests/act/tests/c487ae/43516ed6280651bc0bb5c4fe83ba5312bca2b58b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Failed Example 2 (https://act-rules.github.io/testcases/c487ae/43516ed6280651bc0bb5c4fe83ba5312bca2b58b.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI"><img src="/test-assets/shared/w3c-logo.png" alt=""/></a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.not.be.empty;
});
});
14 changes: 14 additions & 0 deletions tests/act/tests/c487ae/51db96f8a86e965c58617540df61b15b8ba2aee3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Failed Example 5 (https://act-rules.github.io/testcases/c487ae/51db96f8a86e965c58617540df61b15b8ba2aee3.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI"><img src="/test-assets/shared/w3c-logo.png" title=""/></a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.not.be.empty;
});
});
14 changes: 14 additions & 0 deletions tests/act/tests/c487ae/679a7f5c037a7080108928ea74e3792cc9818490.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Failed Example 3 (https://act-rules.github.io/testcases/c487ae/679a7f5c037a7080108928ea74e3792cc9818490.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="http://www.w3.org/WAI"><img src="/test-assets/shared/w3c-logo.png" role="presentation"/></a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.not.be.empty;
});
});
18 changes: 18 additions & 0 deletions tests/act/tests/c487ae/7453d6a6491ddfe546eabb9f9cf1f01a96b9a805.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Failed Example 9 (https://act-rules.github.io/testcases/c487ae/7453d6a6491ddfe546eabb9f9cf1f01a96b9a805.html)", async () => {
await fixture(`<!DOCTYPE html> <img src="/test-assets/c487ae/planets.jpg" width="145" height="126" alt="Planets" usemap="#planetmap" />
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" />
</map>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.not.be.empty;
});
});
14 changes: 14 additions & 0 deletions tests/act/tests/c487ae/8130b961773da8671837e6a633ca879d1edd28d0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Failed Example 10 (https://act-rules.github.io/testcases/c487ae/8130b961773da8671837e6a633ca879d1edd28d0.html)", async () => {
await fixture(`<!DOCTYPE html> <a href="https://www.w3.org/WAI" role="none"> </a>`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.not.be.empty;
});
});
16 changes: 16 additions & 0 deletions tests/act/tests/c487ae/8b39de5e01179f2ca0b55e8aae65a18766530003.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";

describe("[c487ae]Link has non-empty accessible name", function () {
it("Failed Example 11 (https://act-rules.github.io/testcases/c487ae/8b39de5e01179f2ca0b55e8aae65a18766530003.html)", async () => {
await fixture(`<!DOCTYPE html> See [<a href="https://act-rules.github.io/" role="doc-biblioref"
><img src="https://github.com/act-rules/act-rules.github.io/blob/develop/test-assets/shared/act-logo.png" alt=""/></a
>]`);

const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});

expect(results).to.not.be.empty;
});
});
Loading

0 comments on commit 6b14944

Please sign in to comment.