Skip to content

Commit 6002651

Browse files
authored
Feature/279/separate image matching (#298)
* (#279) Remove image matching provider code * (#279) Remove image matching providers from registry * (#279) Update vision adapter test * (#279) Remove opencv4nodejs-prebuilt dependency * (#279) Plugin e2e test * (#279) Init plugin e2e test * (#279) Align e2e package versions * (#279) Fix resource path * (#279) Add error info to output, formatting * (#279) Run plugin test in Docker environment * (#279) Export FileType enum * (#279) Move screen e2e test to plugin e2e test subpackage since it requires the template-matcher package as well * (#279) Move keyboard e2e test to plugin subpackage as well
1 parent a818d79 commit 6002651

40 files changed

Lines changed: 7262 additions & 1311 deletions

‎.build/build.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ echo "Installing node version $nodeVersion"
2323
nvm install $nodeVersion
2424

2525
npm ci
26+
npm --prefix e2e/plugin-test ci
2627
E2E_TEST=1 npm run coverage -- --coverageDirectory=coverage/e2e

‎e2e/electron-test/package-lock.json‎

Lines changed: 61 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎e2e/electron-test/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-test",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "A test to verify usage with Electron",
55
"main": "main.js",
66
"author": {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
screen,
1111
sleep,
1212
straightTo,
13-
} from "./index";
13+
} from "@nut-tree/nut-js";
14+
15+
import "@nut-tree/template-matcher";
1416

1517
jest.setTimeout(60000);
1618

lib/keyboard.class.e2e.spec.ts renamed to e2e/plugin-test/keyboard.class.e2e.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { jestMatchers, Key, keyboard, screen } from "../index";
1+
import { jestMatchers, Key, keyboard, screen } from "@nut-tree/nut-js";
2+
import "@nut-tree/template-matcher";
23

34
jest.setTimeout(30000);
45
expect.extend(jestMatchers);

‎e2e/plugin-test/package-lock.json‎

Lines changed: 6789 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎e2e/plugin-test/package.json‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "plugin-tests",
3+
"version": "1.7.0",
4+
"description": "Tests to verify plugins",
5+
"main": "main.js",
6+
"author": {
7+
"name": "Simon Hofmann",
8+
"email": "kontakt@s1h.org",
9+
"url": "https://s1h.org"
10+
},
11+
"license": "Apache-2.0",
12+
"devDependencies": {
13+
"@nut-tree/nut-js": "file:../../",
14+
"@nut-tree/template-matcher": "0.0.1",
15+
"node-abort-controller": "2.0.0"
16+
}
17+
}
Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import {existsSync} from "fs";
2-
import {VisionAdapter} from "./adapter/vision.adapter.class";
3-
import {FileType} from "./file-type.enum";
4-
import {ScreenClass} from "./screen.class";
5-
import {sleep} from "./sleep.function";
2+
import {screen, sleep, FileType, Region} from "@nut-tree/nut-js";
63
import AbortController from "node-abort-controller";
7-
import {Region} from "./region.class";
8-
import providerRegistry from "./provider/provider-registry.class";
4+
5+
import "@nut-tree/template-matcher";
96

107
jest.setTimeout(10000);
118

