apify-test-tools 0.10.2-beta.2 → 0.10.2-beta.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.
Files changed (77) hide show
  1. package/.github/cli/apify-test-tools.mjs +140 -140
  2. package/.github/scripts/run-with-apify-tokens.mjs +1 -1
  3. package/.github/workflows/public_pr-build-test.yaml +25 -25
  4. package/.github/workflows/public_push-build-latest.yaml +20 -4
  5. package/CHANGELOG.md +2 -0
  6. package/README.md +119 -14
  7. package/bin/affected-actors.ts +157 -0
  8. package/bin/build.ts +55 -38
  9. package/bin/diff-changes.ts +25 -17
  10. package/bin/git.ts +44 -44
  11. package/bin/main.ts +132 -106
  12. package/bin/slack.ts +24 -0
  13. package/bin/stdin-input.ts +65 -0
  14. package/dist/bin/affected-actors.d.ts +45 -0
  15. package/dist/bin/affected-actors.d.ts.map +1 -0
  16. package/dist/bin/affected-actors.js +87 -0
  17. package/dist/bin/affected-actors.js.map +1 -0
  18. package/dist/bin/build.d.ts +12 -5
  19. package/dist/bin/build.d.ts.map +1 -1
  20. package/dist/bin/build.js +45 -23
  21. package/dist/bin/build.js.map +1 -1
  22. package/dist/bin/diff-changes.d.ts +8 -2
  23. package/dist/bin/diff-changes.d.ts.map +1 -1
  24. package/dist/bin/diff-changes.js +16 -16
  25. package/dist/bin/diff-changes.js.map +1 -1
  26. package/dist/bin/git.d.ts +19 -14
  27. package/dist/bin/git.d.ts.map +1 -1
  28. package/dist/bin/git.js +37 -35
  29. package/dist/bin/git.js.map +1 -1
  30. package/dist/bin/main.js +110 -86
  31. package/dist/bin/main.js.map +1 -1
  32. package/dist/bin/slack.d.ts +8 -0
  33. package/dist/bin/slack.d.ts.map +1 -1
  34. package/dist/bin/slack.js +18 -0
  35. package/dist/bin/slack.js.map +1 -1
  36. package/dist/bin/stdin-input.d.ts +17 -0
  37. package/dist/bin/stdin-input.d.ts.map +1 -0
  38. package/dist/bin/stdin-input.js +54 -0
  39. package/dist/bin/stdin-input.js.map +1 -0
  40. package/dist/test/bundle/cli-bundle.test.js +36 -6
  41. package/dist/test/bundle/cli-bundle.test.js.map +1 -1
  42. package/dist/test/e2e/cli-bundle.e2e.test.js +16 -9
  43. package/dist/test/e2e/cli-bundle.e2e.test.js.map +1 -1
  44. package/dist/test/unit/bin/affected-actors.test.d.ts +2 -0
  45. package/dist/test/unit/bin/affected-actors.test.d.ts.map +1 -0
  46. package/dist/test/unit/bin/affected-actors.test.js +154 -0
  47. package/dist/test/unit/bin/affected-actors.test.js.map +1 -0
  48. package/dist/test/unit/bin/build-cli.test.d.ts +2 -0
  49. package/dist/test/unit/bin/build-cli.test.d.ts.map +1 -0
  50. package/dist/test/unit/bin/build-cli.test.js +52 -0
  51. package/dist/test/unit/bin/build-cli.test.js.map +1 -0
  52. package/dist/test/unit/bin/build.test.js +61 -4
  53. package/dist/test/unit/bin/build.test.js.map +1 -1
  54. package/dist/test/unit/bin/diff-changes.test.js +78 -49
  55. package/dist/test/unit/bin/diff-changes.test.js.map +1 -1
  56. package/dist/test/unit/bin/git.test.js +39 -54
  57. package/dist/test/unit/bin/git.test.js.map +1 -1
  58. package/dist/test/unit/bin/slack.test.js +39 -1
  59. package/dist/test/unit/bin/slack.test.js.map +1 -1
  60. package/dist/test/unit/bin/stdin-input.test.d.ts +2 -0
  61. package/dist/test/unit/bin/stdin-input.test.d.ts.map +1 -0
  62. package/dist/test/unit/bin/stdin-input.test.js +50 -0
  63. package/dist/test/unit/bin/stdin-input.test.js.map +1 -0
  64. package/dist/test/unit/should-built-and-test.test.js +23 -17
  65. package/dist/test/unit/should-built-and-test.test.js.map +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +1 -1
  68. package/test/bundle/cli-bundle.test.ts +59 -6
  69. package/test/e2e/cli-bundle.e2e.test.ts +26 -11
  70. package/test/unit/bin/affected-actors.test.ts +184 -0
  71. package/test/unit/bin/build-cli.test.ts +61 -0
  72. package/test/unit/bin/build.test.ts +71 -3
  73. package/test/unit/bin/diff-changes.test.ts +87 -49
  74. package/test/unit/bin/git.test.ts +44 -55
  75. package/test/unit/bin/slack.test.ts +44 -1
  76. package/test/unit/bin/stdin-input.test.ts +61 -0
  77. package/test/unit/should-built-and-test.test.ts +27 -17
