apify-test-tools 0.6.0 → 0.6.1

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 (108) hide show
  1. package/.github/workflows/_check_code.yaml +17 -19
  2. package/.github/workflows/_update_release_metadata.yaml +1 -1
  3. package/.github/workflows/manual_release_stable.yaml +1 -0
  4. package/.github/workflows/on_master.yaml +2 -0
  5. package/.husky/pre-commit +13 -0
  6. package/CHANGELOG.md +11 -3
  7. package/CONTRIBUTING.md +5 -0
  8. package/README.md +39 -43
  9. package/bin/build.ts +138 -87
  10. package/bin/diff-changes.ts +156 -0
  11. package/bin/diff-json-schema.ts +50 -0
  12. package/bin/git.ts +42 -11
  13. package/bin/github.ts +7 -6
  14. package/bin/main.ts +21 -11
  15. package/bin/slack.ts +6 -2
  16. package/bin/test-report.ts +55 -44
  17. package/bin/types.ts +56 -59
  18. package/bin/utils.ts +19 -131
  19. package/dist/bin/build.d.ts +1 -1
  20. package/dist/bin/build.d.ts.map +1 -1
  21. package/dist/bin/build.js +49 -31
  22. package/dist/bin/build.js.map +1 -1
  23. package/dist/bin/diff-changes.d.ts +16 -0
  24. package/dist/bin/diff-changes.d.ts.map +1 -0
  25. package/dist/bin/diff-changes.js +103 -0
  26. package/dist/bin/diff-changes.js.map +1 -0
  27. package/dist/bin/diff-json-schema.d.ts +7 -0
  28. package/dist/bin/diff-json-schema.d.ts.map +1 -0
  29. package/dist/bin/diff-json-schema.js +45 -0
  30. package/dist/bin/diff-json-schema.js.map +1 -0
  31. package/dist/bin/git.d.ts +8 -3
  32. package/dist/bin/git.d.ts.map +1 -1
  33. package/dist/bin/git.js +35 -10
  34. package/dist/bin/git.js.map +1 -1
  35. package/dist/bin/github.d.ts +1 -3
  36. package/dist/bin/github.d.ts.map +1 -1
  37. package/dist/bin/github.js +5 -5
  38. package/dist/bin/github.js.map +1 -1
  39. package/dist/bin/main.js +14 -5
  40. package/dist/bin/main.js.map +1 -1
  41. package/dist/bin/slack.d.ts +1 -1
  42. package/dist/bin/slack.d.ts.map +1 -1
  43. package/dist/bin/slack.js +1 -1
  44. package/dist/bin/slack.js.map +1 -1
  45. package/dist/bin/test-report.d.ts.map +1 -1
  46. package/dist/bin/test-report.js +9 -3
  47. package/dist/bin/test-report.js.map +1 -1
  48. package/dist/bin/types.d.ts +0 -1
  49. package/dist/bin/types.d.ts.map +1 -1
  50. package/dist/bin/utils.d.ts +0 -14
  51. package/dist/bin/utils.d.ts.map +1 -1
  52. package/dist/bin/utils.js +12 -95
  53. package/dist/bin/utils.js.map +1 -1
  54. package/dist/lib/extend-expect.d.ts.map +1 -1
  55. package/dist/lib/extend-expect.js +11 -11
  56. package/dist/lib/extend-expect.js.map +1 -1
  57. package/dist/lib/lib.d.ts +3 -2
  58. package/dist/lib/lib.d.ts.map +1 -1
  59. package/dist/lib/lib.js +7 -3
  60. package/dist/lib/lib.js.map +1 -1
  61. package/dist/lib/run-test-result.d.ts +1 -1
  62. package/dist/lib/run-test-result.d.ts.map +1 -1
  63. package/dist/lib/run-test-result.js.map +1 -1
  64. package/dist/lib/types.d.ts +2 -3
  65. package/dist/lib/types.d.ts.map +1 -1
  66. package/dist/lib/utils.d.ts +1 -1
  67. package/dist/lib/utils.d.ts.map +1 -1
  68. package/dist/lib/utils.js +4 -1
  69. package/dist/lib/utils.js.map +1 -1
  70. package/dist/test/unit/bin/diff-changes.test.d.ts +2 -0
  71. package/dist/test/unit/bin/diff-changes.test.d.ts.map +1 -0
  72. package/dist/test/unit/bin/diff-changes.test.js +159 -0
  73. package/dist/test/unit/bin/diff-changes.test.js.map +1 -0
  74. package/dist/test/unit/bin/diff.test.d.ts +2 -0
  75. package/dist/test/unit/bin/diff.test.d.ts.map +1 -0
  76. package/dist/test/unit/bin/diff.test.js +143 -0
  77. package/dist/test/unit/bin/diff.test.js.map +1 -0
  78. package/dist/test/unit/bin/git.test.js +48 -19
  79. package/dist/test/unit/bin/git.test.js.map +1 -1
  80. package/dist/test/unit/custom-matchers.test.js +3 -8
  81. package/dist/test/unit/custom-matchers.test.js.map +1 -1
  82. package/dist/test/unit/parse-commit.test.js +1 -1
  83. package/dist/test/unit/parse-commit.test.js.map +1 -1
  84. package/dist/test/unit/should-built-and-test.test.js +159 -39
  85. package/dist/test/unit/should-built-and-test.test.js.map +1 -1
  86. package/dist/tsconfig.tsbuildinfo +1 -1
  87. package/eslint.config.mjs +4 -2
  88. package/knip.json +1 -1
  89. package/lib/extend-expect.ts +21 -21
  90. package/lib/lib.ts +17 -17
  91. package/lib/run-test-result.ts +6 -2
  92. package/lib/types.ts +5 -8
  93. package/lib/utils.ts +13 -9
  94. package/package.json +10 -3
  95. package/test/tsconfig.json +2 -4
  96. package/test/unit/bin/diff-changes.test.ts +182 -0
  97. package/test/unit/bin/diff.test.ts +212 -0
  98. package/test/unit/bin/git.test.ts +59 -20
  99. package/test/unit/custom-matchers.test.ts +10 -9
  100. package/test/unit/parse-commit.test.ts +2 -1
  101. package/test/unit/should-built-and-test.test.ts +181 -40
  102. package/bin/consts.ts +0 -6
  103. package/dist/bin/consts.d.ts +0 -4
  104. package/dist/bin/consts.d.ts.map +0 -1
  105. package/dist/bin/consts.js +0 -6
  106. package/dist/bin/consts.js.map +0 -1
  107. package/example-github-events/pull-request.json +0 -523
  108. package/example-github-events/push.json +0 -216