129
describe("Screen.", () => {
1310
it("should capture the screen", () => {
1411
// GIVEN
15-
const visionAdapter = new VisionAdapter(providerRegistry);
16-
const SUT = new ScreenClass(visionAdapter);
1712

1813
// WHEN
19-
SUT.capture("asdf", FileType.PNG).then(filename => {
14+
screen.capture("asdf", FileType.PNG).then(filename => {
2015
// THEN
2116
expect(filename).not.toBeNull();
2217
sleep(1000).then(() => {
@@ -27,11 +22,9 @@ describe("Screen.", () => {
2722

2823
it("should capture the screen and save to JPG", () => {
2924
// GIVEN
30-
const visionAdapter = new VisionAdapter(providerRegistry);
31-
const SUT = new ScreenClass(visionAdapter);
3225

3326
// WHEN
34-
SUT.capture("asdf", FileType.JPG).then(filename => {
27+
screen.capture("asdf", FileType.JPG).then(filename => {
3528
// THEN
3629
expect(filename).not.toBeNull();
3730
sleep(1000).then(() => {
@@ -42,12 +35,10 @@ describe("Screen.", () => {
4235

4336
it("should capture the screen and save file with prefix", () => {
4437
// GIVEN
45-
const visionAdapter = new VisionAdapter(providerRegistry);
46-
const SUT = new ScreenClass(visionAdapter);
4738
const prefix = "foo_";
4839

4940
// WHEN
50-
SUT.capture("asdf", FileType.JPG, "./", prefix).then(filename => {
41+
screen.capture("asdf", FileType.JPG, "./", prefix).then(filename => {
5142
// THEN
5243
expect(filename.includes(prefix)).toBeTruthy();
5344
expect(filename).not.toBeNull();
@@ -59,12 +50,10 @@ describe("Screen.", () => {
5950

6051
it("should capture the screen and save file with postfix", () => {
6152
// GIVEN
62-
const visionAdapter = new VisionAdapter(providerRegistry);
63-
const SUT = new ScreenClass(visionAdapter);
6453
const postfix = "_bar";
6554

6655
// WHEN
67-
SUT.capture("asdf", FileType.JPG, "./", "", postfix).then(filename => {
56+
screen.capture("asdf", FileType.JPG, "./", "", postfix).then(filename => {
6857
// THEN
6958
expect(filename.includes(postfix)).toBeTruthy();
7059
expect(filename).not.toBeNull();
@@ -76,14 +65,12 @@ describe("Screen.", () => {
7665

7766
it("should capture the screen and save file with pre- and postfix", () => {
7867
// GIVEN
79-
const visionAdapter = new VisionAdapter(providerRegistry);
80-
const SUT = new ScreenClass(visionAdapter);
8168
const filename = "asdf";
8269
const prefix = "foo_";
8370
const postfix = "_bar";
8471

8572
// WHEN
86-
SUT.capture("asdf", FileType.JPG, "./", prefix, postfix).then(output => {
73+
screen.capture("asdf", FileType.JPG, "./", prefix, postfix).then(output => {
8774
// THEN
8875
expect(output.includes(`${prefix}${filename}${postfix}`)).toBeTruthy();
8976
expect(output).not.toBeNull();
@@ -96,14 +83,12 @@ describe("Screen.", () => {
9683
it("should reject after timeout", async () => {
9784
// GIVEN
9885
const timeout = 5000;
99-
const visionAdapter = new VisionAdapter(providerRegistry);
100-
const SUT = new ScreenClass(visionAdapter);
101-
SUT.config.resourceDirectory = "./e2e/assets";
86+
screen.config.resourceDirectory = "./e2e/assets";
10287

10388
// WHEN
10489
const start = Date.now();
10590
try {
106-
await SUT.waitFor("calculator.png", timeout);
91+
await screen.waitFor("calculator.png", timeout);
10792
} catch (e) {
10893
// THEN
10994
expect(e).toBe(`Action timed out after ${timeout} ms`);
@@ -120,13 +105,11 @@ describe("Screen.", () => {
120105
const abortAfterMs = 1000;
121106
const controller = new AbortController();
122107
const signal = controller.signal;
123-
const visionAdapter = new VisionAdapter(providerRegistry);
124-
const SUT = new ScreenClass(visionAdapter);
125-
SUT.config.resourceDirectory = "./e2e/assets";
108+
screen.config.resourceDirectory = "./e2e/assets";
126109

127110
// WHEN
128111
const start = Date.now();
129-
SUT.waitFor("calculator.png", timeout, {abort: signal}).catch(e => {
112+
screen.waitFor("calculator.png", timeout, {abort: signal}).catch(e => {
130113
const end = Date.now();
131114

132115
// THEN
@@ -140,13 +123,11 @@ describe("Screen.", () => {
140123

141124
it("should grab the whole screen content and return an Image", async () => {
142125
// GIVEN
143-
const visionAdapter = new VisionAdapter(providerRegistry);
144-
const SUT = new ScreenClass(visionAdapter);
145-
const screenWidth = await SUT.width();
146-
const screenHeight = await SUT.height();
126+
const screenWidth = await screen.width();
127+
const screenHeight = await screen.height();
147128

148129
// WHEN
149-
const image = await SUT.grab();
130+
const image = await screen.grab();
150131

151132
// THEN
152133
expect(image.data).not.toBeUndefined();
@@ -156,12 +137,10 @@ describe("Screen.", () => {
156137

157138
it("should grab a screen region and return an Image", async () => {
158139
// GIVEN
159-
const visionAdapter = new VisionAdapter(providerRegistry);
160-
const SUT = new ScreenClass(visionAdapter);
161140
const regionToGrab = new Region(0, 0, 100, 100);
162141

163142
// WHEN
164-
const image = await SUT.grabRegion(regionToGrab);
143+
const image = await screen.grabRegion(regionToGrab);
165144

166145
// THEN
167146
expect(image.data).not.toBeUndefined();

0 commit comments

Comments
 (0)