apify-test-tools 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -175,7 +175,7 @@ export const extendExpect = (expect: ExpectStatic): ExpectStatic => {
175
175
  isWithinInterval(ppeDiffs, actual[ppeEvent], expected, ppeEvent as PpeEvent);
176
176
  }
177
177
 
178
- diffs.pass = ppeDiffs.pass;
178
+ diffs.pass = diffs.pass && ppeDiffs.pass;
179
179
  diffs.actual.push(ppeDiffs.actual.join('\n '));
180
180
  diffs.expected.push(ppeDiffs.expected.join('\n '));
181
181
  }
package/lib/lib.ts CHANGED
@@ -173,6 +173,10 @@ interface StandbyTask {
173
173
  taskId: string;
174
174
  }
175
175
 
176
+ const randomInt = (min: number, max: number) => {
177
+ return Math.floor(Math.random() * (max - min + 1)) + min;
178
+ }
179
+
176
180
  /**
177
181
  * Creates a task with specific `build` - either `buildNumber` or default.
178
182
  *
@@ -202,11 +206,15 @@ const createStandbyTask = async (actorNameOrId: string, buildNumber?: string): P
202
206
  }
203
207
 
204
208
  try {
209
+ const title = `Test task - ${build}:${actorNameOrId}`.slice(0, 62);
210
+ // we try to create unique task name containing only `a-z0-9-` characters and at most 63 characters long
211
+ const name = `${randomInt(1, 1_000_000)}${title.toLowerCase().replaceAll(/\s+/g, '').replaceAll(/[^a-z0-9-]+/g, '-')}`.slice(0, 62);
205
212
  const newTask = await apifyClient.tasks().create({
206
213
  actId: actorNameOrId,
207
214
  actorStandby: actorStandbyOptions,
208
215
  description: `Task for testing standby version ${build}`,
209
- title: `Test task - ${build}`,
216
+ title,
217
+ name,
210
218
  }) as Task & { standbyUrl?: string };
211
219
 
212
220
  const { id, standbyUrl } = newTask;
@@ -234,7 +242,17 @@ const createStartRunFn = <T>(actorNameOrId: string, testContext: TestContext) =>
234
242
  input,
235
243
  options,
236
244
  prefilledInput,
245
+ runId,
237
246
  } = runOptions;
247
+
248
+ if (runId) {
249
+ const run = await apifyClient.run(runId).get()
250
+ if (!run) {
251
+ throw new Error(`Run with id "${runId}" doesn't exist`);
252
+ }
253
+ return new RunTestResult(apifyClient, run)
254
+ }
255
+
238
256
  const actor = apifyClient.actor(actorNameOrId);
239
257
 
240
258
  const actorInput = {
package/lib/types.ts CHANGED
@@ -12,6 +12,13 @@ export type RunOptions<T> = {
12
12
  input: Omit<T, 'actorName'>
13
13
  options?: ActorCallOptions
14
14
  prefilledInput?: boolean
15
+ /**
16
+ * If you specify `runId`, all the other options will be ignored and this run's data will
17
+ * be downloaded instead.
18
+ *
19
+ * This is usefull for testing your tests on existing runs
20
+ */
21
+ runId?: string
15
22
  }
16
23
 
17
24
  export type Dataset<T> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-test-tools",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "description": "TBD",
6
6
  "engines": {