@@ -1,7 +1,9 @@
1
- import { describe, expect, test } from 'vitest';
1
+ import type { MockInstance } from 'vitest';
2
+ import { beforeEach, describe, expect, test, vi } from 'vitest';
2
3
 
3
- import type { ActorConfig } from '../../bin/types.js';
4
- import { getChangedActors } from '../../bin/utils.js';
4
+ import { getChangedActors } from '../../bin/diff-changes.js';
5
+ import * as DiffJsonSchema from '../../bin/diff-json-schema.js';
6
+ import type { ActorConfig, Commit } from '../../bin/types.js';
5
7
 
6
8
  describe('Should build and test parser', () => {
7
9
  // From https://github.com/apify-store/testing-repo-for-github-actions
@@ -23,89 +25,226 @@ describe('Should build and test parser', () => {
23
25
  },
24
26
  ];
25
27
 
26
- test('Ignores dev-only readme', async () => {
28
+ const commits: Commit[] = [
29
+ { sha: 'Commit1', author: '', date: '', message: '' },
30
+ { sha: 'Commit3', author: '', date: '', message: '' },
31
+ ];
32
+
33
+ let isCosmeticOnlyJsonSchemaSpy: MockInstance;
34
+
35
+ beforeEach(() => {
36
+ // Default: JSON changes are functional (triggers build/test)
37
+ isCosmeticOnlyJsonSchemaSpy = vi.spyOn(DiffJsonSchema, 'isCosmeticOnlyJsonSchemaChange').mockReturnValue(false);
38
+ });
39
+
40
+ test('Ignores dev-only readme', () => {
27
41
  const FILES = ['README.md', 'code/README.md', 'shared/README.md'];
28
42
 
29
- const { actorsChanged, codeChanged } = await getChangedActors({ actorConfigs: ACTOR_CONFIGS, isLatest: false, filepathsChanged: FILES });
43
+ const actorsChanged = getChangedActors({
44
+ actorConfigs: ACTOR_CONFIGS,
45
+ isLatest: false,
46
+ filepathsChanged: FILES,
47
+ commits,
48
+ });
30
49
 
31
50
  expect(actorsChanged).toEqual([]);
32
- expect(codeChanged).toBe(false);
33
51
  });
34
52
 
35
- test('Ignores other ignored files and folders', async () => {
53
+ test('Ignores other ignored files and folders', () => {
36
54
  const FILES = ['.vscode/', '.gitignore', '.husky/', '.eslintrc', '.editorconfig', '.actor/'];
37
55
 
38
- const { actorsChanged, codeChanged } = await getChangedActors({ actorConfigs: ACTOR_CONFIGS, isLatest: false, filepathsChanged: FILES });
56
+ const actorsChanged = getChangedActors({
57
+ actorConfigs: ACTOR_CONFIGS,
58
+ isLatest: false,
59
+ filepathsChanged: FILES,
60
+ commits,
61
+ });
39
62
 
40
63
  expect(actorsChanged).toEqual([]);
41
- expect(codeChanged).toBe(false);
42
64
  });
43
65
 
44
- test('Only builds latest for all Actors', async () => {
66
+ test('Only builds latest for all Actors', () => {
45
67
  const FILES = ['shared/CHANGELOG.md', 'CHANGELOG.md'];
46
68
 
47
- const { actorsChanged, codeChanged } = await getChangedActors({ actorConfigs: ACTOR_CONFIGS, isLatest: true, filepathsChanged: FILES });
69
+ const actorsChanged = getChangedActors({
70
+ actorConfigs: ACTOR_CONFIGS,
71
+ isLatest: true,
72
+ filepathsChanged: FILES,
73
+ commits,
74
+ });
48
75
 
49
76
  expect(actorsChanged).toEqual(ACTOR_CONFIGS.filter(({ isStandalone }) => !isStandalone));
50
- expect(codeChanged).toBe(false);
51
77
  });
52
78
 
53
- test('Code updated, tests miniactors', async () => {
79
+ test('Code updated, tests miniactors', () => {
54
80
  const FILES = ['code/src/main.ts', 'package.json'];
55
81
 
56
- const { actorsChanged, codeChanged } = await getChangedActors({ actorConfigs: ACTOR_CONFIGS, isLatest: false, filepathsChanged: FILES });
82
+ const actorsChanged = getChangedActors({
83
+ actorConfigs: ACTOR_CONFIGS,
84
+ isLatest: false,
85
+ filepathsChanged: FILES,
86
+ commits,
87
+ });
57
88
 
58
89
  expect(actorsChanged).toEqual(ACTOR_CONFIGS.filter(({ isStandalone }) => !isStandalone));
59
- expect(codeChanged).toBe(true);
60
90
  });
61
91
 
62
- test('Specific Actor functionality configs updated', async () => {
63
- const FILES = ['actors/lukaskrivka_testing-github-integration-1/.actor/actor.json', 'standalone-actors/lukaskrivka_test-standalone/Dockerfile'];
92
+ test('Specific Actor functionality configs updated', () => {
93
+ const FILES = [
94
+ 'actors/lukaskrivka_testing-github-integration-1/.actor/actor.json',
95
+ 'standalone-actors/lukaskrivka_test-standalone/Dockerfile',
96
+ ];
97
+ // Default mock returns false = functional change
64
98
 
65
- const { actorsChanged, codeChanged } = await getChangedActors({ actorConfigs: ACTOR_CONFIGS, isLatest: false, filepathsChanged: FILES });
99
+ const actorsChanged = getChangedActors({
100
+ actorConfigs: ACTOR_CONFIGS,
101
+ isLatest: false,
102
+ filepathsChanged: FILES,
103
+ commits,
104
+ });
66
105
 
67
106
  expect(actorsChanged).toEqual([ACTOR_CONFIGS[0], ACTOR_CONFIGS[2]]);
68
- expect(codeChanged).toBe(false);
69
107
  });
70
108
 
71
- test('src/main.ts updated', async () => {
72
- const FILES = [
73
- 'src/main.ts',
74
- ];
109
+ test('src/main.ts updated', () => {
110
+ const FILES = ['src/main.ts'];
75
111
 
76
- const { actorsChanged, codeChanged } = await getChangedActors({ actorConfigs: ACTOR_CONFIGS, isLatest: true, filepathsChanged: FILES });
112
+ const actorsChanged = getChangedActors({
113
+ actorConfigs: ACTOR_CONFIGS,
114
+ isLatest: true,
115
+ filepathsChanged: FILES,
116
+ commits,
117
+ });
77
118
 
78
119
  expect(actorsChanged).toEqual(ACTOR_CONFIGS.slice(0, 2));
79
- expect(codeChanged).toBe(false);
80
120
  });
81
121
 
82
- test('Miniactor, Code and standalone actor updated,', async () => {
122
+ test('Miniactor, Code and standalone actor updated,', () => {
83
123
  const FILES = [
84
124
  'actors/lukaskrivka_testing-github-integration-1/.actor/actor.json',
85
125
  'code/src/main.ts',
86
126
  'standalone-actors/lukaskrivka_test-standalone/Dockerfile',
87
127
  ];
128
+ // Default mock returns false = functional change for the JSON file
88
129
 
89
- const { actorsChanged, codeChanged } = await getChangedActors({ actorConfigs: ACTOR_CONFIGS, isLatest: false, filepathsChanged: FILES });
130
+ const actorsChanged = getChangedActors({
131
+ actorConfigs: ACTOR_CONFIGS,
132
+ isLatest: false,
133
+ filepathsChanged: FILES,
134
+ commits,
135
+ });
90
136
 
91
137
  expect(actorsChanged).toEqual(ACTOR_CONFIGS);
92
- expect(codeChanged).toBe(true);
93
138
  });
94
139
 
95
- test('Specific Actor non-functional configs updated', async () => {
96
- const FILES = ['actors/lukaskrivka_testing-github-integration-2/.actor/README.md', 'standalone-actors/lukaskrivka_test-standalone/CHANGELOG.md'];
140
+ test('Specific Actor non-functional configs updated', () => {
141
+ const FILES = [
142
+ 'actors/lukaskrivka_testing-github-integration-2/.actor/README.md',
143
+ 'standalone-actors/lukaskrivka_test-standalone/CHANGELOG.md',
144
+ ];
145
+
146
+ const actorsChanged = getChangedActors({
147
+ actorConfigs: ACTOR_CONFIGS,
148
+ isLatest: false,
149
+ filepathsChanged: FILES,
150
+ commits,
151
+ });
152
+
153
+ expect(actorsChanged).toEqual([]);
154
+ });
155
+
156
+ test('JSON file with cosmetic-only changes in PR context (isLatest=false) skips tests', () => {
157
+ const FILES = ['actors/lukaskrivka_testing-github-integration-1/.actor/actor.json'];
158
+ isCosmeticOnlyJsonSchemaSpy.mockReturnValue(true);
159
+
160
+ const actorsChanged = getChangedActors({
161
+ actorConfigs: ACTOR_CONFIGS,
162
+ isLatest: false,
163
+ filepathsChanged: FILES,
164
+ commits,
165
+ });
166
+
167
+ expect(actorsChanged).toEqual([]);
168
+ });
169
+
170
+ test('JSON file with cosmetic-only changes in latest context still triggers build', () => {
171
+ const FILES = ['actors/lukaskrivka_testing-github-integration-1/.actor/actor.json'];
172
+ isCosmeticOnlyJsonSchemaSpy.mockReturnValue(true);
173
+
174
+ const actorsChanged = getChangedActors({
175
+ actorConfigs: ACTOR_CONFIGS,
176
+ isLatest: true,
177
+ filepathsChanged: FILES,
178
+ commits,
179
+ });
180
+
181
+ expect(actorsChanged).toEqual([ACTOR_CONFIGS[0]]);
182
+ });
183
+
184
+ test('JSON file with functional changes triggers tests', () => {
185
+ const FILES = ['actors/lukaskrivka_testing-github-integration-1/.actor/actor.json'];
186
+ // Default mock returns false = functional change
97
187
 
98
- const { actorsChanged, codeChanged } = await getChangedActors({ actorConfigs: ACTOR_CONFIGS, isLatest: false, filepathsChanged: FILES });
188
+ const actorsChanged = getChangedActors({
189
+ actorConfigs: ACTOR_CONFIGS,
190
+ isLatest: false,
191
+ filepathsChanged: FILES,
192
+ commits,
193
+ });
194
+
195
+ expect(actorsChanged).toEqual([ACTOR_CONFIGS[0]]);
196
+ });
197
+
198
+ test('Mix: one actor has cosmetic-only JSON change, another has functional JSON change', () => {
199
+ const FILES = [
200
+ 'actors/lukaskrivka_testing-github-integration-1/.actor/actor.json',
201
+ 'actors/lukaskrivka_testing-github-integration-2/.actor/input_schema.json',
202
+ ];
203
+ // Actor 1 JSON is cosmetic-only, actor 2 JSON is functional
204
+ isCosmeticOnlyJsonSchemaSpy.mockImplementation(
205
+ (_commits, filepath: string) => !filepath.includes('input_schema.json'),
206
+ );
207
+
208
+ const actorsChanged = getChangedActors({
209
+ actorConfigs: ACTOR_CONFIGS,
210
+ isLatest: false,
211
+ filepathsChanged: FILES,
212
+ commits,
213
+ });
214
+
215
+ // Only the second actor (functional change) should be built and tested
216
+ expect(actorsChanged).toEqual([ACTOR_CONFIGS[1]]);
217
+ });
218
+
219
+ test('Standalone actor with cosmetic-only JSON change in PR context skips tests', () => {
220
+ const FILES = ['standalone-actors/lukaskrivka_test-standalone/.actor/actor.json'];
221
+ isCosmeticOnlyJsonSchemaSpy.mockReturnValue(true);
222
+
223
+ const actorsChanged = getChangedActors({
224
+ actorConfigs: ACTOR_CONFIGS,
225
+ isLatest: false,
226
+ filepathsChanged: FILES,
227
+ commits,
228
+ });
99
229
 
100
230
  expect(actorsChanged).toEqual([]);
101
- expect(codeChanged).toBe(false);
102
231
  });
103
232
 
104
- test('Google Maps real user-case that had undefined', async () => {
105
- const FILES = ['actors/compass_Google-Maps-Reviews-Scraper/.actor/INPUT_SCHEMA.json', 'actors/compass_crawler-google-places/.actor/INPUT_SCHEMA.json',
106
- 'code/src/consts.ts', 'code/src/crawlers/cheerio/routes.ts', 'code/src/detail_page_handle.ts', 'code/src/enqueue_places.ts',
107
- 'code/src/helper-classes/initialize-all.ts', 'code/src/helper-classes/stats.ts', 'code/src/helper-classes/unmatched-categories.ts',
108
- 'code/src/main.ts', 'code/src/typedefs/general.ts', 'code/src/utils/background-enqueue.ts'];
233
+ test('Google Maps real user-case that had undefined', () => {
234
+ const FILES = [
235
+ 'actors/compass_Google-Maps-Reviews-Scraper/.actor/INPUT_SCHEMA.json',
236
+ 'actors/compass_crawler-google-places/.actor/INPUT_SCHEMA.json',
237
+ 'code/src/consts.ts',
238
+ 'code/src/crawlers/cheerio/routes.ts',
239
+ 'code/src/detail_page_handle.ts',
240
+ 'code/src/enqueue_places.ts',
241
+ 'code/src/helper-classes/initialize-all.ts',
242
+ 'code/src/helper-classes/stats.ts',
243
+ 'code/src/helper-classes/unmatched-categories.ts',
244
+ 'code/src/main.ts',
245
+ 'code/src/typedefs/general.ts',
246
+ 'code/src/utils/background-enqueue.ts',
247
+ ];
109
248
 
110
249
  const ACTOR_CONFIGS_GOOGLE_MAPS: ActorConfig[] = [
111
250
  {
@@ -156,11 +295,13 @@ describe('Should build and test parser', () => {
156
295
  },
157
296
  ];
158
297
 
159
- const { actorsChanged, codeChanged } = await getChangedActors({
160
- actorConfigs: ACTOR_CONFIGS_GOOGLE_MAPS, isLatest: false, filepathsChanged: FILES,
298
+ const actorsChanged = getChangedActors({
299
+ actorConfigs: ACTOR_CONFIGS_GOOGLE_MAPS,
300
+ isLatest: false,
301
+ filepathsChanged: FILES,
302
+ commits,
161
303
  });
162
304
 
163
305
  expect(actorsChanged).toEqual(ACTOR_CONFIGS_GOOGLE_MAPS.filter(({ isStandalone }) => !isStandalone));
164
- expect(codeChanged).toBe(true);
165
306
  });
166
307
  });
package/bin/consts.ts DELETED
@@ -1,6 +0,0 @@
1
- // Technically, upgrades in shared or packages might not need impact every actor
2
- // but we cannot really know that
3
- export const DEFAULT_BUILD_ALL_FOLDERS = ['code', 'shared', 'packages'];
4
-
5
- export const PERSISTED_GH_JOBS_KVS_ID = 'XIBdO8EJePdD0KiAI';
6
- export const MINIACTORS_LIST_STORE_ID = 'ftXklt2f2mN30Oc3y';
@@ -1,4 +0,0 @@
1
- export declare const DEFAULT_BUILD_ALL_FOLDERS: string[];
2
- export declare const PERSISTED_GH_JOBS_KVS_ID = "XIBdO8EJePdD0KiAI";
3
- export declare const MINIACTORS_LIST_STORE_ID = "ftXklt2f2mN30Oc3y";
4
- //# sourceMappingURL=consts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../bin/consts.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,UAAiC,CAAC;AAExE,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAC5D,eAAO,MAAM,wBAAwB,sBAAsB,CAAC"}
@@ -1,6 +0,0 @@
1
- // Technically, upgrades in shared or packages might not need impact every actor
2
- // but we cannot really know that
3
- export const DEFAULT_BUILD_ALL_FOLDERS = ['code', 'shared', 'packages'];
4
- export const PERSISTED_GH_JOBS_KVS_ID = 'XIBdO8EJePdD0KiAI';
5
- export const MINIACTORS_LIST_STORE_ID = 'ftXklt2f2mN30Oc3y';
6
- //# sourceMappingURL=consts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../bin/consts.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,iCAAiC;AACjC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAC5D,MAAM,CAAC,MAAM,wBAAwB,GAAG,mBAAmB,CAAC"}