Skip to content

Commit

Permalink
Bugfix/(nut tree/plugin ocr#25)/default confidence (#541)
Browse files Browse the repository at this point in the history
* (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
  • Loading branch information
s1hofmann committed Oct 17, 2023
1 parent dd5c382 commit 778cd7f
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 208 deletions.
25 changes: 10 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ on:
# paths-ignore:
# - '**/*.md'
pull_request:
workflow_dispatch:

jobs:
sonar:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- name: Setup Docker
run: |
docker pull s1hofmann/nut-ci:latest
Expand Down Expand Up @@ -57,20 +58,15 @@ jobs:
strategy:
matrix:
os: [windows-latest, macos-latest]
node: [16]
node: [18]
runs-on: ${{matrix.os}}
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- name: Setup Docker
if: ${{matrix.os == 'ubuntu-latest'}}
run: |
docker pull s1hofmann/nut-ci:latest
docker run -it -d --name nut-ci --shm-size 8gb --user $(id -u):$(id -g) -v ${PWD}:${PWD}:rw s1hofmann/nut-ci:latest bash
- name: Install
run: npm ci
- name: Compile
Expand All @@ -80,10 +76,9 @@ jobs:
- name: Generate coverage report
uses: GabrielBB/xvfb-action@v1
with:
run: npm run coverage -- --coverageDirectory=coverage/unit
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
run: |
npx playwright install --with-deps
npm run coverage -- --coverageDirectory=coverage/unit
- name: Run Electron e2e test subpackage
uses: GabrielBB/xvfb-action@v1
with:
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/snapshot_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ on:
repository_dispatch:
types:
- snapshot-release
workflow_dispatch:

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [16]
node: [18]
runs-on: ${{matrix.os}}
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- name: Setup Docker
Expand All @@ -39,7 +40,9 @@ jobs:
- name: Run tests
uses: GabrielBB/xvfb-action@v1
with:
run: npm test
run: |
npx playwright install --with-deps
npm test
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
Expand All @@ -54,11 +57,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Install
run: npm ci
Expand All @@ -70,7 +73,7 @@ jobs:
run: npm run publish-next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
registry-url: "https://npm.pkg.github.com"
- name: Publish snapshot release to GPR
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/tagged_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [16]
node: [18]
runs-on: ${{matrix.os}}
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- name: Setup Docker
Expand All @@ -32,7 +32,9 @@ jobs:
- name: Generate coverage report
uses: GabrielBB/xvfb-action@v1
with:
run: npm test
run: |
npx playwright install --with-deps
npm test
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
Expand All @@ -47,11 +49,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Install
run: npm ci
Expand All @@ -67,7 +69,7 @@ jobs:
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
registry-url: "https://npm.pkg.github.com"
- name: Publish tagged release to GPR
Expand Down
9 changes: 3 additions & 6 deletions e2e/window-test/test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
const { _electron: electron } = require("playwright");
const { getActiveWindow, getWindows } = require("@nut-tree/nut-js");
const { sleep, getActiveWindow, getWindows } = require("@nut-tree/nut-js");
const { POS_X, POS_Y, WIDTH, HEIGTH, TITLE } = require("./constants");

const sleep = async (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

let app;
let page;
let windowHandle;

const APP_TIMEOUT = 10000;
jest.setTimeout(APP_TIMEOUT);

beforeEach(async () => {
app = await electron.launch({ args: ["main.js"] });
app = await electron.launch({ args: ["main.js"], cwd: __dirname });
page = await app.firstWindow({ timeout: APP_TIMEOUT });
windowHandle = await app.browserWindow(page);
await page.waitForLoadState("domcontentloaded");
Expand Down
36 changes: 18 additions & 18 deletions lib/match-request.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ export class MatchRequest<NEEDLE_TYPE, PROVIDER_DATA_TYPE> {
public constructor(
public readonly haystack: Image,
public readonly needle: NEEDLE_TYPE,
public readonly confidence: number,
public readonly providerData?: PROVIDER_DATA_TYPE
public readonly confidence: number | undefined,
public readonly providerData?: PROVIDER_DATA_TYPE,
) {}
}

export function isImageMatchRequest<PROVIDER_DATA_TYPE>(
matchRequest: any
matchRequest: any,
): matchRequest is MatchRequest<Image, PROVIDER_DATA_TYPE> {
return isImage(matchRequest.needle);
}

export function isTextMatchRequest<PROVIDER_DATA_TYPE>(
matchRequest: any
matchRequest: any,
): matchRequest is MatchRequest<TextQuery, PROVIDER_DATA_TYPE> {
return isTextQuery(matchRequest.needle);
}

export function isColorMatchRequest<PROVIDER_DATA_TYPE>(
matchRequest: any
matchRequest: any,
): matchRequest is MatchRequest<ColorQuery, PROVIDER_DATA_TYPE> {
return isColorQuery(matchRequest.needle);
}
Expand All @@ -42,35 +42,35 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
providerRegistry: ProviderRegistry,
needle: PointResultFindInput,
searchRegion: Region,
minMatch: number,
minMatch: number | undefined,
screenImage: Image,
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
): MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE>;
export function createMatchRequest<PROVIDER_DATA_TYPE>(
providerRegistry: ProviderRegistry,
needle: RegionResultFindInput,
searchRegion: Region,
minMatch: number,
minMatch: number | undefined,
screenImage: Image,
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
): MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>;
export function createMatchRequest<PROVIDER_DATA_TYPE>(
providerRegistry: ProviderRegistry,
needle: RegionResultFindInput | PointResultFindInput,
searchRegion: Region,
minMatch: number,
minMatch: number | undefined,
screenImage: Image,
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
):
| MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>
| MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE>;
export function createMatchRequest<PROVIDER_DATA_TYPE>(
providerRegistry: ProviderRegistry,
needle: RegionResultFindInput | PointResultFindInput,
searchRegion: Region,
minMatch: number,
minMatch: number | undefined,
screenImage: Image,
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
):
| MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>
| MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE> {
Expand All @@ -80,27 +80,27 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
.info(
`Searching for image ${
needle.id
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`,
);

return new MatchRequest(
screenImage,
needle,
minMatch,
params?.providerData
params?.providerData,
);
} else if (isTextQuery(needle)) {
providerRegistry.getLogProvider().info(
`Searching for ${isLineQuery(needle) ? "line" : "word"} {
${isLineQuery(needle) ? needle.by.line : needle.by.word}
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`,
);

return new MatchRequest(
screenImage,
needle,
minMatch,
params?.providerData
params?.providerData,
);
} else if (isColorQuery(needle)) {
const color = needle.by.color;
Expand All @@ -109,7 +109,7 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
.info(
`Searching for color RGBA(${color.R},${color.G},${color.B},${
color.A
}) in region ${searchRegion.toString()}.`
}) in region ${searchRegion.toString()}.`,
);

return new MatchRequest(screenImage, needle, 1, params?.providerData);
Expand Down
Loading

0 comments on commit 778cd7f

Please sign in to comment.