Skip to content

Commit

Permalink
Update Jest and enable Renovate (#102)
Browse files Browse the repository at this point in the history
* Make framework exception more generic
* Add basic Jest test
* Update Jest
* Enable Jest updates

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Jym77 and github-actions[bot] authored Oct 29, 2024
1 parent 1ab81f9 commit bce02db
Show file tree
Hide file tree
Showing 11 changed files with 587 additions and 600 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- run: yarn dedupe --check
- run: yarn build --quiet
- run: yarn test
- run: yarn test:cypress
- run: yarn test:other
- run: yarn validate-structure
- run: yarn extract --quiet
- run: yarn knip
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build": "node --max-old-space-size=8192 scripts/build.mjs --pretty",
"clean": "node scripts/clean.mjs --pretty",
"test": "node scripts/test.mjs --pretty",
"test:cypress": "yarn workspace @siteimprove/alfa-cypress run test",
"test:other": "yarn workspaces foreach --all --exclude @siteimprove/alfa-integrations run test",
"watch": "node scripts/watch.mjs --pretty",
"extract": "node scripts/api-extractor.mjs --pretty",
"document": "api-documenter generate -i docs/data/api -o docs/api",
Expand Down
19 changes: 17 additions & 2 deletions packages/alfa-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@
"dist/**/*.js",
"dist/**/*.d.ts"
],
"scripts": {
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
},
"jest": {
"moduleFileExtensions": [
"js"
]
},
"dependencies": {
"@siteimprove/alfa-act": "^0.93.8",
"@siteimprove/alfa-assert": "workspace:^",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-hash": "^0.93.8",
"@siteimprove/alfa-mapper": "^0.93.8",
"@types/jest": "^26.0.10",
"jest": "^29.0.1"
"@types/jest": "^29.5.14",
"jest": "^29.7.0"
},
"peerDependencies": {
"@siteimprove/alfa-act": "^0.93.8",
Expand All @@ -39,5 +47,12 @@
"publishConfig": {
"access": "public",
"registry": "https://npm.pkg.github.com/"
},
"devDependencies": {
"@siteimprove/alfa-device": "^0.93.8",
"@siteimprove/alfa-dom": "^0.93.8",
"@siteimprove/alfa-http": "^0.93.8",
"@siteimprove/alfa-rules": "^0.93.8",
"@siteimprove/alfa-web": "^0.93.8"
}
}
4 changes: 3 additions & 1 deletion packages/alfa-jest/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../tsconfig.json",
"compilerOptions": { "outDir": "../dist" },
"compilerOptions": {
"outDir": "../dist"
},
"files": ["./index.ts", "./jest.ts"],
"references": [{ "path": "../../alfa-assert" }]
}
35 changes: 35 additions & 0 deletions packages/alfa-jest/test/jest.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Device } from "@siteimprove/alfa-device";
import { h } from "@siteimprove/alfa-dom";
import { Request, Response } from "@siteimprove/alfa-http";
import { Rules } from "@siteimprove/alfa-rules";
import { Page } from "@siteimprove/alfa-web";

import { Jest } from "../dist/jest.js";

Jest.createPlugin((page: Page) => page, [Rules.get("R12").getUnsafe()]);

describe(".createPlugin adds a .toBeAccessible method", () => {
const page = Page.of(
Request.empty(),
Response.empty(),
h.document([<button>Hello World</button>]),
Device.standard()
);

it("should have a .toBeAccessible method", async () => {
await expect(page).toBeAccessible();
});
});

describe(".createPlugin adds a .not.toBeAccessible method", () => {
const page = Page.of(
Request.empty(),
Response.empty(),
h.document([<button></button>]),
Device.standard()
);

it("should have a .not.toBeAccessible method", async () => {
await expect(page).not.toBeAccessible();
});
});
12 changes: 12 additions & 0 deletions packages/alfa-jest/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": ".",
"jsx": "react-jsx",
"jsxImportSource": "@siteimprove/alfa-dom",
"types": ["jest"]
},
"files": ["./jest.spec.tsx"],
"references": [{ "path": "../src" }]
}
2 changes: 1 addition & 1 deletion packages/alfa-jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../tsconfig.json",
"references": [{ "path": "./src" }]
"references": [{ "path": "./src" }, { "path": "./test" }]
}
1 change: 1 addition & 0 deletions packages/alfa-scraper/src/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const { ceil } = Math;
export class Scraper {
public static async of(
browser: Promise<puppeteer.Browser> = puppeteer.launch({
headless: true,
args: [
"--no-sandbox",

Expand Down
3 changes: 2 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@siteimprove/alfa-cheerio: [cheerio, domhandler]",
"@siteimprove/alfa-enzyme: [enzyme]",
"@siteimprove/alfa-jasmine: [jasmine]",
"@siteimprove/alfa-jest: [jest]",
"@siteimprove/alfa-jquery: [jquery]",
"@siteimprove/alfa-react: [react, react-test-renderer]",
"@siteimprove/alfa-unexpected: [unexpected]",
Expand All @@ -22,10 +21,12 @@
"matchPackagePatterns": ["*"],
"excludePackagePrefixes": [
"@siteimprove/alfa",
"@types/jest",
"@types/selenium-webdriver",
"axios",
"chalk",
"cypress",
"jest",
"jsonld",
"playwright",
"puppeteer",
Expand Down
16 changes: 11 additions & 5 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ function test(root = "packages") {
system.readDirectory(root, [".spec.ts", ".spec.tsx"], ["node_modules"]),
os.cpus().length,
(fileName, done) => {
// These tests run with their own test framework and must therefore **not**
// be run through this script!
const testFrameworks = ["cypress", "jest"];

if (fileName.includes("cypress.spec.ts")) {
if (testFrameworks.some((framework) => fileName.includes(framework))) {
// Cypress is a special kid including its own test framework, so we
// cannot easily rely on alfa-test and skip it here. It needs to be
// tested separately
system.write("Skipping Cypress test, use `yarn test:cypress` instead");
return
system.write(
`Skipping tests having their own framework (${fileName}), use \`yarn test:other\` instead`
);

return;
}

if (!first) {
Expand All @@ -47,13 +53,13 @@ function test(root = "packages") {
stdio: "inherit",
}).then(
() => done(),
(err) => done(err),
(err) => done(err)
);
},
(err) => {
if (err) {
system.exit(1);
}
},
}
);
}
Loading

0 comments on commit bce02db

Please sign in to comment.