Skip to content

Commit 0eb483e

Browse files
authored
Replace nutjs with @hurdlegroup/robotjs and clipboardy (#293)
1 parent 81c51f4 commit 0eb483e

5 files changed

+463
-2258
lines changed

e2e/keyboardClicking.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Key, keyboard } from "@nut-tree/nut-js";
1+
import { keyTap } from "@hurdlegroup/robotjs";
22
import { Frame, Page } from "puppeteer";
33
import { rangoCommandWithoutTarget } from "./utils/rangoCommands";
44
import { sleep } from "./utils/testHelpers";
@@ -11,7 +11,7 @@ async function testKeyboardClickingHighlighting(page: Page | Frame) {
1111
return Number.parseInt(window.getComputedStyle(inner).borderWidth, 10);
1212
});
1313

14-
await keyboard.type(Key.A);
14+
keyTap("a");
1515
await sleep(100);
1616

1717
const [borderWidthAfter, borderColorAfter] = await page.$eval(
@@ -26,7 +26,7 @@ async function testKeyboardClickingHighlighting(page: Page | Frame) {
2626
expect(borderWidthAfter).toBe(borderWidthBefore + 1);
2727
expect(borderColorAfter).toMatch(/^rgba\(.+0\.7\)$/);
2828

29-
await keyboard.type(Key.A);
29+
keyTap("a");
3030
await sleep(100);
3131

3232
const [borderWidthAfterCompletion, borderColorAfterCompletion] =
@@ -82,8 +82,8 @@ describe("With hints in main frame", () => {
8282
});
8383

8484
test("Typing the hint characters clicks the link", async () => {
85-
await keyboard.type(Key.A);
86-
await keyboard.type(Key.A);
85+
keyTap("a");
86+
keyTap("a");
8787

8888
await page.waitForNavigation();
8989

@@ -121,8 +121,8 @@ describe("With hints in other frames", () => {
121121
const contentFrame = (await frame!.contentFrame())!;
122122
await contentFrame.waitForSelector(".rango-hint");
123123

124-
await keyboard.type(Key.A);
125-
await keyboard.type(Key.A);
124+
keyTap("a");
125+
keyTap("a");
126126

127127
await contentFrame.waitForNavigation();
128128

e2e/noContentScript.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { clipboard } from "@nut-tree/nut-js";
1+
import clipboard from "clipboardy";
22
import { ResponseToTalon } from "../src/typings/RequestFromTalon";
33
import {
44
rangoCommandWithTarget,
@@ -14,7 +14,7 @@ describe("Direct clicking", () => {
1414
test("If no content script is loaded in the current page it sends the command to talon to type the characters", async () => {
1515
await rangoCommandWithTarget("directClickElement", ["a"]);
1616
await sleep(300);
17-
const clip = await clipboard.getContent();
17+
const clip = clipboard.readSync();
1818
const response = JSON.parse(clip) as ResponseToTalon;
1919
const found = response.actions.find(
2020
(action) => action.name === "typeTargetCharacters"
@@ -27,7 +27,7 @@ describe("Direct clicking", () => {
2727
describe("Background commands", () => {
2828
test("Commands that don't need the content script are still able to run", async () => {
2929
await rangoCommandWithoutTarget("copyLocationProperty", "href");
30-
const clip = await clipboard.getContent();
30+
const clip = clipboard.readSync();
3131
const response = JSON.parse(clip) as ResponseToTalon;
3232
const action = response.actions[0]!;
3333

e2e/utils/rangoCommands.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/* eslint-disable no-await-in-loop */
2-
import { keyboard, Key, clipboard, sleep } from "@nut-tree/nut-js";
2+
import { keyTap } from "@hurdlegroup/robotjs";
3+
import clipboard from "clipboardy";
4+
import { sleep } from "./testHelpers";
35

46
async function waitForCompletion() {
57
let message: any;
68

79
while (!message || message.type !== "response") {
8-
const clip = await clipboard.getContent();
10+
const clip = clipboard.readSync();
911

1012
try {
1113
message = JSON.parse(clip) as unknown;
@@ -32,8 +34,8 @@ export async function rangoCommandWithTarget(
3234

3335
const commandString = JSON.stringify(command);
3436

35-
await clipboard.setContent(commandString);
36-
await keyboard.type(Key.LeftControl, Key.LeftShift, Key.Num3);
37+
clipboard.writeSync(commandString);
38+
keyTap("3", ["control", "shift"]);
3739
await waitForCompletion();
3840
}
3941

@@ -52,7 +54,7 @@ export async function rangoCommandWithoutTarget(
5254

5355
const commandString = JSON.stringify(command);
5456

55-
await clipboard.setContent(commandString);
56-
await keyboard.type(Key.LeftControl, Key.LeftShift, Key.Num3);
57+
clipboard.writeSync(commandString);
58+
keyTap("3", ["control", "shift"]);
5759
await waitForCompletion();
5860
}

0 commit comments

Comments
 (0)