apify-test-tools 0.5.7-beta.5 → 0.5.7-beta.7

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.
@@ -291,7 +291,6 @@ const isWithinInterval = <T extends string>(
291
291
  diffs.pass = false;
292
292
  diffs.actual.push(`${intervalOption}=${actual}`);
293
293
  diffs.expected.push(`${intervalOption}=${expected}`);
294
- // eslint-disable-next-line consistent-return
295
294
  return false;
296
295
  }
297
296
  } else if (typeof expected === 'object') {
@@ -301,7 +300,6 @@ const isWithinInterval = <T extends string>(
301
300
  diffs.pass = false;
302
301
  diffs.actual.push(`${intervalOption}=${actual}`);
303
302
  diffs.expected.push(`${intervalOption}=<${min ?? ''},${max ?? ''}>`);
304
- // eslint-disable-next-line consistent-return
305
303
  return false;
306
304
  }
307
305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-test-tools",
3
- "version": "0.5.7-beta.5",
3
+ "version": "0.5.7-beta.7",
4
4
  "type": "module",
5
5
  "description": "TBD",
6
6
  "repository": {
@@ -1,16 +1,20 @@
1
1
  import type { MockInstance } from 'vitest';
2
2
  import { beforeEach, describe, expect, it, vi } from 'vitest';
3
3
 
4
- import { getChangedFiles, getCommits } from '../../../bin/git.js';
4
+ import { getChangedFiles, getCommits, parseBaseCommit } from '../../../bin/git.js';
5
5
  import * as Utils from '../../../bin/utils.js';
6
6
 
7
7
  describe('getCommits', () => {
8
8
  const sourceBranch = 'feature-branch';
9
9
  const targetBranch = 'main';
10
10
 
11
- const commit1 = 'Commit1»¦«Author1»¦«Date1»¦«First Change On Feature';
12
- const commit2 = 'Commit2»¦«Author1»¦«Date2»¦«Second Change On Feature';
13
- const commit3 = 'Commit3»¦«Author1»¦«Date3»¦«Third Change On Feature';
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`;
14
18
 
15
19
  let gitCommandSpy: MockInstance;
16
20
 
@@ -26,9 +30,9 @@ describe('getCommits', () => {
26
30
 
27
31
  // Assert
28
32
  expect(commits).toStrictEqual([
29
- { sha: 'Commit1', author: 'Author1', date: 'Date1', message: 'First Change On Feature' },
30
- { sha: 'Commit2', author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
31
- { sha: 'Commit3', author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
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' },
32
36
  ]);
33
37
 
34
38
  expect(gitCommandSpy).toHaveBeenCalledTimes(1);
@@ -39,12 +43,12 @@ describe('getCommits', () => {
39
43
 
40
44
  it('should return commits after the base commit if provided', () => {
41
45
  // Act
42
- const commits = getCommits({ sourceBranch, targetBranch, baseCommit: 'Commit1' });
46
+ const commits = getCommits({ sourceBranch, targetBranch, baseCommit: sha1 });
43
47
 
44
48
  // Assert
45
49
  expect(commits).toStrictEqual([
46
- { sha: 'Commit2', author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
47
- { sha: 'Commit3', author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
50
+ { sha: sha2, author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
51
+ { sha: sha3, author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
48
52
  ]);
49
53
 
50
54
  expect(gitCommandSpy).toHaveBeenCalledTimes(1);
@@ -55,13 +59,13 @@ describe('getCommits', () => {
55
59
 
56
60
  it('should return all commits if base commit is not found', () => {
57
61
  // Act
58
- const commits = getCommits({ sourceBranch, targetBranch, baseCommit: 'NonExistingCommit' });
62
+ const commits = getCommits({ sourceBranch, targetBranch, baseCommit: 'a'.repeat(40) });
59
63
 
60
64
  // Assert
61
65
  expect(commits).toStrictEqual([
62
- { sha: 'Commit1', author: 'Author1', date: 'Date1', message: 'First Change On Feature' },
63
- { sha: 'Commit2', author: 'Author1', date: 'Date2', message: 'Second Change On Feature' },
64
- { sha: 'Commit3', author: 'Author1', date: 'Date3', message: 'Third Change On Feature' },
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' },
65
69
  ]);
66
70
 
67
71
  expect(gitCommandSpy).toHaveBeenCalledTimes(1);
@@ -80,9 +84,11 @@ describe('getChangedFiles', () => {
80
84
 
81
85
  it('should return changed files between commits', () => {
82
86
  // Arrange
87
+ const firstSha = '1'.repeat(40);
88
+ const lastSha = '3'.repeat(40);
83
89
  const commits = [
84
- { sha: 'Commit1', author: '', date: '', message: '' },
85
- { sha: 'Commit3', author: '', date: '', message: '' },
90
+ { sha: firstSha, author: '', date: '', message: '' },
91
+ { sha: lastSha, author: '', date: '', message: '' },
86
92
  ];
87
93
 
88
94
  // Act
@@ -92,12 +98,13 @@ describe('getChangedFiles', () => {
92
98
  expect(changedFiles).toStrictEqual(['file1.txt', 'folder/file2.txt']);
93
99
 
94
100
  expect(gitCommandSpy).toHaveBeenCalledTimes(1);
95
- expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only Commit1~..Commit3`);
101
+ expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only ${firstSha}~..${lastSha}`);
96
102
  });
97
103
 
98
104
  it('should handle only one commit', () => {
99
105
  // Arrange
100
- const commits = [{ sha: 'Commit1', author: '', date: '', message: '' }];
106
+ const onlySha = '1'.repeat(40);
107
+ const commits = [{ sha: onlySha, author: '', date: '', message: '' }];
101
108
 
102
109
  // Act
103
110
  const changedFiles = getChangedFiles(commits);
@@ -106,6 +113,36 @@ describe('getChangedFiles', () => {
106
113
  expect(changedFiles).toStrictEqual(['file1.txt', 'folder/file2.txt']);
107
114
 
108
115
  expect(gitCommandSpy).toHaveBeenCalledTimes(1);
109
- expect(gitCommandSpy).toHaveBeenCalledWith(`git diff --name-only Commit1~..Commit1`);
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');
110
147
  });
111
148
  });