Skip to content

Commit 778cd7f

Browse files
authored
Bugfix/(nut tree/plugin ocr#25)/default confidence (#541)
* (nut-tree/plugin-ocr#25) Made the confidence value of a match request optional * (nut-tree/plugin-ocr#25) Stop setting a default confidence value to not override other confidence value (e.g. the OCR one) with the explicit value of the match request * (nut-tree/plugin-ocr#25) Removed redefinition of sleep and used import * (nut-tree/plugin-ocr#25) Updated workflow definitions * (nut-tree/plugin-ocr#25) Run npx playwright install before running tests * (nut-tree/plugin-ocr#25) Specify working directory where to load the Electron main from in window tests * (nut-tree/plugin-ocr#25) Increased Jest timeout for window tests to accommodate startup times, removed superfluous Docker stuf from CI runs on macOS and Windows, since tests would be running in Linux again which is just confusing in this place
1 parent dd5c382 commit 778cd7f

File tree

7 files changed

+207
-208
lines changed

7 files changed

+207
-208
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ on:
77
# paths-ignore:
88
# - '**/*.md'
99
pull_request:
10+
workflow_dispatch:
1011

1112
jobs:
1213
sonar:
1314
runs-on: ubuntu-latest
1415
if: "!contains(github.event.head_commit.message, 'skip ci')"
1516
steps:
1617
- name: Set up Git repository
17-
uses: actions/checkout@v2
18+
uses: actions/checkout@v3
1819
- name: Set up node
19-
uses: actions/setup-node@v2
20+
uses: actions/setup-node@v3
2021
with:
21-
node-version: 16
22+
node-version: 18
2223
- name: Setup Docker
2324
run: |
2425
docker pull s1hofmann/nut-ci:latest
@@ -57,20 +58,15 @@ jobs:
5758
strategy:
5859
matrix:
5960
os: [windows-latest, macos-latest]
60-
node: [16]
61+
node: [18]
6162
runs-on: ${{matrix.os}}
6263
steps:
6364
- name: Set up Git repository
64-
uses: actions/checkout@v2
65+
uses: actions/checkout@v3
6566
- name: Set up node
66-
uses: actions/setup-node@v2
67+
uses: actions/setup-node@v3
6768
with:
6869
node-version: ${{matrix.node}}
69-
- name: Setup Docker
70-
if: ${{matrix.os == 'ubuntu-latest'}}
71-
run: |
72-
docker pull s1hofmann/nut-ci:latest
73-
docker run -it -d --name nut-ci --shm-size 8gb --user $(id -u):$(id -g) -v ${PWD}:${PWD}:rw s1hofmann/nut-ci:latest bash
7470
- name: Install
7571
run: npm ci
7672
- name: Compile
@@ -80,10 +76,9 @@ jobs:
8076
- name: Generate coverage report
8177
uses: GabrielBB/xvfb-action@v1
8278
with:
83-
run: npm run coverage -- --coverageDirectory=coverage/unit
84-
- name: Run Docker E2E tests
85-
if: ${{matrix.os == 'ubuntu-latest'}}
86-
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
79+
run: |
80+
npx playwright install --with-deps
81+
npm run coverage -- --coverageDirectory=coverage/unit
8782
- name: Run Electron e2e test subpackage
8883
uses: GabrielBB/xvfb-action@v1
8984
with:

.github/workflows/snapshot_release.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ on:
88
repository_dispatch:
99
types:
1010
- snapshot-release
11+
workflow_dispatch:
1112

1213
jobs:
1314
test:
1415
strategy:
1516
matrix:
1617
os: [ubuntu-latest, windows-latest, macos-latest]
17-
node: [16]
18+
node: [18]
1819
runs-on: ${{matrix.os}}
1920
steps:
2021
- name: Set up Git repository
21-
uses: actions/checkout@v2
22+
uses: actions/checkout@v3
2223
- name: Set up node
23-
uses: actions/setup-node@v2
24+
uses: actions/setup-node@v3
2425
with:
2526
node-version: ${{matrix.node}}
2627
- name: Setup Docker
@@ -39,7 +40,9 @@ jobs:
3940
- name: Run tests
4041
uses: GabrielBB/xvfb-action@v1
4142
with:
42-
run: npm test
43+
run: |
44+
npx playwright install --with-deps
45+
npm test
4346
- name: Run Docker E2E tests
4447
if: ${{matrix.os == 'ubuntu-latest'}}
4548
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
@@ -54,11 +57,11 @@ jobs:
5457
runs-on: ubuntu-latest
5558
steps:
5659
- name: Set up Git repository
57-
uses: actions/checkout@v2
60+
uses: actions/checkout@v3
5861
- name: Set up node
59-
uses: actions/setup-node@v2
62+
uses: actions/setup-node@v3
6063
with:
61-
node-version: 16
64+
node-version: 18
6265
registry-url: "https://registry.npmjs.org"
6366
- name: Install
6467
run: npm ci
@@ -70,7 +73,7 @@ jobs:
7073
run: npm run publish-next
7174
env:
7275
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
73-
- uses: actions/setup-node@v2
76+
- uses: actions/setup-node@v3
7477
with:
7578
registry-url: "https://npm.pkg.github.com"
7679
- name: Publish snapshot release to GPR

.github/workflows/tagged_release.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [ubuntu-latest, windows-latest, macos-latest]
12-
node: [16]
12+
node: [18]
1313
runs-on: ${{matrix.os}}
1414
steps:
1515
- name: Set up Git repository
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v3
1717
- name: Set up node
18-
uses: actions/setup-node@v2
18+
uses: actions/setup-node@v3
1919
with:
2020
node-version: ${{matrix.node}}
2121
- name: Setup Docker
@@ -32,7 +32,9 @@ jobs:
3232
- name: Generate coverage report
3333
uses: GabrielBB/xvfb-action@v1
3434
with:
35-
run: npm test
35+
run: |
36+
npx playwright install --with-deps
37+
npm test
3638
- name: Run Docker E2E tests
3739
if: ${{matrix.os == 'ubuntu-latest'}}
3840
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
@@ -47,11 +49,11 @@ jobs:
4749
runs-on: ubuntu-latest
4850
steps:
4951
- name: Set up Git repository
50-
uses: actions/checkout@v2
52+
uses: actions/checkout@v3
5153
- name: Set up node
52-
uses: actions/setup-node@v2
54+
uses: actions/setup-node@v3
5355
with:
54-
node-version: 16
56+
node-version: 18
5557
registry-url: "https://registry.npmjs.org"
5658
- name: Install
5759
run: npm ci
@@ -67,7 +69,7 @@ jobs:
6769
run: npm publish
6870
env:
6971
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
70-
- uses: actions/setup-node@v2
72+
- uses: actions/setup-node@v3
7173
with:
7274
registry-url: "https://npm.pkg.github.com"
7375
- name: Publish tagged release to GPR

e2e/window-test/test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
const { _electron: electron } = require("playwright");
2-
const { getActiveWindow, getWindows } = require("@nut-tree/nut-js");
2+
const { sleep, getActiveWindow, getWindows } = require("@nut-tree/nut-js");
33
const { POS_X, POS_Y, WIDTH, HEIGTH, TITLE } = require("./constants");
44

5-
const sleep = async (ms) => {
6-
return new Promise((resolve) => setTimeout(resolve, ms));
7-
};
8-
95
let app;
106
let page;
117
let windowHandle;
128

139
const APP_TIMEOUT = 10000;
10+
jest.setTimeout(APP_TIMEOUT);
1411

1512
beforeEach(async () => {
16-
app = await electron.launch({ args: ["main.js"] });
13+
app = await electron.launch({ args: ["main.js"], cwd: __dirname });
1714
page = await app.firstWindow({ timeout: APP_TIMEOUT });
1815
windowHandle = await app.browserWindow(page);
1916
await page.waitForLoadState("domcontentloaded");

lib/match-request.class.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ export class MatchRequest<NEEDLE_TYPE, PROVIDER_DATA_TYPE> {
1515
public constructor(
1616
public readonly haystack: Image,
1717
public readonly needle: NEEDLE_TYPE,
18-
public readonly confidence: number,
19-
public readonly providerData?: PROVIDER_DATA_TYPE
18+
public readonly confidence: number | undefined,
19+
public readonly providerData?: PROVIDER_DATA_TYPE,
2020
) {}
2121
}
2222

2323
export function isImageMatchRequest<PROVIDER_DATA_TYPE>(
24-
matchRequest: any
24+
matchRequest: any,
2525
): matchRequest is MatchRequest<Image, PROVIDER_DATA_TYPE> {
2626
return isImage(matchRequest.needle);
2727
}
2828

2929
export function isTextMatchRequest<PROVIDER_DATA_TYPE>(
30-
matchRequest: any
30+
matchRequest: any,
3131
): matchRequest is MatchRequest<TextQuery, PROVIDER_DATA_TYPE> {
3232
return isTextQuery(matchRequest.needle);
3333
}
3434

3535
export function isColorMatchRequest<PROVIDER_DATA_TYPE>(
36-
matchRequest: any
36+
matchRequest: any,
3737
): matchRequest is MatchRequest<ColorQuery, PROVIDER_DATA_TYPE> {
3838
return isColorQuery(matchRequest.needle);
3939
}
@@ -42,35 +42,35 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
4242
providerRegistry: ProviderRegistry,
4343
needle: PointResultFindInput,
4444
searchRegion: Region,
45-
minMatch: number,
45+
minMatch: number | undefined,
4646
screenImage: Image,
47-
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
47+
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
4848
): MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE>;
4949
export function createMatchRequest<PROVIDER_DATA_TYPE>(
5050
providerRegistry: ProviderRegistry,
5151
needle: RegionResultFindInput,
5252
searchRegion: Region,
53-
minMatch: number,
53+
minMatch: number | undefined,
5454
screenImage: Image,
55-
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
55+
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
5656
): MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>;
5757
export function createMatchRequest<PROVIDER_DATA_TYPE>(
5858
providerRegistry: ProviderRegistry,
5959
needle: RegionResultFindInput | PointResultFindInput,
6060
searchRegion: Region,
61-
minMatch: number,
61+
minMatch: number | undefined,
6262
screenImage: Image,
63-
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
63+
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
6464
):
6565
| MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>
6666
| MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE>;
6767
export function createMatchRequest<PROVIDER_DATA_TYPE>(
6868
providerRegistry: ProviderRegistry,
6969
needle: RegionResultFindInput | PointResultFindInput,
7070
searchRegion: Region,
71-
minMatch: number,
71+
minMatch: number | undefined,
7272
screenImage: Image,
73-
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
73+
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
7474
):
7575
| MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>
7676
| MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE> {
@@ -80,27 +80,27 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
8080
.info(
8181
`Searching for image ${
8282
needle.id
83-
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`
83+
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`,
8484
);
8585

8686
return new MatchRequest(
8787
screenImage,
8888
needle,
8989
minMatch,
90-
params?.providerData
90+
params?.providerData,
9191
);
9292
} else if (isTextQuery(needle)) {
9393
providerRegistry.getLogProvider().info(
9494
`Searching for ${isLineQuery(needle) ? "line" : "word"} {
9595
${isLineQuery(needle) ? needle.by.line : needle.by.word}
96-
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`
96+
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`,
9797
);
9898

9999
return new MatchRequest(
100100
screenImage,
101101
needle,
102102
minMatch,
103-
params?.providerData
103+
params?.providerData,
104104
);
105105
} else if (isColorQuery(needle)) {
106106
const color = needle.by.color;
@@ -109,7 +109,7 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
109109
.info(
110110
`Searching for color RGBA(${color.R},${color.G},${color.B},${
111111
color.A
112-
}) in region ${searchRegion.toString()}.`
112+
}) in region ${searchRegion.toString()}.`,
113113
);
114114

115115
return new MatchRequest(screenImage, needle, 1, params?.providerData);

0 commit comments

Comments
 (0)