Skip to content
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
npm i -D apify-test-tools
```

- Requires `vitest` version `3.2.0` or later (uses [annotate](https://vitest.dev/guide/test-context.html#annotate))
- Requires Node.js 22.12–22.x, 24.x, or 26+ and `vitest` 5.0.3+ (uses [annotate](https://vitest.dev/guide/test-context.html#annotate))
- Make sure `target` and `module` in your `tsconfig.json`'s `compilerOptions` are set to `ES2022`
- Every Actor must already have at least one build under its default build tag (usually `latest`), built
from a Git repository version whose URL points to this repository. Build it once manually on the
Expand Down
21 changes: 6 additions & 15 deletions lib/extend-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,13 @@ export const extendExpect = (expect: ExpectStatic): ExpectStatic => {
// here we are switching logic of expect and expect.soft
// expect => expect.soft
// expect.hard => expect
const { soft } = expect;
const oldExpect = { ...expect };
const softExpect = <T>(actual: T, message?: string): Assertion => {
return soft(actual, message);
};
const softExpect = Object.assign(
<T>(actual: T, message?: string): Assertion<void, T> => expect.soft(actual, message),
expect,
{ hard: <T>(actual: T, message?: string): Assertion<void, T> => expect(actual, message) },
);

for (const [key, value] of Object.entries(oldExpect)) {
// @ts-expect-error: No idea how to type this properly
softExpect[key] = value;
}

softExpect.hard = <T>(actual: T, message?: string): Assertion<T> => {
return expect(actual, message);
};

return softExpect as unknown as ExpectStatic;
return softExpect;
};

type Diffs = {
Expand Down
12 changes: 6 additions & 6 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export type RunStatus =
| 'TIMING-OUT'
| 'TIMED-OUT';

export interface ActorMatchers<R = unknown> {
export interface ActorMatchers<R extends void | Promise<void> = void> {
toBeArray: () => R;
toBeBoolean: () => R;
toBeEmptyArray: () => R;
Expand All @@ -133,7 +133,7 @@ export interface ActorMatchers<R = unknown> {
*/
toFinishWith: <PpeEvent extends string>(options: ToFinishWithOptions<PpeEvent>) => Promise<R>;
toStartWith: (prefix: string) => R;
hard: <T>(actual: T, message?: string) => Assertion;
hard: <T>(actual: T, message?: string) => Assertion<void, T>;
}

export type ActorTestOptions = Omit<TestOptions, 'retry' | 'timeout'> & {
Expand All @@ -155,10 +155,10 @@ export type ActorTestOptions = Omit<TestOptions, 'retry' | 'timeout'> & {
};

declare module 'vitest' {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-object-type
interface Assertion<T = any> extends ActorMatchers<T> {}
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-object-type
interface Matchers<T = any> extends ActorMatchers<T> {}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars
interface Assertion<R extends void | Promise<void> = void, T = unknown> extends ActorMatchers<R> {}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars
interface Matchers<R extends void | Promise<void> = void | Promise<void>, T = unknown> extends ActorMatchers<R> {}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface AsymmetricMatchersContaining extends ActorMatchers {}
}
Loading
Loading