@guidepup/guidepup
Advanced tools
Comparing version 0.9.3 to 0.10.0
@@ -7,1 +7,2 @@ export declare const DEFAULT_RETRY_COUNT = 3; | ||
export declare const ERR_WAITING_TIMEOUT = "Timed out waiting."; | ||
export declare const APPLE_SCRIPT_TIMED_OUT_ERR_SNIPPET = "AppleEvent timed out"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ERR_WAITING_TIMEOUT = exports.DEFAULT_MAX_BUFFER = exports.DEFAULT_TIMEOUT = exports.DEFAULT_POLL_INTERVAL = exports.DEFAULT_MUTATING_ACTION_RETRY_COUNT = exports.DEFAULT_RETRY_COUNT = void 0; | ||
exports.APPLE_SCRIPT_TIMED_OUT_ERR_SNIPPET = exports.ERR_WAITING_TIMEOUT = exports.DEFAULT_MAX_BUFFER = exports.DEFAULT_TIMEOUT = exports.DEFAULT_POLL_INTERVAL = exports.DEFAULT_MUTATING_ACTION_RETRY_COUNT = exports.DEFAULT_RETRY_COUNT = void 0; | ||
exports.DEFAULT_RETRY_COUNT = 3; | ||
@@ -10,1 +10,2 @@ exports.DEFAULT_MUTATING_ACTION_RETRY_COUNT = 1; | ||
exports.ERR_WAITING_TIMEOUT = "Timed out waiting."; | ||
exports.APPLE_SCRIPT_TIMED_OUT_ERR_SNIPPET = "AppleEvent timed out"; |
import type { CommandOptions } from "../CommandOptions"; | ||
import { Applications } from "./Applications"; | ||
export declare function activate(applicationName: Applications | string, options?: CommandOptions): Promise<void>; | ||
export declare function activate(applicationName: string, options?: CommandOptions): Promise<void>; |
import type { CommandOptions } from "../CommandOptions"; | ||
import { Applications } from "./Applications"; | ||
export declare function quit(applicationName: Applications, options?: CommandOptions): Promise<void>; | ||
export declare function quit(applicationName: string, options?: CommandOptions): Promise<void>; |
@@ -5,3 +5,2 @@ "use strict"; | ||
const constants_1 = require("../constants"); | ||
const APPLE_SCRIPT_TIMED_OUT_ERR_SNIPPET = "AppleEvent timed out"; | ||
async function retryIfAppleEventTimeout(delegate, { retries = constants_1.DEFAULT_MUTATING_ACTION_RETRY_COUNT } = { | ||
@@ -17,3 +16,3 @@ retries: constants_1.DEFAULT_MUTATING_ACTION_RETRY_COUNT, | ||
error = e; | ||
if (!e.message.includes(APPLE_SCRIPT_TIMED_OUT_ERR_SNIPPET)) { | ||
if (!e.message.includes(constants_1.APPLE_SCRIPT_TIMED_OUT_ERR_SNIPPET)) { | ||
break; | ||
@@ -20,0 +19,0 @@ } |
@@ -11,9 +11,6 @@ "use strict"; | ||
maxBuffer: constants_1.DEFAULT_MAX_BUFFER, | ||
}, (e, stdout, stderr) => { | ||
}, (e, stdout) => { | ||
if (e) { | ||
return reject(e); | ||
} | ||
if (stderr) { | ||
console.error(stderr); | ||
} | ||
if (!stdout) { | ||
@@ -20,0 +17,0 @@ return resolve(); |
@@ -1,5 +0,1 @@ | ||
import type { KeyCodeCommand } from "../KeyCodeCommand"; | ||
import type { KeystrokeCommand } from "../KeystrokeCommand"; | ||
import type { CommandOptions } from "../../CommandOptions"; | ||
import { Applications } from "../Applications"; | ||
export declare function sendKeys(applicationName: Applications | string, keyCommand: KeyCodeCommand | KeystrokeCommand, options?: CommandOptions): Promise<void>; | ||
export { sendKeys } from "./sendKeys"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sendKeys = void 0; | ||
const activate_1 = require("../activate"); | ||
const keyCode_1 = require("../keyCode"); | ||
const keystroke_1 = require("./keystroke"); | ||
const isKeyCode_1 = require("../../isKeyCode"); | ||
const errors_1 = require("../errors"); | ||
async function sendKeys(applicationName, keyCommand, options) { | ||
await (0, activate_1.activate)(applicationName); | ||
try { | ||
return (0, isKeyCode_1.isKeyCode)(keyCommand) | ||
? await (0, keyCode_1.keyCode)(keyCommand, options) | ||
: await (0, keystroke_1.keystroke)(keyCommand, options); | ||
} | ||
catch (e) { | ||
throw new Error(`${errors_1.ERR_PREFIX_SEND_KEYS}${applicationName}\n${e.message}`); | ||
} | ||
} | ||
exports.sendKeys = sendKeys; | ||
var sendKeys_1 = require("./sendKeys"); | ||
Object.defineProperty(exports, "sendKeys", { enumerable: true, get: function () { return sendKeys_1.sendKeys; } }); |
@@ -10,3 +10,3 @@ "use strict"; | ||
async function performCommand(command, options) { | ||
const performCommandScript = `tell commander to perform command "${command.toLowerCase()}"`; | ||
const performCommandScript = `tell commander to perform command "${command}"`; | ||
const script = `tell application "${Applications_1.Applications.VOICE_OVER}"\n${(0, withTransaction_1.withTransaction)(performCommandScript)}\nend tell`; | ||
@@ -13,0 +13,0 @@ try { |
@@ -22,3 +22,3 @@ import type { KeyCodeCommand } from "../KeyCodeCommand"; | ||
* | ||
* @returns {boolean} | ||
* @returns {Promise<boolean>} | ||
*/ | ||
@@ -147,7 +147,5 @@ static default(): Promise<boolean>; | ||
* | ||
* Note `vo.startLog()` must first be called for spoken phrases to be logged. | ||
* | ||
* @returns {Promise<string[]>} The phrase log. | ||
* @returns {string[]} The phrase log. | ||
*/ | ||
getSpokenPhraseLog(): Promise<string[]>; | ||
getSpokenPhraseLog(): string[]; | ||
/** | ||
@@ -164,15 +162,5 @@ * Get the text of the item in the VoiceOver cursor. | ||
* | ||
* Note `vo.startLog()` must first be called for item text to be logged. | ||
* | ||
* @returns {Promise<string[]>} The item text log. | ||
* @returns {string[]} The item text log. | ||
*/ | ||
getItemTextLog(): Promise<string[]>; | ||
/** | ||
* Start logging spoken phrases and item text. | ||
*/ | ||
startLog(): void; | ||
/** | ||
* Stop logging spoken phrases and item text. | ||
*/ | ||
stopLog(): void; | ||
getItemTextLog(): string[]; | ||
} |
@@ -37,3 +37,2 @@ "use strict"; | ||
let VoiceOverBase = VoiceOverBase_1 = class VoiceOverBase { | ||
#log = false; | ||
#spokenPhraseLog = []; | ||
@@ -43,6 +42,4 @@ #itemTextLog = []; | ||
const result = await promise; | ||
if (this.#log) { | ||
this.#spokenPhraseLog.push(await this.getLastSpokenPhrase()); | ||
this.#itemTextLog.push(await this.getItemText()); | ||
} | ||
this.#spokenPhraseLog.push(await this.getLastSpokenPhrase()); | ||
this.#itemTextLog.push(await this.getItemText()); | ||
return result; | ||
@@ -56,3 +53,3 @@ } | ||
static async detect() { | ||
return (await (0, isMacOS_1.isMacOS)()) && (await (0, supportsAppleScriptControl_1.supportsAppleScriptControl)()); | ||
return (0, isMacOS_1.isMacOS)() && (await (0, supportsAppleScriptControl_1.supportsAppleScriptControl)()); | ||
} | ||
@@ -62,6 +59,6 @@ /** | ||
* | ||
* @returns {boolean} | ||
* @returns {Promise<boolean>} | ||
*/ | ||
static async default() { | ||
return await (0, isMacOS_1.isMacOS)(); | ||
static default() { | ||
return Promise.resolve((0, isMacOS_1.isMacOS)()); | ||
} | ||
@@ -230,7 +227,5 @@ /** | ||
* | ||
* Note `vo.startLog()` must first be called for spoken phrases to be logged. | ||
* | ||
* @returns {Promise<string[]>} The phrase log. | ||
* @returns {string[]} The phrase log. | ||
*/ | ||
async getSpokenPhraseLog() { | ||
getSpokenPhraseLog() { | ||
return this.#spokenPhraseLog; | ||
@@ -251,21 +246,7 @@ } | ||
* | ||
* Note `vo.startLog()` must first be called for item text to be logged. | ||
* | ||
* @returns {Promise<string[]>} The item text log. | ||
* @returns {string[]} The item text log. | ||
*/ | ||
async getItemTextLog() { | ||
getItemTextLog() { | ||
return this.#itemTextLog; | ||
} | ||
/** | ||
* Start logging spoken phrases and item text. | ||
*/ | ||
startLog() { | ||
this.#log = true; | ||
} | ||
/** | ||
* Stop logging spoken phrases and item text. | ||
*/ | ||
stopLog() { | ||
this.#log = false; | ||
} | ||
}; | ||
@@ -272,0 +253,0 @@ VoiceOverBase = VoiceOverBase_1 = __decorate([ |
@@ -39,7 +39,5 @@ import type { KeyCodeCommand } from "./KeyCodeCommand"; | ||
* | ||
* Note `vo.startLog()` must first be called for spoken phrases to be logged. | ||
* | ||
* @returns {Promise<string[]>} The phrase log. | ||
* @returns {string[]} The phrase log. | ||
*/ | ||
getSpokenPhraseLog(): Promise<string[]>; | ||
getSpokenPhraseLog(): string[]; | ||
/** | ||
@@ -54,15 +52,5 @@ * Get the text of the item in the ScreenReader cursor. | ||
* | ||
* Note `vo.startLog()` must first be called for item text to be logged. | ||
* | ||
* @returns {Promise<string[]>} The item text log. | ||
* @returns {string[]} The item text log. | ||
*/ | ||
getItemTextLog(): Promise<string[]>; | ||
/** | ||
* Start logging spoken phrases and item text. | ||
*/ | ||
startLog(): void; | ||
/** | ||
* Stop logging spoken phrases and item text. | ||
*/ | ||
stopLog(): void; | ||
getItemTextLog(): string[]; | ||
} | ||
@@ -69,0 +57,0 @@ export interface ScreenReader { |
@@ -5,2 +5,16 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
async function resolveWhenTrue(condition, pollInterval, signal) { | ||
let result; | ||
try { | ||
result = await condition(); | ||
} | ||
catch (_) { | ||
result = false; | ||
} | ||
if (result || signal.aborted) { | ||
return; | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, pollInterval)); | ||
resolveWhenTrue(condition, pollInterval, signal); | ||
} | ||
async function waitForCondition(condition, { pollInterval = constants_1.DEFAULT_POLL_INTERVAL, pollTimeout = constants_1.DEFAULT_TIMEOUT, timeoutErrorMessage = constants_1.ERR_WAITING_TIMEOUT, } = { | ||
@@ -11,28 +25,9 @@ pollInterval: constants_1.DEFAULT_POLL_INTERVAL, | ||
}) { | ||
let pollIntervalId; | ||
let pollTimeoutId; | ||
let timeoutTimerId; | ||
const controller = new AbortController(); | ||
await Promise.race([ | ||
new Promise((resolve) => { | ||
pollIntervalId = setInterval(async () => { | ||
let result; | ||
try { | ||
result = await condition(); | ||
} | ||
catch (_) { | ||
result = false; | ||
} | ||
if (result) { | ||
clearTimeout(pollTimeoutId); | ||
clearInterval(pollIntervalId); | ||
pollTimeoutId = undefined; | ||
pollIntervalId = undefined; | ||
resolve(); | ||
} | ||
}, pollInterval); | ||
}), | ||
resolveWhenTrue(condition, pollInterval, controller.signal), | ||
new Promise((_, reject) => { | ||
pollTimeoutId = setTimeout(() => { | ||
clearInterval(pollIntervalId); | ||
pollTimeoutId = undefined; | ||
pollIntervalId = undefined; | ||
timeoutTimerId = setTimeout(() => { | ||
controller.abort(); | ||
reject(new Error(timeoutErrorMessage)); | ||
@@ -42,3 +37,5 @@ }, pollTimeout); | ||
]); | ||
clearTimeout(timeoutTimerId); | ||
timeoutTimerId = undefined; | ||
} | ||
exports.waitForCondition = waitForCondition; |
@@ -55,7 +55,5 @@ import { KeyCodeCommand } from "../KeyCodeCommand"; | ||
* | ||
* Note `vo.startLog()` must first be called for spoken phrases to be logged. | ||
* | ||
* @returns {Promise<string[]>} The phrase log. | ||
* @returns {string[]} The phrase log. | ||
*/ | ||
getSpokenPhraseLog(): Promise<string[]>; | ||
getSpokenPhraseLog(): string[]; | ||
/** | ||
@@ -70,15 +68,5 @@ * Get the text of the item in the NVDA cursor. | ||
* | ||
* Note `vo.startLog()` must first be called for item text to be logged. | ||
* | ||
* @returns {Promise<string[]>} The item text log. | ||
* @returns {string[]} The item text log. | ||
*/ | ||
getItemTextLog(): Promise<string[]>; | ||
/** | ||
* Start logging spoken phrases and item text. | ||
*/ | ||
startLog(): void; | ||
/** | ||
* Stop logging spoken phrases and item text. | ||
*/ | ||
stopLog(): void; | ||
getItemTextLog(): string[]; | ||
} |
@@ -24,3 +24,2 @@ "use strict"; | ||
let NVDA = NVDA_1 = class NVDA { | ||
#log = false; | ||
#spokenPhraseLog = []; | ||
@@ -30,5 +29,3 @@ #itemTextLog = []; | ||
const result = await promise; | ||
if (this.#log) { | ||
// TODO: store last logs | ||
} | ||
// TODO: store last logs | ||
return result; | ||
@@ -105,7 +102,5 @@ } | ||
* | ||
* Note `vo.startLog()` must first be called for spoken phrases to be logged. | ||
* | ||
* @returns {Promise<string[]>} The phrase log. | ||
* @returns {string[]} The phrase log. | ||
*/ | ||
async getSpokenPhraseLog() { | ||
getSpokenPhraseLog() { | ||
return this.#spokenPhraseLog; | ||
@@ -125,21 +120,7 @@ } | ||
* | ||
* Note `vo.startLog()` must first be called for item text to be logged. | ||
* | ||
* @returns {Promise<string[]>} The item text log. | ||
* @returns {string[]} The item text log. | ||
*/ | ||
async getItemTextLog() { | ||
getItemTextLog() { | ||
return this.#itemTextLog; | ||
} | ||
/** | ||
* Start logging spoken phrases and item text. | ||
*/ | ||
startLog() { | ||
this.#log = true; | ||
} | ||
/** | ||
* Stop logging spoken phrases and item text. | ||
*/ | ||
stopLog() { | ||
this.#log = false; | ||
} | ||
}; | ||
@@ -146,0 +127,0 @@ NVDA = NVDA_1 = __decorate([ |
{ | ||
"name": "@guidepup/guidepup", | ||
"version": "0.9.3", | ||
"version": "0.10.0", | ||
"description": "Screen-reader driver for automation.", | ||
@@ -25,3 +25,3 @@ "main": "lib/index.js", | ||
"build": "yarn clean && yarn gen && yarn compile && yarn docs", | ||
"ci": "yarn clean && yarn lint && yarn build", | ||
"ci": "yarn clean && yarn lint && yarn test:coverage && yarn build", | ||
"clean": "rimraf lib docs", | ||
@@ -35,5 +35,8 @@ "compile": "tsc", | ||
"lint:fix": "yarn lint --fix", | ||
"test": "jest", | ||
"test:coverage": "yarn test --coverage", | ||
"prepublish": "yarn build" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^16.11.11", | ||
@@ -44,3 +47,5 @@ "@typescript-eslint/eslint-plugin": "^5.5.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"jest": "^27.4.7", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^27.1.3", | ||
"ts-node": "^10.4.0", | ||
@@ -47,0 +52,0 @@ "typedoc": "^0.22.10", |
@@ -91,2 +91,4 @@ <h1 align="center">Guidepup</h1> | ||
- [`web-test-runner-voiceover`](https://github.com/coryrylan/web-test-runner-voiceover) | ||
- [`nvda-testing-driver`](https://github.com/kastwey/nvda-testing-driver) | ||
- [`assistive-webdriver`](https://github.com/AmadeusITGroup/Assistive-Webdriver) | ||
@@ -93,0 +95,0 @@ ## License |
Sorry, the diff of this file is not supported yet
534871
150
97
12
12058