apify-test-tools 0.6.4-beta.0 → 0.6.4-beta.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.
- package/CHANGELOG.md +16 -0
- package/bin/diff-changes.ts +10 -9
- package/bin/git.ts +5 -45
- package/bin/main.ts +22 -46
- package/dist/bin/diff-changes.d.ts.map +1 -1
- package/dist/bin/diff-changes.js +10 -8
- package/dist/bin/diff-changes.js.map +1 -1
- package/dist/bin/git.d.ts +0 -11
- package/dist/bin/git.d.ts.map +1 -1
- package/dist/bin/git.js +3 -37
- package/dist/bin/git.js.map +1 -1
- package/dist/bin/main.js +22 -33
- package/dist/bin/main.js.map +1 -1
- package/dist/lib/lib.d.ts +4 -1
- package/dist/lib/lib.d.ts.map +1 -1
- package/dist/lib/lib.js +3 -2
- package/dist/lib/lib.js.map +1 -1
- package/dist/test/unit/bin/git.test.js +1 -68
- package/dist/test/unit/bin/git.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/lib.ts +7 -2
- package/package.json +1 -1
- package/test/unit/bin/git.test.ts +1 -87
package/lib/lib.ts
CHANGED
|
@@ -143,9 +143,14 @@ export const it = testActor;
|
|
|
143
143
|
*/
|
|
144
144
|
const createStartStandbyFn = <I, O>(standbyTask: StandbyTask) => {
|
|
145
145
|
const { standbyUrl } = standbyTask;
|
|
146
|
-
return async ({
|
|
147
|
-
|
|
146
|
+
return async ({
|
|
147
|
+
input,
|
|
148
|
+
path = '',
|
|
149
|
+
headers = {},
|
|
150
|
+
}: Pick<RunOptions<I>, 'input'> & { path?: string; headers?: Record<string, string> }) => {
|
|
151
|
+
const response = await fetch(standbyUrl + path, {
|
|
148
152
|
headers: {
|
|
153
|
+
...headers,
|
|
149
154
|
Authorization: `Bearer ${apifyClient.token}`,
|
|
150
155
|
},
|
|
151
156
|
method: 'POST',
|
package/package.json
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { MockInstance } from 'vitest';
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
getBranchOnlyChangedFiles,
|
|
6
|
-
getChangedFiles,
|
|
7
|
-
getCommits,
|
|
8
|
-
hasMergeFromTarget,
|
|
9
|
-
parseBaseCommit,
|
|
10
|
-
} from '../../../bin/git.js';
|
|
4
|
+
import { getChangedFiles, getCommits, parseBaseCommit } from '../../../bin/git.js';
|
|
11
5
|
import * as Utils from '../../../bin/utils.js';
|
|
12
6
|
|
|
13
7
|
describe('getCommits', () => {
|
|
@@ -123,86 +117,6 @@ describe('getChangedFiles', () => {
|
|
|
123
117
|
});
|
|
124
118
|
});
|
|
125
119
|
|
|
126
|
-
describe('hasMergeFromTarget', () => {
|
|
127
|
-
const sourceBranch = 'feature-branch';
|
|
128
|
-
const targetBranch = 'main';
|
|
129
|
-
const mergeSha = 'f'.repeat(40);
|
|
130
|
-
const branchParentSha = 'b'.repeat(40);
|
|
131
|
-
const targetParentSha = 't'.repeat(40);
|
|
132
|
-
|
|
133
|
-
let gitCommandSpy: MockInstance;
|
|
134
|
-
|
|
135
|
-
beforeEach(() => {
|
|
136
|
-
gitCommandSpy = vi.spyOn(Utils, 'spawnCommandInGhWorkspace');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should return false when there are no merge commits on the branch', () => {
|
|
140
|
-
gitCommandSpy.mockImplementation((cmd: string) => {
|
|
141
|
-
if (cmd.includes('--merges')) return '';
|
|
142
|
-
return '';
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
expect(hasMergeFromTarget(sourceBranch, targetBranch)).toBe(false);
|
|
146
|
-
expect(gitCommandSpy).toHaveBeenCalledWith(
|
|
147
|
-
`git log --merges --pretty=format:%H ${targetBranch}..${sourceBranch}`,
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('should return true when a merge commit has a parent reachable from targetBranch', () => {
|
|
152
|
-
gitCommandSpy.mockImplementation((cmd: string) => {
|
|
153
|
-
if (cmd.includes('--merges')) return mergeSha;
|
|
154
|
-
if (cmd.includes('--pretty=format:%P')) return `${branchParentSha} ${targetParentSha}`;
|
|
155
|
-
if (cmd.startsWith(`git merge-base ${branchParentSha}`)) return branchParentSha; // not ancestor
|
|
156
|
-
if (cmd.startsWith(`git merge-base ${targetParentSha}`)) return targetParentSha; // is ancestor
|
|
157
|
-
return '';
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
expect(hasMergeFromTarget(sourceBranch, targetBranch)).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should return false when the merge commit parent is not reachable from targetBranch (unrelated branch merge)', () => {
|
|
164
|
-
const unrelatedSha = 'e'.repeat(40);
|
|
165
|
-
const differentMergeBase = '0'.repeat(40);
|
|
166
|
-
gitCommandSpy.mockImplementation((cmd: string) => {
|
|
167
|
-
if (cmd.includes('--merges')) return mergeSha;
|
|
168
|
-
if (cmd.includes('--pretty=format:%P')) return `${branchParentSha} ${unrelatedSha}`;
|
|
169
|
-
// merge-base returns something other than the parent — not an ancestor
|
|
170
|
-
if (cmd.startsWith('git merge-base')) return differentMergeBase;
|
|
171
|
-
return '';
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
expect(hasMergeFromTarget(sourceBranch, targetBranch)).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('getBranchOnlyChangedFiles', () => {
|
|
179
|
-
const sourceBranch = 'feature-branch';
|
|
180
|
-
const targetBranch = 'main';
|
|
181
|
-
|
|
182
|
-
let gitCommandSpy: MockInstance;
|
|
183
|
-
|
|
184
|
-
beforeEach(() => {
|
|
185
|
-
gitCommandSpy = vi.spyOn(Utils, 'spawnCommandInGhWorkspace');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should return files touched by non-merge commits', () => {
|
|
189
|
-
gitCommandSpy.mockReturnValue('README.md\n\nactors/foo_bar/src/main.ts\n');
|
|
190
|
-
|
|
191
|
-
const result = getBranchOnlyChangedFiles(sourceBranch, targetBranch);
|
|
192
|
-
|
|
193
|
-
expect(result).toStrictEqual(['README.md', 'actors/foo_bar/src/main.ts']);
|
|
194
|
-
expect(gitCommandSpy).toHaveBeenCalledWith(
|
|
195
|
-
`git log --no-merges --name-only --pretty=format: ${targetBranch}..${sourceBranch}`,
|
|
196
|
-
);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('should return empty array when there are no non-merge commits', () => {
|
|
200
|
-
gitCommandSpy.mockReturnValue('');
|
|
201
|
-
|
|
202
|
-
expect(getBranchOnlyChangedFiles(sourceBranch, targetBranch)).toStrictEqual([]);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
120
|
const VALID_SHA = 'a'.repeat(40);
|
|
207
121
|
const VALID_JSON = JSON.stringify({ sha: VALID_SHA, author: 'test', date: 'now', message: 'msg' });
|
|
208
122
|
|