Skip to content

Commit

Permalink
chore: remove dependency on @guidepup/guidepup package
Browse files Browse the repository at this point in the history
  • Loading branch information
jlp-craigmorten committed Sep 14, 2024
1 parent a5e56a5 commit 63539e5
Show file tree
Hide file tree
Showing 6 changed files with 663 additions and 859 deletions.
21 changes: 8 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@guidepup/virtual-screen-reader",
"version": "0.27.1",
"version": "0.28.0",
"description": "Virtual Screen Reader driver for unit test automation.",
"author": "Craig Morten <craig.morten@hotmail.co.uk>",
"license": "MIT",
Expand Down Expand Up @@ -32,10 +32,6 @@
"require": {
"types": "./lib/cjs/index.d.ts",
"default": "./lib/cjs/index.cjs"
},
"default": {
"types": "./lib/cjs/index.d.ts",
"default": "./lib/cjs/index.cjs"
}
},
"./browser.js": {
Expand Down Expand Up @@ -64,21 +60,20 @@
"wpt:update": "yarn wpt:init --remote && cd test/wpt && python wpt.py manifest --path ../wpt-jsdom/wpt-manifest.json"
},
"dependencies": {
"@guidepup/guidepup": "^0.22.3",
"@testing-library/dom": "^10.4.0",
"@testing-library/user-event": "^14.5.2",
"aria-query": "^5.3.0",
"dom-accessibility-api": "^0.6.3"
"dom-accessibility-api": "^0.7.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
"@arethetypeswrong/cli": "^0.16.2",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.0.0",
"@types/expect": "^24.3.0",
"@types/jest": "^29.5.12",
"@types/json-schema": "^7.0.15",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.12",
"@types/node": "^22.5.5",
"@types/prop-types": "^15.7.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
Expand All @@ -92,19 +87,19 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"js-yaml": "^4.1.0",
"jsdom": "^24.1.1",
"minimatch": "^9.0.5",
"jsdom": "^25.0.0",
"minimatch": "^10.0.1",
"mocha": "^10.7.0",
"mocha-sugar-free": "^1.4.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rimraf": "^5.0.7",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.3",
"ts-jest-resolver": "^2.0.1",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.2",
"tsup": "^8.2.2",
"typescript": "^5.5.4",
"typescript-eslint": "^7.17.0"
"typescript-eslint": "^8.5.0"
}
}
20 changes: 9 additions & 11 deletions src/Virtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
AccessibilityNode,
createAccessibilityTree,
} from "./createAccessibilityTree";
import type { CommandOptions, ScreenReader } from "@guidepup/guidepup";
import { commands, type VirtualCommands } from "./commands/index";
import {
ERR_VIRTUAL_MISSING_CONTAINER,
Expand Down Expand Up @@ -74,7 +73,7 @@ export interface Root {
MutationObserver?: typeof MutationObserver;
}

export interface StartOptions extends CommandOptions {
export interface StartOptions {
/**
* The bounding HTML element to use the Virtual Screen Reader in.
*
Expand Down Expand Up @@ -200,7 +199,7 @@ const defaultUserEventOptions = {
* });
* ```
*/
export class Virtual implements ScreenReader {
export class Virtual {
#activeNode: AccessibilityNode | null = null;
#container: Node | null = null;
#cursor: HTMLDivElement | null = null;
Expand Down Expand Up @@ -328,15 +327,14 @@ export class Virtual implements ScreenReader {
// We've covered the tree having no length so there must be at least one
// index or we default back to the beginning of the tree.
const newActiveNode =

tree.find(({ node }) => node === target) ?? tree.at(0)!;

this.#updateState(newActiveNode, true);
}

#focusActiveElement() {
// Is only called following a null guard for `this.#activeNode`.

const target = getElementNode(this.#activeNode!);
target?.focus();
}
Expand Down Expand Up @@ -426,7 +424,7 @@ export class Virtual implements ScreenReader {
// This only fires after keyboard like interactions, both of which null
// guard the `this.#activeNode` so it stands that we should still be able
// to find it in the tree.

const newActiveNode = tree.at(currentIndex)!;

this.#updateState(newActiveNode, ignoreIfNoChange);
Expand Down Expand Up @@ -700,7 +698,7 @@ export class Virtual implements ScreenReader {
const nextIndex = currentIndex === -1 ? 0 : currentIndex - 1;
// We've covered the tree having no length so there must be at least one
// index, and we ensure to zero-guard with the logic above.

const newActiveNode = tree.at(nextIndex)!;

this.#updateState(newActiveNode);
Expand Down Expand Up @@ -745,7 +743,7 @@ export class Virtual implements ScreenReader {
: currentIndex + 1;
// We've covered the tree having no length so there must be at least one
// index, and we ensure to zero-guard with the logic above.

const newActiveNode = tree.at(nextIndex)!;

this.#updateState(newActiveNode);
Expand Down Expand Up @@ -966,7 +964,7 @@ export class Virtual implements ScreenReader {
async perform<
T extends keyof VirtualCommands,
K extends Omit<Parameters<VirtualCommands[T]>[0], keyof VirtualCommandArgs>
>(command: T, options?: { [L in keyof K]: K[L] } & CommandOptions) {
>(command: T, options?: { [L in keyof K]: K[L] }) {
this.#checkContainer();
await tick();

Expand All @@ -980,7 +978,7 @@ export class Virtual implements ScreenReader {
const nextIndex = commands[command]?.({
...options,
// `this.#checkContainer();` above null guards us here.

container: this.#container!,
currentIndex,
tree,
Expand All @@ -992,7 +990,7 @@ export class Virtual implements ScreenReader {

// We know the tree has length, and we guard against the command not being
// able to find an index in the tree so we are fine.

const newActiveNode = tree.at(nextIndex)!;
this.#updateState(newActiveNode);

Expand Down
2 changes: 1 addition & 1 deletion test/int/ariaLive.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */

const { default: userEvent } = require("@testing-library/user-event");

Expand Down
4 changes: 1 addition & 3 deletions test/int/ariaModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/**
* @namespace aria
*/
Expand Down Expand Up @@ -203,7 +201,7 @@ aria.Utils = aria.Utils || {};
aria.Utils.IgnoreUtilFocusChanges = true;
try {
element.focus();
} catch (e) {
} catch {
// continue regardless of error
}
aria.Utils.IgnoreUtilFocusChanges = false;
Expand Down
3 changes: 2 additions & 1 deletion test/int/noMutationObserver.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
(window.MutationObserver as unknown) = undefined;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { virtual } = require("../../src");

describe("No Mutation Observer", () => {
Expand Down
Loading

0 comments on commit 63539e5

Please sign in to comment.