apify-test-tools 0.5.0 → 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/.prettierrc +5 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +10 -0
- package/bin/git.ts +24 -44
- package/bin/github.ts +5 -14
- package/bin/main.ts +38 -38
- package/bin/slack.ts +13 -16
- package/dist/bin/git.d.ts +9 -4
- package/dist/bin/git.d.ts.map +1 -1
- package/dist/bin/git.js +15 -36
- package/dist/bin/git.js.map +1 -1
- package/dist/bin/github.d.ts +1 -1
- package/dist/bin/github.d.ts.map +1 -1
- package/dist/bin/github.js +3 -9
- package/dist/bin/github.js.map +1 -1
- package/dist/bin/main.js +5 -7
- package/dist/bin/main.js.map +1 -1
- package/dist/bin/slack.d.ts +2 -2
- package/dist/bin/slack.d.ts.map +1 -1
- package/dist/bin/slack.js +4 -2
- package/dist/bin/slack.js.map +1 -1
- package/dist/lib/consts.d.ts +1 -1
- package/dist/lib/consts.d.ts.map +1 -1
- package/dist/lib/consts.js +1 -4
- package/dist/lib/consts.js.map +1 -1
- package/dist/lib/extend-expect.d.ts.map +1 -1
- package/dist/lib/extend-expect.js +11 -2
- package/dist/lib/extend-expect.js.map +1 -1
- package/dist/lib/lib.d.ts +1 -1
- package/dist/lib/lib.d.ts.map +1 -1
- package/dist/lib/lib.js +12 -9
- 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 +1 -0
- package/dist/lib/run-test-result.js.map +1 -1
- package/dist/lib/types.d.ts +2 -0
- package/dist/lib/types.d.ts.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/test/unit/custom-matchers.test.js +2 -2
- package/dist/test/unit/custom-matchers.test.js.map +1 -1
- package/dist/test/unit/parse-commit.test.js +5 -5
- package/dist/test/unit/parse-commit.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/consts.ts +2 -5
- package/lib/extend-expect.ts +38 -25
- package/lib/lib.ts +31 -42
- package/lib/run-test-result.ts +9 -10
- package/lib/types.ts +69 -68
- package/package.json +4 -1
- package/test/unit/bin/git.test.ts +109 -0
- package/test/unit/custom-matchers.test.ts +6 -9
- package/test/unit/parse-commit.test.ts +6 -7
- package/tsconfig.json +4 -8
- package/test/unit/test-actor.test.ts +0 -17
|
@@ -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
|
+
});
|
|
@@ -2,13 +2,10 @@ import process from 'process';
|
|
|
2
2
|
import { describe } from 'vitest';
|
|
3
3
|
|
|
4
4
|
import { ApifyClient } from 'apify-client';
|
|
5
|
-
import { testStandbyActor, testTestActor } from '../../lib/lib';
|
|
6
|
-
import { RunTestResult } from '../../lib/run-test-result';
|
|
5
|
+
import { testStandbyActor, testTestActor } from '../../lib/lib.js';
|
|
6
|
+
import { RunTestResult } from '../../lib/run-test-result.js';
|
|
7
7
|
|
|
8
|
-
type PpeEventType =
|
|
9
|
-
| 'actor-start'
|
|
10
|
-
| 'search-page-scraped'
|
|
11
|
-
| 'ads-scraped'
|
|
8
|
+
type PpeEventType = 'actor-start' | 'search-page-scraped' | 'ads-scraped';
|
|
12
9
|
enum PpeEventEnum {
|
|
13
10
|
ACTOR_START = 'actor-start',
|
|
14
11
|
SEARCH_PAGE_SCRAPED = 'search-page-scraped',
|
|
@@ -45,7 +42,7 @@ describe('custom-matchers', { timeout: 100_000 }, () => {
|
|
|
45
42
|
},
|
|
46
43
|
});
|
|
47
44
|
|
|
48
|
-
await expect(runResult).toFinishWith<typeof PPE_EVENT_CONST[keyof typeof PPE_EVENT_CONST]>({
|
|
45
|
+
await expect(runResult).toFinishWith<(typeof PPE_EVENT_CONST)[keyof typeof PPE_EVENT_CONST]>({
|
|
49
46
|
datasetItemCount: { min: 1, max: 20 },
|
|
50
47
|
chargedEventCounts: {
|
|
51
48
|
'actor-start': 1,
|
|
@@ -67,7 +64,7 @@ describe('custom-matchers', { timeout: 100_000 }, () => {
|
|
|
67
64
|
maxRequests: 3,
|
|
68
65
|
aggregateContacts: true,
|
|
69
66
|
},
|
|
70
|
-
})
|
|
67
|
+
});
|
|
71
68
|
expect(status).toBe(200);
|
|
72
69
|
expect(data[0].domain).toEqual('apify.com');
|
|
73
70
|
}
|
|
@@ -78,7 +75,7 @@ describe('custom-matchers', { timeout: 100_000 }, () => {
|
|
|
78
75
|
maxRequests: 3,
|
|
79
76
|
aggregateContacts: true,
|
|
80
77
|
},
|
|
81
|
-
})
|
|
78
|
+
});
|
|
82
79
|
expect(status).toBe(200);
|
|
83
80
|
expect(data[0].domain).toEqual('apify.com');
|
|
84
81
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { GIT_FORMAT_SEPARATOR, parseCommit } from '../../bin/git';
|
|
2
|
+
import { GIT_FORMAT_SEPARATOR, parseCommit } from '../../bin/git.js';
|
|
3
3
|
|
|
4
4
|
describe('parseCommit', () => {
|
|
5
|
-
|
|
6
5
|
describe('valid commit strings', () => {
|
|
7
6
|
it('should parse a basic commit string correctly', () => {
|
|
8
7
|
const commitString = `abc123${GIT_FORMAT_SEPARATOR}John Doe<john@example.com>${GIT_FORMAT_SEPARATOR}Mon, 25 Dec 2023 10:30:00 +0100${GIT_FORMAT_SEPARATOR}Add new feature`;
|
|
@@ -13,7 +12,7 @@ describe('parseCommit', () => {
|
|
|
13
12
|
sha: 'abc123',
|
|
14
13
|
author: 'John Doe<john@example.com>',
|
|
15
14
|
date: 'Mon, 25 Dec 2023 10:30:00 +0100',
|
|
16
|
-
message: 'Add new feature'
|
|
15
|
+
message: 'Add new feature',
|
|
17
16
|
});
|
|
18
17
|
});
|
|
19
18
|
|
|
@@ -26,7 +25,7 @@ describe('parseCommit', () => {
|
|
|
26
25
|
sha: 'def456',
|
|
27
26
|
author: 'Jane Smith<jane@example.com>',
|
|
28
27
|
date: 'Tue, 26 Dec 2023 14:15:00 +0100',
|
|
29
|
-
message: 'test: commit with double quotes:
|
|
28
|
+
message: 'test: commit with double quotes: "',
|
|
30
29
|
});
|
|
31
30
|
});
|
|
32
31
|
|
|
@@ -39,7 +38,7 @@ describe('parseCommit', () => {
|
|
|
39
38
|
sha: 'jkl012',
|
|
40
39
|
author: 'María García<maria@example.com>',
|
|
41
40
|
date: 'Thu, 28 Dec 2023 16:20:00 +0100',
|
|
42
|
-
message: 'Add émojis 🚀 and "special" chars'
|
|
41
|
+
message: 'Add émojis 🚀 and "special" chars',
|
|
43
42
|
});
|
|
44
43
|
});
|
|
45
44
|
|
|
@@ -52,7 +51,7 @@ describe('parseCommit', () => {
|
|
|
52
51
|
sha: 'mno345',
|
|
53
52
|
author: 'Test User<test@example.com>',
|
|
54
53
|
date: 'Fri, 29 Dec 2023 11:00:00 +0100',
|
|
55
|
-
message: ''
|
|
54
|
+
message: '',
|
|
56
55
|
});
|
|
57
56
|
});
|
|
58
57
|
});
|
|
@@ -70,4 +69,4 @@ describe('parseCommit', () => {
|
|
|
70
69
|
expect(() => parseCommit(commitString)).toThrow(`Failed to parse commit string: ${commitString}`);
|
|
71
70
|
});
|
|
72
71
|
});
|
|
73
|
-
});
|
|
72
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -2,19 +2,15 @@
|
|
|
2
2
|
"extends": "@apify/tsconfig",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"declaration": true,
|
|
5
|
-
"module": "
|
|
5
|
+
"module": "nodenext",
|
|
6
|
+
"moduleResolution": "nodenext",
|
|
6
7
|
"target": "ES2022",
|
|
7
8
|
"outDir": "dist",
|
|
8
9
|
"noUnusedLocals": false,
|
|
9
10
|
"strict": true,
|
|
10
11
|
"esModuleInterop": true,
|
|
11
12
|
"lib": ["DOM", "es2021"],
|
|
12
|
-
"skipLibCheck": true
|
|
13
|
+
"skipLibCheck": true
|
|
13
14
|
},
|
|
14
|
-
"include": [
|
|
15
|
-
"./index.ts",
|
|
16
|
-
"./bin/**/*",
|
|
17
|
-
"./lib/**/*",
|
|
18
|
-
"./test/**/*",
|
|
19
|
-
]
|
|
15
|
+
"include": ["./index.ts", "./bin/**/*", "./lib/**/*", "./test/**/*"]
|
|
20
16
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, testActor } from '../../lib/lib';
|
|
2
|
-
|
|
3
|
-
describe('testActor tests', async () => {
|
|
4
|
-
testActor('compass/google-maps-extractor', 'basic', async ({ expect, run }) => {
|
|
5
|
-
const runResult = await run({
|
|
6
|
-
input: {},
|
|
7
|
-
prefilledInput: true,
|
|
8
|
-
options: {
|
|
9
|
-
memory: 512,
|
|
10
|
-
},
|
|
11
|
-
})
|
|
12
|
-
const input = await runResult.getInput<{ maxCrawledPlacesPerSearch: number }>();
|
|
13
|
-
await expect(runResult).toFinishWith({
|
|
14
|
-
datasetItemCount: input.maxCrawledPlacesPerSearch,
|
|
15
|
-
})
|
|
16
|
-
});
|
|
17
|
-
});
|