apify-test-tools 0.10.2-beta.6 → 0.10.2-beta.8

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.
Files changed (43) hide show
  1. package/.github/cli/apify-test-tools.mjs +62 -62
  2. package/CHANGELOG.md +1 -0
  3. package/bin/git.ts +5 -1
  4. package/dist/bin/git.d.ts.map +1 -1
  5. package/dist/bin/git.js +4 -1
  6. package/dist/bin/git.js.map +1 -1
  7. package/dist/lib/extend-expect.d.ts.map +1 -1
  8. package/dist/lib/extend-expect.js +37 -218
  9. package/dist/lib/extend-expect.js.map +1 -1
  10. package/dist/lib/lib.d.ts +1 -2
  11. package/dist/lib/lib.d.ts.map +1 -1
  12. package/dist/lib/lib.js +15 -22
  13. package/dist/lib/lib.js.map +1 -1
  14. package/dist/lib/run-checks.d.ts +14 -0
  15. package/dist/lib/run-checks.d.ts.map +1 -0
  16. package/dist/lib/run-checks.js +82 -0
  17. package/dist/lib/run-checks.js.map +1 -0
  18. package/dist/lib/run-test-result.d.ts +3 -6
  19. package/dist/lib/run-test-result.d.ts.map +1 -1
  20. package/dist/lib/run-test-result.js +41 -54
  21. package/dist/lib/run-test-result.js.map +1 -1
  22. package/dist/test/unit/bin/affected-actors-cli.test.js +6 -0
  23. package/dist/test/unit/bin/affected-actors-cli.test.js.map +1 -1
  24. package/dist/test/unit/bin/git.test.js +3 -3
  25. package/dist/test/unit/bin/git.test.js.map +1 -1
  26. package/dist/test/unit/run-checks.test.d.ts +2 -0
  27. package/dist/test/unit/run-checks.test.d.ts.map +1 -0
  28. package/dist/test/unit/run-checks.test.js +62 -0
  29. package/dist/test/unit/run-checks.test.js.map +1 -0
  30. package/dist/test/unit/run-test-result.test.d.ts +2 -0
  31. package/dist/test/unit/run-test-result.test.d.ts.map +1 -0
  32. package/dist/test/unit/run-test-result.test.js +34 -0
  33. package/dist/test/unit/run-test-result.test.js.map +1 -0
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/lib/extend-expect.ts +48 -258
  36. package/lib/lib.ts +24 -28
  37. package/lib/run-checks.ts +101 -0
  38. package/lib/run-test-result.ts +45 -55
  39. package/package.json +1 -1
  40. package/test/unit/bin/affected-actors-cli.test.ts +8 -0
  41. package/test/unit/bin/git.test.ts +8 -5
  42. package/test/unit/run-checks.test.ts +76 -0
  43. package/test/unit/run-test-result.test.ts +44 -0
@@ -124,9 +124,12 @@ describe('getChangedFiles', () => {
124
124
  expect(changedFiles).toStrictEqual(['file1.txt', 'folder/file2.txt']);
125
125
 
126
126
  expect(gitCommandSpy).toHaveBeenCalledTimes(1);
127
- expect(gitCommandSpy).toHaveBeenCalledWith(['diff', '--name-only', `${firstSha}~..${lastSha}`], {
128
- operation: 'get the list of changed files between commits',
129
- });
127
+ expect(gitCommandSpy).toHaveBeenCalledWith(
128
+ ['diff', '--name-only', '--no-renames', `${firstSha}~..${lastSha}`],
129
+ {
130
+ operation: 'get the list of changed files between commits',
131
+ },
132
+ );
130
133
  });
131
134
 
