@out-of-order/vitest 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9 -0
- package/package.json +5 -4
- package/src/index.ts +12 -0
package/dist/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { expect } from "vitest";
|
|
3
3
|
import { audit } from "@out-of-order/core";
|
|
4
|
+
function assertRealBrowser() {
|
|
5
|
+
const userAgent = typeof navigator === "undefined" ? "" : navigator.userAgent;
|
|
6
|
+
if (typeof window === "undefined" || userAgent.includes("jsdom")) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"toHaveValidTabOrder() needs a real browser and found jsdom. Enable Vitest Browser Mode (test.browser.enabled) for these tests. jsdom has no layout engine, so tab order and visibility cannot be measured."
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
4
12
|
function resolveRoot(received) {
|
|
5
13
|
if (received instanceof Element || received instanceof Document || received instanceof DocumentFragment) {
|
|
6
14
|
return received;
|
|
@@ -13,6 +21,7 @@ function resolveRoot(received) {
|
|
|
13
21
|
}
|
|
14
22
|
expect.extend({
|
|
15
23
|
toHaveValidTabOrder(received, options) {
|
|
24
|
+
assertRealBrowser();
|
|
16
25
|
const root = resolveRoot(received);
|
|
17
26
|
const result = audit(root, options);
|
|
18
27
|
const { isNot } = this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@out-of-order/vitest",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "toHaveValidTabOrder() matcher for Vitest Browser Mode.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"tab-order",
|
|
11
11
|
"vitest"
|
|
12
12
|
],
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"author": "Bart Spaans",
|
|
15
13
|
"homepage": "https://github.com/spaansba/out-of-order#readme",
|
|
16
14
|
"bugs": "https://github.com/spaansba/out-of-order/issues",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Bart Spaans",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "git+https://github.com/spaansba/out-of-order.git",
|
|
@@ -37,10 +37,11 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@out-of-order/core": "0.1.
|
|
40
|
+
"@out-of-order/core": "0.1.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@vitest/browser": "^2.1.0",
|
|
44
|
+
"jsdom": "^25.0.0",
|
|
44
45
|
"playwright": "^1.47.0",
|
|
45
46
|
"tsup": "^8.2.0",
|
|
46
47
|
"typescript": "^5.5.0",
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { expect } from "vitest";
|
|
2
2
|
import { audit, type AuditOptions, type AuditResult } from "@out-of-order/core";
|
|
3
3
|
|
|
4
|
+
function assertRealBrowser(): void {
|
|
5
|
+
const userAgent = typeof navigator === "undefined" ? "" : navigator.userAgent;
|
|
6
|
+
if (typeof window === "undefined" || userAgent.includes("jsdom")) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"toHaveValidTabOrder() needs a real browser and found jsdom. Enable Vitest " +
|
|
9
|
+
"Browser Mode (test.browser.enabled) for these tests. jsdom has no layout " +
|
|
10
|
+
"engine, so tab order and visibility cannot be measured.",
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
/** Accept an Element or a Document/DocumentFragment as the assertion target. */
|
|
5
16
|
function resolveRoot(received: unknown): ParentNode {
|
|
6
17
|
if (
|
|
@@ -19,6 +30,7 @@ function resolveRoot(received: unknown): ParentNode {
|
|
|
19
30
|
|
|
20
31
|
expect.extend({
|
|
21
32
|
toHaveValidTabOrder(received: unknown, options?: AuditOptions) {
|
|
33
|
+
assertRealBrowser();
|
|
22
34
|
const root = resolveRoot(received);
|
|
23
35
|
const result: AuditResult = audit(root, options);
|
|
24
36
|
const { isNot } = this;
|