@@ -0,0 +1,61 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { parseBuildInput, parseReleaseChanges } from '../../../bin/stdin-input.js';
4
+
5
+ describe('parseBuildInput', () => {
6
+ it('reads the Actors', () => {
7
+ expect(parseBuildInput('{"actors":[{"actorFullName":"owner/a"}]}')).toStrictEqual({
8
+ actors: [{ actorFullName: 'owner/a' }],
9
+ });
10
+ });
11
+
12
+ it('ignores the other fields, so whole get-affected-actors fields can be passed along', () => {
13
+ const input = { head: 'f'.repeat(40), ref: 'feature', actors: [{ actorFullName: 'owner/a', extra: 1 }] };
14
+ expect(parseBuildInput(JSON.stringify(input))).toStrictEqual({ actors: [{ actorFullName: 'owner/a' }] });
15
+ });
16
+
17
+ it('accepts an empty list, which builds nothing', () => {
18
+ expect(parseBuildInput('{"actors":[]}')).toStrictEqual({ actors: [] });
19
+ });
20
+
21
+ it('rejects empty input, which is what a failed command earlier in a pipe leaves behind', () => {
22
+ expect(() => parseBuildInput(' \n')).toThrow('Expected the Actors to build as JSON on stdin, got nothing');
23
+ });
24
+
25
+ it('rejects input that is not JSON', () => {
26
+ expect(() => parseBuildInput('owner/a')).toThrow('not valid JSON');
27
+ });
28
+
29
+ it('rejects JSON that is not a list of Actors, e.g. a whole get-affected-actors document', () => {
30
+ expect(() => parseBuildInput('{"functionallyChangedActors":[{"actorFullName":"owner/a"}]}')).toThrow(
31
+ 'is not the Actors to build',
32
+ );
33
+ });
34
+ });
35
+
36
+ describe('parseReleaseChanges', () => {
37
+ const commit = { sha: '1'.repeat(40), author: 'Dev<dev@example.com>', date: 'Date', message: 'feat: foo' };
38
+
39
+ it('reads what changed from a get-affected-actors document, ignoring the rest', () => {
40
+ const document = {
41
+ version: 1,
42
+ ref: 'master',
43
+ head: '1'.repeat(40),
44
+ commits: [commit],
45
+ changedFiles: ['src/main.ts'],
46
+ changelog: '- Added foo',
47
+ functionallyChangedActors: [{ actorFullName: 'owner/a' }],
48
+ cosmeticallyChangedActors: [],
49
+ };
50
+ expect(parseReleaseChanges(JSON.stringify(document))).toStrictEqual({
51
+ commits: [commit],
52
+ changedFiles: ['src/main.ts'],
53
+ changelog: '- Added foo',
54
+ });
55
+ });
56
+
57
+ it('rejects empty input and input that is not a get-affected-actors document', () => {
58
+ expect(() => parseReleaseChanges('')).toThrow('got nothing');
59
+ expect(() => parseReleaseChanges('{"actors":[]}')).toThrow('not the output of get-affected-actors');
60
+ });
61
+ });
@@ -41,6 +41,16 @@ const actorConfig = (
41
41
  };
42
42
  };
43
43
 
