Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ echo "Installing node version $nodeVersion"
nvm install $nodeVersion

npm ci
npm --prefix e2e/plugin-test ci
E2E_TEST=1 npm run coverage -- --coverageDirectory=coverage/e2e
147 changes: 61 additions & 86 deletions e2e/electron-test/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion e2e/electron-test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-test",
"version": "1.6.0",
"version": "1.7.0",
"description": "A test to verify usage with Electron",
"main": "main.js",
"author": {
Expand Down
4 changes: 3 additions & 1 deletion index.e2e.spec.ts → e2e/plugin-test/index.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
screen,
sleep,
straightTo,
} from "./index";
} from "@nut-tree/nut-js";

import "@nut-tree/template-matcher";

jest.setTimeout(60000);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { jestMatchers, Key, keyboard, screen } from "../index";
import { jestMatchers, Key, keyboard, screen } from "@nut-tree/nut-js";
import "@nut-tree/template-matcher";

jest.setTimeout(30000);
expect.extend(jestMatchers);
Expand Down
6,789 changes: 6,789 additions & 0 deletions e2e/plugin-test/package-lock.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions e2e/plugin-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "plugin-tests",
"version": "1.7.0",
"description": "Tests to verify plugins",
"main": "main.js",
"author": {
"name": "Simon Hofmann",
"email": "kontakt@s1h.org",
"url": "https://s1h.org"
},
"license": "Apache-2.0",
"devDependencies": {
"@nut-tree/nut-js": "file:../../",
"@nut-tree/template-matcher": "0.0.1",
"node-abort-controller": "2.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import {existsSync} from "fs";
import {VisionAdapter} from "./adapter/vision.adapter.class";
import {FileType} from "./file-type.enum";
import {ScreenClass} from "./screen.class";
import {sleep} from "./sleep.function";
import {screen, sleep, FileType, Region} from "@nut-tree/nut-js";
import AbortController from "node-abort-controller";
import {Region} from "./region.class";
import providerRegistry from "./provider/provider-registry.class";

import "@nut-tree/template-matcher";

jest.setTimeout(10000);

describe("Screen.", () => {
it("should capture the screen", () => {
// GIVEN
const visionAdapter = new VisionAdapter(providerRegistry);
const SUT = new ScreenClass(visionAdapter);

// WHEN
SUT.capture("asdf", FileType.PNG).then(filename => {
screen.capture("asdf", FileType.PNG).then(filename => {
// THEN
expect(filename).not.toBeNull();
sleep(1000).then(() => {
Expand All @@ -27,11 +22,9 @@ describe("Screen.", () => {

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

// WHEN
SUT.capture("asdf", FileType.JPG).then(filename => {
screen.capture("asdf", FileType.JPG).then(filename => {
// THEN
expect(filename).not.toBeNull();
sleep(1000).then(() => {
Expand All @@ -42,12 +35,10 @@ describe("Screen.", () => {

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

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

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

// WHEN
SUT.capture("asdf", FileType.JPG, "./", "", postfix).then(filename => {
screen.capture("asdf", FileType.JPG, "./", "", postfix).then(filename => {
// THEN
expect(filename.includes(postfix)).toBeTruthy();
expect(filename).not.toBeNull();
Expand All @@ -76,14 +65,12 @@ describe("Screen.", () => {

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

// WHEN
SUT.capture("asdf", FileType.JPG, "./", prefix, postfix).then(output => {
screen.capture("asdf", FileType.JPG, "./", prefix, postfix).then(output => {
// THEN
expect(output.includes(`${prefix}${filename}${postfix}`)).toBeTruthy();
expect(output).not.toBeNull();
Expand All @@ -96,14 +83,12 @@ describe("Screen.", () => {
it("should reject after timeout", async () => {
// GIVEN
const timeout = 5000;
const visionAdapter = new VisionAdapter(providerRegistry);
const SUT = new ScreenClass(visionAdapter);
SUT.config.resourceDirectory = "./e2e/assets";
screen.config.resourceDirectory = "./e2e/assets";

// WHEN
const start = Date.now();
try {
await SUT.waitFor("calculator.png", timeout);
await screen.waitFor("calculator.png", timeout);
} catch (e) {
// THEN
expect(e).toBe(`Action timed out after ${timeout} ms`);
Expand All @@ -120,13 +105,11 @@ describe("Screen.", () => {
const abortAfterMs = 1000;
const controller = new AbortController();
const signal = controller.signal;
const visionAdapter = new VisionAdapter(providerRegistry);
const SUT = new ScreenClass(visionAdapter);
SUT.config.resourceDirectory = "./e2e/assets";
screen.config.resourceDirectory = "./e2e/assets";

// WHEN
const start = Date.now();
SUT.waitFor("calculator.png", timeout, {abort: signal}).catch(e => {
screen.waitFor("calculator.png", timeout, {abort: signal}).catch(e => {
const end = Date.now();

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

it("should grab the whole screen content and return an Image", async () => {
// GIVEN
const visionAdapter = new VisionAdapter(providerRegistry);
const SUT = new ScreenClass(visionAdapter);
const screenWidth = await SUT.width();
const screenHeight = await SUT.height();
const screenWidth = await screen.width();
const screenHeight = await screen.height();

// WHEN
const image = await SUT.grab();
const image = await screen.grab();

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

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

// WHEN
const image = await SUT.grabRegion(regionToGrab);
const image = await screen.grabRegion(regionToGrab);

// THEN
expect(image.data).not.toBeUndefined();
Expand Down
Loading