apify-test-tools 0.6.0 → 0.6.2-beta.0
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.
- package/.github/workflows/_check_code.yaml +17 -19
- package/.github/workflows/_update_release_metadata.yaml +1 -1
- package/.github/workflows/manual_release_stable.yaml +1 -0
- package/.github/workflows/on_master.yaml +2 -0
- package/.husky/pre-commit +13 -0
- package/CHANGELOG.md +17 -3
- package/CONTRIBUTING.md +5 -0
- package/README.md +39 -43
- package/bin/build.ts +138 -87
- package/bin/diff-changes.ts +156 -0
- package/bin/diff-json-schema.ts +50 -0
- package/bin/git.ts +42 -11
- package/bin/github.ts +7 -6
- package/bin/main.ts +31 -13
- package/bin/slack.ts +6 -2
- package/bin/test-report.ts +55 -44
- package/bin/types.ts +56 -59
- package/bin/utils.ts +19 -131
- package/dist/bin/build.d.ts +1 -1
- package/dist/bin/build.d.ts.map +1 -1
- package/dist/bin/build.js +49 -31
- package/dist/bin/build.js.map +1 -1
- package/dist/bin/diff-changes.d.ts +16 -0
- package/dist/bin/diff-changes.d.ts.map +1 -0
- package/dist/bin/diff-changes.js +103 -0
- package/dist/bin/diff-changes.js.map +1 -0
- package/dist/bin/diff-json-schema.d.ts +7 -0
- package/dist/bin/diff-json-schema.d.ts.map +1 -0
- package/dist/bin/diff-json-schema.js +45 -0
- package/dist/bin/diff-json-schema.js.map +1 -0
- package/dist/bin/git.d.ts +8 -3
- package/dist/bin/git.d.ts.map +1 -1
- package/dist/bin/git.js +35 -10
- package/dist/bin/git.js.map +1 -1
- package/dist/bin/github.d.ts +1 -3
- package/dist/bin/github.d.ts.map +1 -1
- package/dist/bin/github.js +5 -5
- package/dist/bin/github.js.map +1 -1
- package/dist/bin/main.js +19 -7
- package/dist/bin/main.js.map +1 -1
- package/dist/bin/slack.d.ts +1 -1
- package/dist/bin/slack.d.ts.map +1 -1
- package/dist/bin/slack.js +1 -1
- package/dist/bin/slack.js.map +1 -1
- package/dist/bin/test-report.d.ts.map +1 -1
- package/dist/bin/test-report.js +9 -3
- package/dist/bin/test-report.js.map +1 -1
- package/dist/bin/types.d.ts +0 -1
- package/dist/bin/types.d.ts.map +1 -1
- package/dist/bin/utils.d.ts +0 -14
- package/dist/bin/utils.d.ts.map +1 -1
- package/dist/bin/utils.js +12 -95
- package/dist/bin/utils.js.map +1 -1
- package/dist/lib/extend-expect.d.ts.map +1 -1
- package/dist/lib/extend-expect.js +11 -11
- package/dist/lib/extend-expect.js.map +1 -1
- package/dist/lib/lib.d.ts +3 -2
- package/dist/lib/lib.d.ts.map +1 -1
- package/dist/lib/lib.js +7 -3
- package/dist/lib/lib.js.map +1 -1
- package/dist/lib/run-test-result.d.ts +1 -1
- package/dist/lib/run-test-result.d.ts.map +1 -1
- package/dist/lib/run-test-result.js.map +1 -1
- package/dist/lib/types.d.ts +2 -3
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +4 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/test/unit/bin/diff-changes.test.d.ts +2 -0
- package/dist/test/unit/bin/diff-changes.test.d.ts.map +1 -0
- package/dist/test/unit/bin/diff-changes.test.js +159 -0
- package/dist/test/unit/bin/diff-changes.test.js.map +1 -0
- package/dist/test/unit/bin/diff.test.d.ts +2 -0
- package/dist/test/unit/bin/diff.test.d.ts.map +1 -0
- package/dist/test/unit/bin/diff.test.js +143 -0
- package/dist/test/unit/bin/diff.test.js.map +1 -0
- package/dist/test/unit/bin/git.test.js +48 -19
- package/dist/test/unit/bin/git.test.js.map +1 -1
- package/dist/test/unit/custom-matchers.test.js +3 -8
- package/dist/test/unit/custom-matchers.test.js.map +1 -1
- package/dist/test/unit/parse-commit.test.js +1 -1
- package/dist/test/unit/parse-commit.test.js.map +1 -1
- package/dist/test/unit/should-built-and-test.test.js +159 -39
- package/dist/test/unit/should-built-and-test.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.mjs +4 -2
- package/knip.json +1 -1
- package/lib/extend-expect.ts +21 -21
- package/lib/lib.ts +17 -17
- package/lib/run-test-result.ts +6 -2
- package/lib/types.ts +5 -8
- package/lib/utils.ts +13 -9
- package/package.json +61 -54
- package/test/tsconfig.json +2 -4
- package/test/unit/bin/diff-changes.test.ts +182 -0
- package/test/unit/bin/diff.test.ts +212 -0
- package/test/unit/bin/git.test.ts +59 -20
- package/test/unit/custom-matchers.test.ts +10 -9
- package/test/unit/parse-commit.test.ts +2 -1
- package/test/unit/should-built-and-test.test.ts +181 -40
- package/bin/consts.ts +0 -6
- package/dist/bin/consts.d.ts +0 -4
- package/dist/bin/consts.d.ts.map +0 -1
- package/dist/bin/consts.js +0 -6
- package/dist/bin/consts.js.map +0 -1
- package/example-github-events/pull-request.json +0 -523
- package/example-github-events/push.json +0 -216
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { MockInstance } from 'vitest';
|
|
2
|
+
import { beforeEach, describe, expect, it, test, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { isCosmeticOnlyJsonSchemaChange } from '../../../bin/diff-json-schema.js';
|
|
5
|
+
import * as Utils from '../../../bin/utils.js';
|
|
6
|
+
|
|
7
|
+
const commits = [
|
|
8
|
+
{ sha: 'Commit1', author: '', date: '', message: '' },
|
|
9
|
+
{ sha: 'Commit3', author: '', date: '', message: '' },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
describe('isCosmeticOnlyJsonSchemaChange', () => {
|
|
13
|
+
let gitCommandSpy: MockInstance;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
gitCommandSpy = vi.spyOn(Utils, 'spawnCommandInGhWorkspace');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const mockGitCalls = (oldJson: string, newJson: string) => {
|
|
20
|
+
gitCommandSpy.mockReturnValueOnce(oldJson).mockReturnValueOnce(newJson);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
test('returns true when nothing changed', () => {
|
|
24
|
+
const json = JSON.stringify({ type: 'string', title: 'My field' });
|
|
25
|
+
mockGitCalls(json, json);
|
|
26
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('returns true when only title changes', () => {
|
|
30
|
+
mockGitCalls(
|
|
31
|
+
JSON.stringify({ type: 'string', title: 'Old title' }),
|
|
32
|
+
JSON.stringify({ type: 'string', title: 'New title' }),
|
|
33
|
+
);
|
|
34
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('returns true when only description changes', () => {
|
|
38
|
+
mockGitCalls(
|
|
39
|
+
JSON.stringify({ type: 'string', description: 'Old desc' }),
|
|
40
|
+
JSON.stringify({ type: 'string', description: 'New desc' }),
|
|
41
|
+
);
|
|
42
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('returns true when only example changes', () => {
|
|
46
|
+
mockGitCalls(
|
|
47
|
+
JSON.stringify({ type: 'string', example: 'foo' }),
|
|
48
|
+
JSON.stringify({ type: 'string', example: 'bar' }),
|
|
49
|
+
);
|
|
50
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('returns true when only enumTitles changes', () => {
|
|
54
|
+
mockGitCalls(
|
|
55
|
+
JSON.stringify({ type: 'string', enum: ['a', 'b'], enumTitles: ['Option A', 'Option B'] }),
|
|
56
|
+
JSON.stringify({ type: 'string', enum: ['a', 'b'], enumTitles: ['Choice A', 'Choice B'] }),
|
|
57
|
+
);
|
|
58
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('returns true when only sectionCaption changes', () => {
|
|
62
|
+
mockGitCalls(
|
|
63
|
+
JSON.stringify({ sectionCaption: 'Old caption' }),
|
|
64
|
+
JSON.stringify({ sectionCaption: 'New caption' }),
|
|
65
|
+
);
|
|
66
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('returns true when only sectionDescription changes', () => {
|
|
70
|
+
mockGitCalls(JSON.stringify({ sectionDescription: 'Old' }), JSON.stringify({ sectionDescription: 'New' }));
|
|
71
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('returns false when a functional field (type) changes', () => {
|
|
75
|
+
mockGitCalls(
|
|
76
|
+
JSON.stringify({ type: 'string', title: 'My field' }),
|
|
77
|
+
JSON.stringify({ type: 'integer', title: 'My field' }),
|
|
78
|
+
);
|
|
79
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('returns false when a functional field is added', () => {
|
|
83
|
+
mockGitCalls(JSON.stringify({ title: 'My field' }), JSON.stringify({ title: 'My field', type: 'string' }));
|
|
84
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('returns false when a functional field is removed', () => {
|
|
88
|
+
mockGitCalls(JSON.stringify({ type: 'string', title: 'My field' }), JSON.stringify({ title: 'My field' }));
|
|
89
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('returns true when non-functional fields change at nested level (input schema properties)', () => {
|
|
93
|
+
mockGitCalls(
|
|
94
|
+
JSON.stringify({
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
myField: { type: 'string', title: 'Old title', description: 'Old desc', example: 'old' },
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
JSON.stringify({
|
|
101
|
+
type: 'object',
|
|
102
|
+
properties: {
|
|
103
|
+
myField: { type: 'string', title: 'New title', description: 'New desc', example: 'new' },
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('returns false when a functional nested field changes alongside non-functional ones', () => {
|
|
111
|
+
mockGitCalls(
|
|
112
|
+
JSON.stringify({
|
|
113
|
+
type: 'object',
|
|
114
|
+
properties: { myField: { type: 'string', title: 'Old title' } },
|
|
115
|
+
}),
|
|
116
|
+
JSON.stringify({
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: { myField: { type: 'integer', title: 'New title' } },
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('returns false when a new property is added to input schema', () => {
|
|
125
|
+
mockGitCalls(
|
|
126
|
+
JSON.stringify({ properties: { fieldA: { type: 'string' } } }),
|
|
127
|
+
JSON.stringify({ properties: { fieldA: { type: 'string' }, fieldB: { type: 'integer' } } }),
|
|
128
|
+
);
|
|
129
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('returns false when a property is removed from input schema', () => {
|
|
133
|
+
mockGitCalls(
|
|
134
|
+
JSON.stringify({ properties: { fieldA: { type: 'string' }, fieldB: { type: 'integer' } } }),
|
|
135
|
+
JSON.stringify({ properties: { fieldA: { type: 'string' } } }),
|
|
136
|
+
);
|
|
137
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('returns false when invalid JSON in old content', () => {
|
|
141
|
+
mockGitCalls('not json', '{}');
|
|
142
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('returns false when invalid JSON in new content', () => {
|
|
146
|
+
mockGitCalls('{}', 'not json');
|
|
147
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('returns false when array content changes (not under a non-functional key)', () => {
|
|
151
|
+
mockGitCalls(JSON.stringify({ enum: [1, 2, 3] }), JSON.stringify({ enum: [1, 2, 4] }));
|
|
152
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('returns true when example array changes (non-functional key)', () => {
|
|
156
|
+
mockGitCalls(
|
|
157
|
+
JSON.stringify({ type: 'array', example: [1, 2, 3] }),
|
|
158
|
+
JSON.stringify({ type: 'array', example: [4, 5, 6] }),
|
|
159
|
+
);
|
|
160
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('returns true for a realistic actor.json with only title/description change', () => {
|
|
164
|
+
mockGitCalls(
|
|
165
|
+
JSON.stringify({
|
|
166
|
+
actorSpecification: 1,
|
|
167
|
+
name: 'my-actor',
|
|
168
|
+
title: 'Old Title',
|
|
169
|
+
description: 'Old description',
|
|
170
|
+
version: '1.0',
|
|
171
|
+
}),
|
|
172
|
+
JSON.stringify({
|
|
173
|
+
actorSpecification: 1,
|
|
174
|
+
name: 'my-actor',
|
|
175
|
+
title: 'New Title',
|
|
176
|
+
description: 'New description',
|
|
177
|
+
version: '1.0',
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('returns true when fields under properties are reordered', () => {
|
|
184
|
+
mockGitCalls(
|
|
185
|
+
JSON.stringify({
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: { fieldA: { type: 'string' }, fieldB: { type: 'integer' }, fieldC: { type: 'boolean' } },
|
|
188
|
+
}),
|
|
189
|
+
JSON.stringify({
|
|
190
|
+
type: 'object',
|
|
191
|
+
properties: { fieldC: { type: 'boolean' }, fieldA: { type: 'string' }, fieldB: { type: 'integer' } },
|
|
192
|
+
}),
|
|
193
|
+
);
|
|
194
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('returns false for a realistic actor.json with version change', () => {
|
|
198
|
+
mockGitCalls(
|
|
199
|
+
JSON.stringify({ actorSpecification: 1, name: 'my-actor', title: 'My Actor', version: '1.0' }),
|
|
200
|
+
JSON.stringify({ actorSpecification: 1, name: 'my-actor', title: 'My Actor', version: '1.1' }),
|
|
201
|
+
);
|
|
202
|
+
expect(isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json')).toBe(false);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('uses correct git refs: first-commit parent for old, last commit for new', () => {
|
|
206
|
+
const json = JSON.stringify({});
|
|
207
|
+
mockGitCalls(json, json);
|
|
208
|
+
isCosmeticOnlyJsonSchemaChange(commits, 'actors/foo/actor.json');
|
|
209
|
+
expect(gitCommandSpy).toHaveBeenCalledWith('git show Commit1~:actors/foo/actor.json');
|
|
210
|
+
expect(gitCommandSpy).toHaveBeenCalledWith('git show Commit3:actors/foo/actor.json');
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { MockInstance } from 'vitest';
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { getChangedFiles, getCommits, parseBaseCommit } from '../../../bin/git.js';
|
|
3
5
|
import * as Utils from '../../../bin/utils.js';
|
|
4
6
|
|
|
5
7
|
describe('getCommits', () => {
|
|
6
8
|
const sourceBranch = 'feature-branch';
|
|
7
9
|
const targetBranch = 'main';
|
|
8
10
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
11
|
+
const sha1 = '1'.repeat(40);
|
|
12
|
+
const sha2 = '2'.repeat(40);
|
|
13
|
+
const sha3 = '3'.repeat(40);
|
|
14
|
+
|
|
15
|
+
const commit1 = `${sha1}»¦«Author1»¦«Date1»¦«First Change On Feature`;
|
|
16
|
+
const commit2 = `${sha2}»¦«Author1»¦«Date2»¦«Second Change On Feature`;
|
|
17
|
+
const commit3 = `${sha3}»¦«Author1»¦«Date3»¦«Third Change On Feature`;
|
|
12
18
|
|
|
13
19
|
let gitCommandSpy: MockInstance;
|
|
14
20
|
|
|
@@ -24,9 +30,9 @@ describe('getCommits', () => {
|
|
|
24
30
|
|
|
25
31
|
// Assert
|
|
26
32
|
expect(commits).toStrictEqual([
|
|
27
|
-
{ sha:
|
|
28
|
-
{ sha:
|
|
29
|
-
{ sha:
|
|
33
|
+
{ sha: sha1, author: 'Author1', date: 'Date1', message: 'First Change On Feature' },
|
|
34
|
+
{ sha: sha2, author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
|
|
35
|
+
{ sha: sha3, author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
|
|
30
36
|
]);
|
|
31
37
|
|
|
32
38
|
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
@@ -37,12 +43,12 @@ describe('getCommits', () => {
|
|
|
37
43
|
|
|
38
44
|
it('should return commits after the base commit if provided', () => {
|
|
39
45
|
// Act
|
|
40
|
-
const commits = getCommits({ sourceBranch, targetBranch, baseCommit:
|
|
46
|
+
const commits = getCommits({ sourceBranch, targetBranch, baseCommit: sha1 });
|
|
41
47
|
|
|
42
48
|
// Assert
|
|
43
49
|
expect(commits).toStrictEqual([
|
|
44
|
-
{ sha:
|
|
45
|
-
{ sha:
|
|
50
|
+
{ sha: sha2, author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
|
|
51
|
+
{ sha: sha3, author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
|
|
46
52
|
]);
|
|
47
53
|
|
|
48
54
|
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
@@ -53,13 +59,13 @@ describe('getCommits', () => {
|
|
|
53
59
|
|
|
54
60
|
it('should return all commits if base commit is not found', () => {
|
|
55
61
|
// Act
|
|
56
|
-
const commits = getCommits({ sourceBranch, targetBranch, baseCommit: '
|
|
62
|
+
const commits = getCommits({ sourceBranch, targetBranch, baseCommit: 'a'.repeat(40) });
|
|
57
63
|
|
|
58
64
|
// Assert
|
|
59
65
|
expect(commits).toStrictEqual([
|
|
60
|
-
{ sha:
|
|
61
|
-
{ sha:
|
|
62
|
-
{ sha:
|
|
66
|
+
{ sha: sha1, author: 'Author1', date: 'Date1', message: 'First Change On Feature' },
|
|
67
|
+
{ sha: sha2, author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
|
|
68
|
+
{ sha: sha3, author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
|
|
63
69
|
]);
|
|
64
70
|
|
|
65
71
|
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
@@ -78,9 +84,11 @@ describe('getChangedFiles', () => {
|
|
|
78
84
|
|
|
79
85
|
it('should return changed files between commits', () => {
|
|
80
86
|
// Arrange
|
|
87
|
+
const firstSha = '1'.repeat(40);
|
|
88
|
+
const lastSha = '3'.repeat(40);
|
|
81
89
|
const commits = [
|
|
82
|
-
{ sha:
|
|
83
|
-
{ sha:
|
|
90
|
+
{ sha: firstSha, author: '', date: '', message: '' },
|
|
91
|
+
{ sha: lastSha, author: '', date: '', message: '' },
|
|
84
92
|
];
|
|
85
93
|
|
|
86
94
|
// Act
|
|
@@ -90,12 +98,13 @@ describe('getChangedFiles', () => {
|
|
|
90
98
|
expect(changedFiles).toStrictEqual(['file1.txt', 'folder/file2.txt']);
|
|
91
99
|
|
|
92
100
|
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
93
|
-
expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only
|
|
101
|
+
expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only ${firstSha}~..${lastSha}`);
|
|
94
102
|
});
|
|
95
103
|
|
|
96
104
|
it('should handle only one commit', () => {
|
|
97
105
|
// Arrange
|
|
98
|
-
const
|
|
106
|
+
const onlySha = '1'.repeat(40);
|
|
107
|
+
const commits = [{ sha: onlySha, author: '', date: '', message: '' }];
|
|
99
108
|
|
|
100
109
|
// Act
|
|
101
110
|
const changedFiles = getChangedFiles(commits);
|
|
@@ -104,6 +113,36 @@ describe('getChangedFiles', () => {
|
|
|
104
113
|
expect(changedFiles).toStrictEqual(['file1.txt', 'folder/file2.txt']);
|
|
105
114
|
|
|
106
115
|
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
107
|
-
expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only
|
|
116
|
+
expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only ${onlySha}~..${onlySha}`);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const VALID_SHA = 'a'.repeat(40);
|
|
121
|
+
const VALID_JSON = JSON.stringify({ sha: VALID_SHA, author: 'test', date: 'now', message: 'msg' });
|
|
122
|
+
|
|
123
|
+
describe('parseBaseCommit', () => {
|
|
124
|
+
it('should return undefined for undefined input', () => {
|
|
125
|
+
expect(parseBaseCommit(undefined)).toBeUndefined();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should return undefined for empty string', () => {
|
|
129
|
+
expect(parseBaseCommit('')).toBeUndefined();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should accept a plain SHA string', () => {
|
|
133
|
+
expect(parseBaseCommit(VALID_SHA)).toBe(VALID_SHA);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should extract sha from a JSON commit object', () => {
|
|
137
|
+
expect(parseBaseCommit(VALID_JSON)).toBe(VALID_SHA);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should throw on an invalid SHA string', () => {
|
|
141
|
+
expect(() => parseBaseCommit('not-a-sha')).toThrow('Invalid base commit SHA');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should throw when JSON contains an invalid sha field', () => {
|
|
145
|
+
const badJson = JSON.stringify({ sha: 'bad', author: 'test', date: 'now', message: 'msg' });
|
|
146
|
+
expect(() => parseBaseCommit(badJson)).toThrow('Invalid base commit SHA');
|
|
108
147
|
});
|
|
109
148
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import process from 'process';
|
|
2
|
-
import { describe } from 'vitest';
|
|
1
|
+
import process from 'node:process';
|
|
3
2
|
|
|
4
3
|
import { ApifyClient } from 'apify-client';
|
|
4
|
+
import { describe } from 'vitest';
|
|
5
|
+
|
|
5
6
|
import { testStandbyActor, testTestActor } from '../../lib/lib.js';
|
|
6
7
|
import { RunTestResult } from '../../lib/run-test-result.js';
|
|
7
8
|
|
|
@@ -11,13 +12,13 @@ enum PpeEventEnum {
|
|
|
11
12
|
SEARCH_PAGE_SCRAPED = 'search-page-scraped',
|
|
12
13
|
ADS_SCRAPED = 'ads-scraped',
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
ACTOR_START: 'actor-start'
|
|
16
|
-
ITEM_PUSHED: 'search-page-scraped'
|
|
17
|
-
ADS_SCRAPED: 'ads-scraped'
|
|
18
|
-
}
|
|
15
|
+
type PPE_EVENT_CONST = {
|
|
16
|
+
ACTOR_START: 'actor-start';
|
|
17
|
+
ITEM_PUSHED: 'search-page-scraped';
|
|
18
|
+
ADS_SCRAPED: 'ads-scraped';
|
|
19
|
+
};
|
|
19
20
|
|
|
20
|
-
// TODO: Remake these tests. k5MNKmaDGHlABDn2I run doesn't exist and we probably don't want to depend on fixed run
|
|
21
|
+
// TODO: Remake these tests. k5MNKmaDGHlABDn2I run doesn't exist and we probably don't want to depend on fixed run
|
|
21
22
|
describe.skip('custom-matchers', { timeout: 100_000 }, () => {
|
|
22
23
|
testTestActor('basic', async ({ expect }) => {
|
|
23
24
|
const apifyClient = new ApifyClient({ token: process.env.TESTER_APIFY_TOKEN });
|
|
@@ -43,7 +44,7 @@ describe.skip('custom-matchers', { timeout: 100_000 }, () => {
|
|
|
43
44
|
},
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
await expect(runResult).toFinishWith<
|
|
47
|
+
await expect(runResult).toFinishWith<PPE_EVENT_CONST[keyof PPE_EVENT_CONST]>({
|
|
47
48
|
datasetItemCount: { min: 1, max: 20 },
|
|
48
49
|
chargedEventCounts: {
|
|
49
50
|
'actor-start': 1,
|