-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,039 additions
and
9 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
"extends": "../../../config/api-extractor.json", | ||
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/package", | ||
"name": "@siteimprove/alfa-vitest", | ||
"homepage": "https://alfa.siteimprove.com", | ||
"version": "0.74.2", | ||
"license": "MIT", | ||
"description": "Assertion integrations for the Vitest testing framework", | ||
"repository": { | ||
"type": "git", | ||
"url": "github:Siteimprove/alfa-integrations", | ||
"directory": "packages/alfa-vitest" | ||
}, | ||
"bugs": "https://github.com/siteimprove/alfa/issues", | ||
"engines": { | ||
"node": ">=20.0.0" | ||
}, | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*.js", | ||
"dist/**/*.d.ts" | ||
], | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"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", | ||
"vitest": "^2.1.4" | ||
}, | ||
"peerDependencies": { | ||
"@siteimprove/alfa-act": "^0.93.8", | ||
"@siteimprove/alfa-future": "^0.93.8", | ||
"@siteimprove/alfa-hash": "^0.93.8", | ||
"@siteimprove/alfa-mapper": "^0.93.8" | ||
}, | ||
"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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./vitest.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/tsconfig", | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { "outDir": "../dist" }, | ||
"files": ["./index.ts", "./vitest.ts"], | ||
"references": [{ "path": "../../alfa-assert" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { Question, Rule } from "@siteimprove/alfa-act"; | ||
import type { Handler } from "@siteimprove/alfa-assert"; | ||
import { Asserter } from "@siteimprove/alfa-assert"; | ||
import type { Future } from "@siteimprove/alfa-future"; | ||
import type { Hashable } from "@siteimprove/alfa-hash"; | ||
import type { Mapper } from "@siteimprove/alfa-mapper"; | ||
|
||
import { expect } from "vitest"; | ||
|
||
interface CustomMatchers<R = unknown> { | ||
toBeAccessible: () => R; | ||
} | ||
|
||
declare module "vitest" { | ||
interface Assertion<T = any> extends CustomMatchers<T> {} | ||
interface AsymmetricMatchersContaining extends CustomMatchers {} | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export namespace Vitest { | ||
export function createPlugin< | ||
I, | ||
J, | ||
T extends Hashable, | ||
Q extends Question.Metadata = {}, | ||
S = T | ||
>( | ||
transform: Mapper<I, Future.Maybe<J>>, | ||
rules: Iterable<Rule<J, T, Q, S>>, | ||
handlers: Iterable<Handler<J, T, Q, S>> = [], | ||
options: Asserter.Options<J, T, Q, S> = {} | ||
): void { | ||
const asserter = Asserter.of(rules, handlers, options); | ||
|
||
expect.extend({ | ||
async toBeAccessible(value: I) { | ||
const input = await transform(value); | ||
|
||
const result = await asserter.expect(input).to.be.accessible(); | ||
|
||
const message = result.isOk() ? result.get() : result.getErrUnsafe(); | ||
|
||
return { | ||
pass: result.isOk(), | ||
message: () => | ||
this.utils.matcherHint("toBeAccessible", "received", "", { | ||
isNot: this.isNot, | ||
}) + | ||
" but " + | ||
message, | ||
}; | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": ["vitest"] | ||
}, | ||
"files": ["./vitest.spec.tsx"], | ||
"references": [{ "path": "../src" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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 { expect } from "vitest"; | ||
|
||
import { Vitest } from "../dist/vitest.js"; | ||
|
||
Vitest.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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/tsconfig", | ||
"extends": "../tsconfig.json", | ||
"references": [{ "path": "./src" }, { "path": "./test" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.