diff --git a/apps/web/src/__tests__/polyfill-dialog.ts b/apps/web/src/__tests__/polyfill-dialog.ts new file mode 100644 index 0000000..a472d56 --- /dev/null +++ b/apps/web/src/__tests__/polyfill-dialog.ts @@ -0,0 +1,16 @@ +/** + * jsdom doesn't implement HTMLDialogElement.showModal/close. + * Call this in beforeAll() for tests that render . + */ +export function polyfillDialog(): void { + if (typeof HTMLDialogElement.prototype.showModal !== "function") { + HTMLDialogElement.prototype.showModal = function showModal() { + this.setAttribute("open", ""); + }; + } + if (typeof HTMLDialogElement.prototype.close !== "function") { + HTMLDialogElement.prototype.close = function close() { + this.removeAttribute("open"); + }; + } +} diff --git a/apps/web/src/adapters/bestiary-cache.ts b/apps/web/src/adapters/bestiary-cache.ts index c8aa7f8..75b27ac 100644 --- a/apps/web/src/adapters/bestiary-cache.ts +++ b/apps/web/src/adapters/bestiary-cache.ts @@ -40,7 +40,7 @@ async function getDb(): Promise { } if (oldVersion < 2 && database.objectStoreNames.contains(STORE_NAME)) { // Clear cached creatures to pick up improved tag processing - transaction.objectStore(STORE_NAME).clear(); + void transaction.objectStore(STORE_NAME).clear(); } }, }); diff --git a/apps/web/src/components/__tests__/action-bar.test.tsx b/apps/web/src/components/__tests__/action-bar.test.tsx index ae9e1b5..61be700 100644 --- a/apps/web/src/components/__tests__/action-bar.test.tsx +++ b/apps/web/src/components/__tests__/action-bar.test.tsx @@ -4,6 +4,7 @@ import "@testing-library/jest-dom/vitest"; import { cleanup, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { afterEach, beforeAll, describe, expect, it, vi } from "vitest"; +import { polyfillDialog } from "../../__tests__/polyfill-dialog.js"; import { AllProviders } from "../../__tests__/test-providers.js"; import { ActionBar } from "../action-bar.js"; @@ -50,16 +51,7 @@ beforeAll(() => { dispatchEvent: vi.fn(), })), }); - HTMLDialogElement.prototype.showModal = - HTMLDialogElement.prototype.showModal || - function showModal(this: HTMLDialogElement) { - this.setAttribute("open", ""); - }; - HTMLDialogElement.prototype.close = - HTMLDialogElement.prototype.close || - function close(this: HTMLDialogElement) { - this.removeAttribute("open"); - }; + polyfillDialog(); }); afterEach(cleanup); diff --git a/apps/web/src/components/__tests__/create-player-modal.test.tsx b/apps/web/src/components/__tests__/create-player-modal.test.tsx index 58ff562..0ac1e29 100644 --- a/apps/web/src/components/__tests__/create-player-modal.test.tsx +++ b/apps/web/src/components/__tests__/create-player-modal.test.tsx @@ -4,19 +4,11 @@ import { playerCharacterId } from "@initiative/domain"; import { cleanup, render, screen } from "@testing-library/react"; import { userEvent } from "@testing-library/user-event"; import { afterEach, beforeAll, describe, expect, it, vi } from "vitest"; +import { polyfillDialog } from "../../__tests__/polyfill-dialog.js"; import { CreatePlayerModal } from "../create-player-modal.js"; beforeAll(() => { - HTMLDialogElement.prototype.showModal = - HTMLDialogElement.prototype.showModal || - function showModal(this: HTMLDialogElement) { - this.setAttribute("open", ""); - }; - HTMLDialogElement.prototype.close = - HTMLDialogElement.prototype.close || - function close(this: HTMLDialogElement) { - this.removeAttribute("open"); - }; + polyfillDialog(); }); afterEach(cleanup); diff --git a/apps/web/src/components/__tests__/dialog.test.tsx b/apps/web/src/components/__tests__/dialog.test.tsx index 9c483f4..719f791 100644 --- a/apps/web/src/components/__tests__/dialog.test.tsx +++ b/apps/web/src/components/__tests__/dialog.test.tsx @@ -2,19 +2,11 @@ import { cleanup, render, screen } from "@testing-library/react"; import { userEvent } from "@testing-library/user-event"; import { afterEach, beforeAll, describe, expect, it, vi } from "vitest"; +import { polyfillDialog } from "../../__tests__/polyfill-dialog.js"; import { Dialog, DialogHeader } from "../ui/dialog.js"; beforeAll(() => { - HTMLDialogElement.prototype.showModal = - HTMLDialogElement.prototype.showModal || - function showModal(this: HTMLDialogElement) { - this.setAttribute("open", ""); - }; - HTMLDialogElement.prototype.close = - HTMLDialogElement.prototype.close || - function close(this: HTMLDialogElement) { - this.removeAttribute("open"); - }; + polyfillDialog(); }); afterEach(cleanup); diff --git a/lefthook.yml b/lefthook.yml index 8fdaf90..438d7c9 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -24,6 +24,6 @@ pre-commit: - name: typecheck run: pnpm exec tsc --build - name: oxlint - run: pnpm oxlint + run: pnpm oxlint -- --deny warnings - name: test run: pnpm test diff --git a/package.json b/package.json index 8a3c7e9..cc224fe 100644 --- a/package.json +++ b/package.json @@ -31,10 +31,10 @@ "knip": "knip", "jscpd": "jscpd", "jsinspect": "jsinspect -c .jsinspectrc apps/web/src packages/domain/src packages/application/src", - "oxlint": "oxlint --tsconfig apps/web/tsconfig.json --type-aware", + "oxlint": "oxlint --tsconfig apps/web/tsconfig.json --type-aware --deny warnings", "check:ignores": "node scripts/check-lint-ignores.mjs", "check:classnames": "node scripts/check-cn-classnames.mjs", "check:props": "node scripts/check-component-props.mjs", - "check": "pnpm audit --audit-level=high && knip && biome check . && node scripts/check-lint-ignores.mjs && node scripts/check-cn-classnames.mjs && node scripts/check-component-props.mjs && jscpd && pnpm jsinspect && tsc --build && oxlint --tsconfig apps/web/tsconfig.json --type-aware && vitest run" + "check": "pnpm audit --audit-level=high && knip && biome check . && node scripts/check-lint-ignores.mjs && node scripts/check-cn-classnames.mjs && node scripts/check-component-props.mjs && jscpd && pnpm jsinspect && tsc --build && oxlint --tsconfig apps/web/tsconfig.json --type-aware --deny warnings && vitest run" } }