-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/547/improve jest matchers (#549)
* (#547) New matcher toHaveColor that verifies pixel colors on screen * (#547) Updated toShow to support full search parameters, added the possibility to pass a region to directly specify a search region instead of the whole screen * (#547) Expose new matchers * (#547) npm audit fix * (#547) Try to increase node heap space * (#547) Try to increase node heap space * (#547) Get rid of Docker tests * (#547) Addressed some sonar issues * (#547) Don't run coverage report again after the first stage
- Loading branch information
Showing
19 changed files
with
332 additions
and
278 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { RGBA, screen } from "../../../index"; | ||
import { Point } from "../../point.class"; | ||
import { mockPartial } from "sneer"; | ||
import { toHaveColor } from "./toHaveColor.function"; | ||
|
||
// jest.mock("jimp", () => {}); | ||
|
||
const targetPoint = new Point(400, 400); | ||
|
||
describe(".toHaveColor", () => { | ||
it("should succeed when screen pixel has the correct RGBA value", async () => { | ||
// GIVEN | ||
screen.colorAt = mockPartial(() => { | ||
return new RGBA(0, 0, 0, 0); | ||
}); | ||
|
||
// WHEN | ||
const result = await toHaveColor(targetPoint, new RGBA(0, 0, 0, 0)); | ||
|
||
// THEN | ||
expect(result.pass).toBeTruthy(); | ||
}); | ||
|
||
it("should fail when the screen pixel has the incorrect RGBA value", async () => { | ||
// GIVEN | ||
screen.colorAt = mockPartial(() => { | ||
return new RGBA(255, 0, 5, 0); | ||
}); | ||
|
||
// WHEN | ||
const result = await toHaveColor(targetPoint, new RGBA(0, 0, 0, 0)); | ||
|
||
// THEN | ||
expect(result.pass).toBeFalsy(); | ||
}); | ||
|
||
it("should succeed when the screen pixel has the correct RGBA value", async () => { | ||
// GIVEN | ||
screen.colorAt = mockPartial(() => { | ||
return new RGBA(0, 0, 0, 0); | ||
}); | ||
expect.extend({ | ||
toHaveColor, | ||
}); | ||
|
||
// WHEN | ||
|
||
// THEN | ||
await expect(targetPoint).toHaveColor(new RGBA(0, 0, 0, 0)); | ||
}); | ||
|
||
it("should succeed when the screen pixel has the incorrect RGBA value", async () => { | ||
// GIVEN | ||
screen.colorAt = mockPartial(() => { | ||
return new RGBA(255, 0, 5, 0); | ||
}); | ||
expect.extend({ | ||
toHaveColor, | ||
}); | ||
|
||
// WHEN | ||
|
||
// THEN | ||
await expect(targetPoint).not.toHaveColor(new RGBA(0, 0, 0, 0)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Point, RGBA, screen } from "../../../index"; | ||
|
||
export const toHaveColor = async (received: Point, needle: RGBA) => { | ||
const color = await screen.colorAt(received); | ||
const match = color.toHex() === needle.toHex(); | ||
if (match) { | ||
return { | ||
message: () => | ||
`Expected pixel ${received.toString()} not to to have color ${needle.toHex()}`, | ||
pass: true, | ||
}; | ||
} else { | ||
return { | ||
message: () => | ||
`Expected pixel ${received.toString()} to have color ${needle.toHex()} but is ${color.toHex()}`, | ||
pass: false, | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,44 @@ | ||
import { FindInput, ScreenClass } from "../../screen.class"; | ||
import { OptionalSearchParameters } from "../../optionalsearchparameters.class"; | ||
import { isRegion, Region } from "../../region.class"; | ||
import { screen } from "../../../index"; | ||
|
||
export const toShow = async ( | ||
received: ScreenClass, | ||
export const toShow = async <PROVIDER_DATA>( | ||
received: ScreenClass | Region, | ||
needle: FindInput, | ||
confidence?: number | ||
parameters?: OptionalSearchParameters<PROVIDER_DATA>, | ||
) => { | ||
let locationParams; | ||
if (confidence) { | ||
locationParams = new OptionalSearchParameters(); | ||
locationParams.confidence = confidence; | ||
} | ||
const identifier = (await needle).id; | ||
try { | ||
await received.find(needle, locationParams); | ||
return { | ||
message: () => `Expected screen to not show ${identifier}`, | ||
pass: true, | ||
}; | ||
} catch (err) { | ||
return { | ||
message: () => `Screen is not showing ${identifier}: ${err}`, | ||
pass: false, | ||
}; | ||
if (isRegion(received)) { | ||
if (parameters != null) { | ||
parameters.searchRegion = received; | ||
} else { | ||
parameters = { searchRegion: received }; | ||
} | ||
try { | ||
await screen.find(needle, parameters); | ||
return { | ||
message: () => `Expected screen to not show ${identifier}`, | ||
pass: true, | ||
}; | ||
} catch (err) { | ||
return { | ||
message: () => `Screen is not showing ${identifier}: ${err}`, | ||
pass: false, | ||
}; | ||
} | ||
} else { | ||
try { | ||
await received.find(needle, parameters); | ||
return { | ||
message: () => `Expected screen to not show ${identifier}`, | ||
pass: true, | ||
}; | ||
} catch (err) { | ||
return { | ||
message: () => `Screen is not showing ${identifier}: ${err}`, | ||
pass: false, | ||
}; | ||
} | ||
} | ||
}; |
Oops, something went wrong.