apify-test-tools 0.5.1 → 0.5.2
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 +5 -0
- package/bin/git.ts +19 -34
- package/dist/bin/git.d.ts +7 -2
- package/dist/bin/git.d.ts.map +1 -1
- package/dist/bin/git.js +14 -32
- package/dist/bin/git.js.map +1 -1
- package/dist/lib/lib.js +2 -2
- package/dist/lib/lib.js.map +1 -1
- package/dist/test/unit/bin/git.test.d.ts +2 -0
- package/dist/test/unit/bin/git.test.d.ts.map +1 -0
- package/dist/test/unit/bin/git.test.js +81 -0
- package/dist/test/unit/bin/git.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/lib.ts +2 -2
- package/package.json +1 -1
- package/test/unit/bin/git.test.ts +109 -0
package/lib/lib.ts
CHANGED
|
@@ -111,7 +111,7 @@ export const testStandbyActor = <I = any, O = any>(
|
|
|
111
111
|
const runs = (await apifyClient.task(taskId).runs().list()).items;
|
|
112
112
|
for (const run of runs) {
|
|
113
113
|
const runLink = generateRunLink(run);
|
|
114
|
-
await annotate(runLink
|
|
114
|
+
await annotate(`${name} - ${runLink}`, 'run_link');
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
if (taskId) {
|
|
@@ -253,7 +253,7 @@ const createStartRunFn = <T>(actorNameOrId: string, testContext: TestContext) =>
|
|
|
253
253
|
const run = await actor.call(actorInput, { build, ...options });
|
|
254
254
|
|
|
255
255
|
const runLink = generateRunLink(run);
|
|
256
|
-
await annotate(runLink
|
|
256
|
+
await annotate(`${task.name} - ${runLink}`, 'run_link');
|
|
257
257
|
// @ts-expect-error: `TaskMeta` cannot be retyped
|
|
258
258
|
task.meta = {
|
|
259
259
|
runId: run.id,
|
package/package.json
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, MockInstance, vi } from 'vitest';
|
|
2
|
+
import { getChangedFiles, getCommits } from '../../../bin/git.js';
|
|
3
|
+
import * as Utils from '../../../bin/utils.js';
|
|
4
|
+
|
|
5
|
+
describe('getCommits', () => {
|
|
6
|
+
const sourceBranch = 'feature-branch';
|
|
7
|
+
const targetBranch = 'main';
|
|
8
|
+
|
|
9
|
+
const commit1 = 'Commit1»¦«Author1»¦«Date1»¦«First Change On Feature';
|
|
10
|
+
const commit2 = 'Commit2»¦«Author1»¦«Date2»¦«Second Change On Feature';
|
|
11
|
+
const commit3 = 'Commit3»¦«Author1»¦«Date3»¦«Third Change On Feature';
|
|
12
|
+
|
|
13
|
+
let gitCommandSpy: MockInstance;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
gitCommandSpy = vi
|
|
17
|
+
.spyOn(Utils, 'spawnCommandInGhWorkspace')
|
|
18
|
+
.mockReturnValue(`${commit3}\n${commit2}\n${commit1}`);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should return commits between source and target branches', () => {
|
|
22
|
+
// Act
|
|
23
|
+
const commits = getCommits({ sourceBranch, targetBranch });
|
|
24
|
+
|
|
25
|
+
// Assert
|
|
26
|
+
expect(commits).toStrictEqual([
|
|
27
|
+
{ sha: 'Commit1', author: 'Author1', date: 'Date1', message: 'First Change On Feature' },
|
|
28
|
+
{ sha: 'Commit2', author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
|
|
29
|
+
{ sha: 'Commit3', author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
33
|
+
expect(gitCommandSpy).toHaveBeenCalledWith(
|
|
34
|
+
`git log --pretty=format:'%H»¦«%aN<%aE>»¦«%aD»¦«%s' main..feature-branch`,
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return commits after the base commit if provided', () => {
|
|
39
|
+
// Act
|
|
40
|
+
const commits = getCommits({ sourceBranch, targetBranch, baseCommit: 'Commit1' });
|
|
41
|
+
|
|
42
|
+
// Assert
|
|
43
|
+
expect(commits).toStrictEqual([
|
|
44
|
+
{ sha: 'Commit2', author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
|
|
45
|
+
{ sha: 'Commit3', author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(gitCommandSpy).toHaveBeenCalledWith(
|
|
50
|
+
`git log --pretty=format:'%H»¦«%aN<%aE>»¦«%aD»¦«%s' main..feature-branch`,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should return all commits if base commit is not found', () => {
|
|
55
|
+
// Act
|
|
56
|
+
const commits = getCommits({ sourceBranch, targetBranch, baseCommit: 'NonExistingCommit' });
|
|
57
|
+
|
|
58
|
+
// Assert
|
|
59
|
+
expect(commits).toStrictEqual([
|
|
60
|
+
{ sha: 'Commit1', author: 'Author1', date: 'Date1', message: 'First Change On Feature' },
|
|
61
|
+
{ sha: 'Commit2', author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
|
|
62
|
+
{ sha: 'Commit3', author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
66
|
+
expect(gitCommandSpy).toHaveBeenCalledWith(
|
|
67
|
+
`git log --pretty=format:'%H»¦«%aN<%aE>»¦«%aD»¦«%s' main..feature-branch`,
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('getChangedFiles', () => {
|
|
73
|
+
let gitCommandSpy: MockInstance;
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
gitCommandSpy = vi.spyOn(Utils, 'spawnCommandInGhWorkspace').mockReturnValue('file1.txt\nfolder/file2.txt');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should return changed files between commits', () => {
|
|
80
|
+
// Arrange
|
|
81
|
+
const commits = [
|
|
82
|
+
{ sha: 'Commit1', author: '', date: '', message: '' },
|
|
83
|
+
{ sha: 'Commit3', author: '', date: '', message: '' },
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
// Act
|
|
87
|
+
const changedFiles = getChangedFiles(commits);
|
|
88
|
+
|
|
89
|
+
// Assert
|
|
90
|
+
expect(changedFiles).toStrictEqual(['file1.txt', 'folder/file2.txt']);
|
|
91
|
+
|
|
92
|
+
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only Commit1~..Commit3`);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should handle only one commit', () => {
|
|
97
|
+
// Arrange
|
|
98
|
+
const commits = [{ sha: 'Commit1', author: '', date: '', message: '' }];
|
|
99
|
+
|
|
100
|
+
// Act
|
|
101
|
+
const changedFiles = getChangedFiles(commits);
|
|
102
|
+
|
|
103
|
+
// Assert
|
|
104
|
+
expect(changedFiles).toStrictEqual(['file1.txt', 'folder/file2.txt']);
|
|
105
|
+
|
|
106
|
+
expect(gitCommandSpy).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only Commit1~..Commit1`);
|
|
108
|
+
});
|
|
109
|
+
});
|