44
+ // What a PR (functional changes only) or a release (isLatest, all changes) builds, in config order
45
+ const changedActorsFor = async ({
46
+ isLatest = false,
47
+ ...options
48
+ }: Parameters<typeof getChangedActors>[0] & { isLatest?: boolean }): Promise<ActorConfig[]> => {
49
+ const { functional, cosmetic } = await getChangedActors(options);
50
+ const changed = isLatest ? [...functional, ...cosmetic] : functional;
51
+ return options.actorConfigs.filter((config) => changed.includes(config));
52
+ };
53
+
44
54
  describe('Should build and test parser', () => {
45
55
  // From https://github.com/apify-store/testing-repo-for-github-actions
46
56
  const ACTOR_CONFIGS: ActorConfig[] = [
@@ -70,7 +80,7 @@ describe('Should build and test parser', () => {
70
80
  test('Ignores dev-only readme', async () => {
71
81
  const FILES = ['README.md', 'code/README.md', 'shared/README.md'];
72
82
 
73
- const actorsChanged = await getChangedActors({
83
+ const actorsChanged = await changedActorsFor({
74
84
  actorConfigs: ACTOR_CONFIGS,
75
85
  isLatest: false,
76
86
  filepathsChanged: FILES,
@@ -83,7 +93,7 @@ describe('Should build and test parser', () => {
83
93
  test('Ignores other ignored files and folders', async () => {
84
94
  const FILES = ['.vscode/settings.json', '.gitignore', '.husky/pre-commit', '.eslintrc', '.editorconfig'];
85
95
 
86
- const actorsChanged = await getChangedActors({
96
+ const actorsChanged = await changedActorsFor({
87
97
  actorConfigs: ACTOR_CONFIGS,
88
98
  isLatest: false,
89
99
  filepathsChanged: FILES,
@@ -96,7 +106,7 @@ describe('Should build and test parser', () => {
96
106
  test('.actor/ changes trigger builds for broad-context actors', async () => {
97
107
  const FILES = ['.actor/actor.json'];
98
108
 
99
- const actorsChanged = await getChangedActors({
109
+ const actorsChanged = await changedActorsFor({
100
110
  actorConfigs: ACTOR_CONFIGS,
101
111
  isLatest: false,
102
112
  filepathsChanged: FILES,
@@ -109,7 +119,7 @@ describe('Should build and test parser', () => {
109
119
  test('Configured changelog is cosmetic for every actor, only on latest', async () => {
110
120
  const FILES = ['CHANGELOG.md'];
111
121
 
112
- const actorsChangedNotLatest = await getChangedActors({
122
+ const actorsChangedNotLatest = await changedActorsFor({
113
123
  actorConfigs: ACTOR_CONFIGS,
114
124
  isLatest: false,
115
125
  filepathsChanged: FILES,
@@ -117,7 +127,7 @@ describe('Should build and test parser', () => {
117
127
  });
118
128
  expect(actorsChangedNotLatest).toEqual([]);
119
129
 
120
- const actorsChangedLatest = await getChangedActors({
130
+ const actorsChangedLatest = await changedActorsFor({
121
131
  actorConfigs: ACTOR_CONFIGS,
122
132
  isLatest: true,
123
133
  filepathsChanged: FILES,
@@ -129,7 +139,7 @@ describe('Should build and test parser', () => {
129
139
  test('A changelog nested inside one actor own folder is excluded for sibling actors', async () => {
130
140
  const FILES = ['actors/lukaskrivka_testing-github-integration-1/CHANGELOG.md'];
131
141
 
132
- const actorsChanged = await getChangedActors({
142
+ const actorsChanged = await changedActorsFor({
133
143
  actorConfigs: ACTOR_CONFIGS,
134
144
  isLatest: true,
135
145
  filepathsChanged: FILES,
@@ -142,7 +152,7 @@ describe('Should build and test parser', () => {
142
152
  test('Code updated, tests broad-context actors', async () => {
143
153
  const FILES = ['code/src/main.ts', 'package.json'];
144
154
 
145
- const actorsChanged = await getChangedActors({
155
+ const actorsChanged = await changedActorsFor({
146
156
  actorConfigs: ACTOR_CONFIGS,
147
157
  isLatest: false,
148
158
  filepathsChanged: FILES,
@@ -158,7 +168,7 @@ describe('Should build and test parser', () => {
158
168
  'standalone-actors/lukaskrivka_test-standalone/Dockerfile',
159
169
  ];
160
170
 
161
- const actorsChanged = await getChangedActors({
171
+ const actorsChanged = await changedActorsFor({
162
172
  actorConfigs: ACTOR_CONFIGS,
163
173
  isLatest: false,
164
174
  filepathsChanged: FILES,
@@ -171,7 +181,7 @@ describe('Should build and test parser', () => {
171
181
  test('src/main.ts updated', async () => {
172
182
  const FILES = ['src/main.ts'];
173
183
 
174
- const actorsChanged = await getChangedActors({
184
+ const actorsChanged = await changedActorsFor({
175
185
  actorConfigs: ACTOR_CONFIGS,
176
186
  isLatest: true,
177
187
  filepathsChanged: FILES,
@@ -188,7 +198,7 @@ describe('Should build and test parser', () => {
188
198
  'standalone-actors/lukaskrivka_test-standalone/Dockerfile',
189
199
  ];
190
200
 
191
- const actorsChanged = await getChangedActors({
201
+ const actorsChanged = await changedActorsFor({
192
202
  actorConfigs: ACTOR_CONFIGS,
193
203
  isLatest: false,
194
204
  filepathsChanged: FILES,
@@ -204,7 +214,7 @@ describe('Should build and test parser', () => {
204
214
  'standalone-actors/lukaskrivka_test-standalone/README.md',
205
215
  ];
206
216
 
207
- const actorsChanged = await getChangedActors({
217
+ const actorsChanged = await changedActorsFor({
208
218
  actorConfigs: ACTOR_CONFIGS,
209
219
  isLatest: false,
210
220
  filepathsChanged: FILES,
@@ -217,7 +227,7 @@ describe('Should build and test parser', () => {
217
227
  test('Actor JSON changes in PR context trigger tests', async () => {
218
228
  const FILES = ['actors/lukaskrivka_testing-github-integration-1/.actor/actor.json'];
219
229
 
220
- const actorsChanged = await getChangedActors({
230
+ const actorsChanged = await changedActorsFor({
221
231
  actorConfigs: ACTOR_CONFIGS,
222
232
  isLatest: false,
223
233
  filepathsChanged: FILES,
@@ -230,7 +240,7 @@ describe('Should build and test parser', () => {
230
240
  test('Actor JSON changes in latest context trigger builds', async () => {
231
241
  const FILES = ['actors/lukaskrivka_testing-github-integration-1/.actor/actor.json'];
232
242
 
233
- const actorsChanged = await getChangedActors({
243
+ const actorsChanged = await changedActorsFor({
234
244
  actorConfigs: ACTOR_CONFIGS,
235
245
  isLatest: true,
236
246
  filepathsChanged: FILES,
@@ -243,7 +253,7 @@ describe('Should build and test parser', () => {
243
253
  test('JSON file with functional changes triggers tests', async () => {
244
254
  const FILES = ['actors/lukaskrivka_testing-github-integration-1/.actor/actor.json'];
245
255
 
246
- const actorsChanged = await getChangedActors({
256
+ const actorsChanged = await changedActorsFor({
247
257
  actorConfigs: ACTOR_CONFIGS,
248
258
  isLatest: false,
249
259
  filepathsChanged: FILES,
@@ -259,7 +269,7 @@ describe('Should build and test parser', () => {
259
269
  'actors/lukaskrivka_testing-github-integration-2/.actor/input_schema.json',
260
270
  ];
261
271
 
262
- const actorsChanged = await getChangedActors({
272
+ const actorsChanged = await changedActorsFor({
263
273
  actorConfigs: ACTOR_CONFIGS,
264
274
  isLatest: false,
265
275
  filepathsChanged: FILES,
@@ -272,7 +282,7 @@ describe('Should build and test parser', () => {
272
282
  test('Narrow-context actor JSON change in PR context triggers tests', async () => {
273
283
  const FILES = ['standalone-actors/lukaskrivka_test-standalone/.actor/actor.json'];
274
284
 
275
- const actorsChanged = await getChangedActors({
285
+ const actorsChanged = await changedActorsFor({
276
286
  actorConfigs: ACTOR_CONFIGS,
277
287
  isLatest: false,
278
288
  filepathsChanged: FILES,
@@ -331,7 +341,7 @@ describe('Should build and test parser', () => {
331
341
  ),
332
342
  ];
333
343
 
334
- const actorsChanged = await getChangedActors({
344
+ const actorsChanged = await changedActorsFor({
335
345
  actorConfigs: ACTOR_CONFIGS_GOOGLE_MAPS,
336
346
  isLatest: false,
337
347
  filepathsChanged: FILES,