132
135
  it('should throw without running git when the commit list is empty', async () => {
@@ -147,7 +150,7 @@ describe('getChangedFiles', () => {
147
150
  expect(changedFiles).toStrictEqual(['file1.txt', 'folder/file2.txt']);
148
151
 
149
152
  expect(gitCommandSpy).toHaveBeenCalledTimes(1);
150
- expect(gitCommandSpy).toHaveBeenCalledWith(['diff', '--name-only', `${onlySha}~..${onlySha}`], {
153
+ expect(gitCommandSpy).toHaveBeenCalledWith(['diff', '--name-only', '--no-renames', `${onlySha}~..${onlySha}`], {
151
154
  operation: 'get the list of changed files between commits',
152
155
  });
153
156
  });
@@ -412,7 +415,7 @@ describe('getChangedFilesBetween', () => {
412
415
  'src/main.ts',
413
416
  'CHANGELOG.md',
414
417
  ]);
415
- expect(spy).toHaveBeenCalledWith(['diff', '--name-only', 'base-sha..head-sha'], {
418
+ expect(spy).toHaveBeenCalledWith(['diff', '--name-only', '--no-renames', 'base-sha..head-sha'], {
416
419
  operation: 'get the list of changed files between commits',
417
420
  });
418
421
  });
@@ -0,0 +1,76 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { checkRun } from '../../lib/run-checks.js';
4
+ import type { RunTestResult } from '../../lib/run-test-result.js';
5
+
6
+ const fakeRun = (overrides: { status?: string; log?: string; stats?: object; chargedEventCounts?: object } = {}) =>
7
+ ({
8
+ status: overrides.status ?? 'SUCCEEDED',
9
+ getRunInfo: async () => ({
10
+ stats: { durationMillis: 5_000 },
11
+ chargedEventCounts: overrides.chargedEventCounts,
12
+ }),
13
+ getDataset: async () => ({ items: new Array(10) }),
14
+ getStatistics: async () => ({
15
+ requestsFailed: 0,
16
+ requestsRetries: 1,
17
+ requestRetryHistogram: [5, 1],
18
+ ...overrides.stats,
19
+ }),
20
+ getLog: async () => overrides.log ?? 'all good',
21
+ }) as unknown as RunTestResult;
22
+
23
+ const failures = async (run: RunTestResult, options: Parameters<typeof checkRun>[1]) =>
24
+ (await checkRun(run, options)).filter(({ pass }) => !pass).map(({ name }) => name);
25
+
26
+ describe('checkRun()', () => {
27
+ it('passes a run matching the defaults', async () => {
28
+ expect(await failures(fakeRun(), { datasetItemCount: 10 })).toEqual([]);
29
+ });
30
+
31
+ it('reports every failing check at once', async () => {
32
+ const run = fakeRun({ status: 'FAILED', log: 'TypeError: x', stats: { requestsFailed: 2 } });
33
+ expect(await failures(run, { datasetItemCount: { min: 11 } })).toEqual([
34
+ 'status',
35
+ 'datasetItemCount',
36
+ 'failedRequests',
37
+ 'forbiddenLogs',
38
+ ]);
39
+ });
40
+
41
+ it('disables a check with null', async () => {
42
+ const run = fakeRun({ stats: { requestsFailed: 2 } });
43
+ expect(await failures(run, { datasetItemCount: 10, failedRequests: null })).toEqual([]);
44
+ });
45
+
46
+ it('treats explicitly undefined options as disabled checks', async () => {
47
+ const options = { datasetItemCount: 10, duration: undefined, maxRetriesPerRequest: undefined };
48
+ expect(await failures(fakeRun(), options)).toEqual([]);
49
+ });
50
+
51
+ it('checks the longest retry chain only when asked to', async () => {
52
+ expect(await failures(fakeRun(), { datasetItemCount: 10, maxRetriesPerRequest: 0 })).toEqual([
53
+ 'maxRetriesPerRequest',
54
+ ]);
55
+ expect(await failures(fakeRun(), { datasetItemCount: 10, maxRetriesPerRequest: 1 })).toEqual([]);
56
+ });
57
+
58
+ describe('chargedEventCounts', () => {
59
+ const run = fakeRun({ chargedEventCounts: { start: 1, item: 7 } });
60
+
61
+ it('passes matching counts and intervals', async () => {
62
+ const options = { datasetItemCount: 10, chargedEventCounts: { start: 1, item: { min: 5 } } };
63
+ expect(await failures(run, options)).toEqual([]);
64
+ });
65
+
66
+ it('expects unlisted charged events to not happen', async () => {
67
+ const options = { datasetItemCount: 10, chargedEventCounts: { start: 1 } as Record<string, number> };
68
+ expect(await failures(run, options)).toEqual(['chargedEventCounts.item']);
69
+ });
70
+
71
+ it('fails an expected event that was never charged', async () => {
72
+ const options = { datasetItemCount: 10, chargedEventCounts: { start: 1, item: 7, extra: { min: 0 } } };
73
+ expect(await failures(run, options)).toEqual(['chargedEventCounts.extra']);
74
+ });
75
+ });
76
+ });
@@ -0,0 +1,44 @@
1
+ import type { ActorRun, ApifyClient } from 'apify-client';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+
4
+ import { RunTestResult } from '../../lib/run-test-result.js';
5
+
6
+ const run = { id: 'run', status: 'SUCCEEDED', defaultDatasetId: 'ds', defaultKeyValueStoreId: 'kvs' } as ActorRun;
7
+
8
+ describe('RunTestResult', () => {
9
+ it('fetches the log once, even when empty or requested concurrently', async () => {
10
+ const get = vi.fn(async () => '');
11
+ const client = { run: () => ({ log: () => ({ get }) }) } as unknown as ApifyClient;
12
+ const result = new RunTestResult(client, run);
13
+
14
+ await Promise.all([result.getLog(), result.getLog()]);
15
+ await result.getLog();
16
+
17
+ expect(get).toHaveBeenCalledTimes(1);
18
+ });
19
+
20
+ it('retries after a failed fetch', async () => {
21
+ const get = vi.fn().mockRejectedValueOnce(new Error('boom')).mockResolvedValueOnce('log');
22
+ const client = { run: () => ({ log: () => ({ get }) }) } as unknown as ApifyClient;
23
+ const result = new RunTestResult(client, run);
24
+
25
+ await expect(result.getLog()).rejects.toThrow('boom');
26
+ expect(await result.getLog()).toBe('log');
27
+ });
28
+
29
+ it('pages through the dataset instead of listing it in one response', async () => {
30
+ const total = 25_000;
31
+ const listItems = vi.fn(async ({ offset, limit }: { offset: number; limit: number }) => ({
32
+ total,
33
+ items: Array.from({ length: Math.min(limit, total - offset) }, (_, i) => offset + i),
34
+ }));
35
+ const client = { dataset: () => ({ listItems }) } as unknown as ApifyClient;
36
+ const result = new RunTestResult(client, run);
37
+
38
+ const { items } = await result.getDataset<number>();
39
+
40
+ expect(items).toHaveLength(total);
41
+ expect(items[24_999]).toBe(24_999);
42
+ expect(listItems).toHaveBeenCalledTimes(25);
43
+ });
44
+ });