apify-test-tools 0.10.2-beta.13 → 0.10.2-beta.14

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.
Files changed (113) hide show
  1. package/.github/cli/apify-test-tools.mjs +123 -128
  2. package/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml +1 -1
  3. package/.github/workflows/public_platform-tests.yaml +36 -22
  4. package/.github/workflows/public_pr-build-test.yaml +7 -6
  5. package/.github/workflows/public_push-build-latest.yaml +6 -4
  6. package/CHANGELOG.md +2 -0
  7. package/CONTRIBUTING.md +8 -6
  8. package/README.md +10 -11
  9. package/bin/actor-ids.ts +38 -0
  10. package/bin/build.ts +1 -1
  11. package/bin/git.ts +20 -92
  12. package/bin/main.ts +87 -73
  13. package/bin/notify.ts +198 -0
  14. package/bin/run-tests.ts +141 -0
  15. package/bin/slack.ts +16 -87
  16. package/bin/stdin-input.ts +98 -7
  17. package/bin/test-report.ts +141 -140
  18. package/bin/types.ts +0 -9
  19. package/dist/bin/actor-ids.d.ts +16 -0
  20. package/dist/bin/actor-ids.d.ts.map +1 -0
  21. package/dist/bin/actor-ids.js +24 -0
  22. package/dist/bin/actor-ids.js.map +1 -0
  23. package/dist/bin/build.js +1 -1
  24. package/dist/bin/build.js.map +1 -1
  25. package/dist/bin/git.d.ts +6 -16
  26. package/dist/bin/git.d.ts.map +1 -1
  27. package/dist/bin/git.js +15 -75
  28. package/dist/bin/git.js.map +1 -1
  29. package/dist/bin/main.js +80 -51
  30. package/dist/bin/main.js.map +1 -1
  31. package/dist/bin/notify.d.ts +35 -0
  32. package/dist/bin/notify.d.ts.map +1 -0
  33. package/dist/bin/notify.js +131 -0
  34. package/dist/bin/notify.js.map +1 -0
  35. package/dist/bin/run-tests.d.ts +21 -0
  36. package/dist/bin/run-tests.d.ts.map +1 -0
  37. package/dist/bin/run-tests.js +116 -0
  38. package/dist/bin/run-tests.js.map +1 -0
  39. package/dist/bin/slack.d.ts +2 -17
  40. package/dist/bin/slack.d.ts.map +1 -1
  41. package/dist/bin/slack.js +17 -58
  42. package/dist/bin/slack.js.map +1 -1
  43. package/dist/bin/stdin-input.d.ts +71 -9
  44. package/dist/bin/stdin-input.d.ts.map +1 -1
  45. package/dist/bin/stdin-input.js +76 -6
  46. package/dist/bin/stdin-input.js.map +1 -1
  47. package/dist/bin/test-report.d.ts +69 -8
  48. package/dist/bin/test-report.d.ts.map +1 -1
  49. package/dist/bin/test-report.js +76 -67
  50. package/dist/bin/test-report.js.map +1 -1
  51. package/dist/bin/types.d.ts +0 -8
  52. package/dist/bin/types.d.ts.map +1 -1
  53. package/dist/lib/lib.d.ts +0 -3
  54. package/dist/lib/lib.d.ts.map +1 -1
  55. package/dist/lib/lib.js +5 -10
  56. package/dist/lib/lib.js.map +1 -1
  57. package/dist/test/bundle/cli-bundle.test.js +40 -48
  58. package/dist/test/bundle/cli-bundle.test.js.map +1 -1
  59. package/dist/test/e2e/cli-bundle.e2e.test.js +15 -16
  60. package/dist/test/e2e/cli-bundle.e2e.test.js.map +1 -1
  61. package/dist/test/e2e/git-build-release.e2e.test.js +2 -2
  62. package/dist/test/e2e/git-build-release.e2e.test.js.map +1 -1
  63. package/dist/test/unit/bin/actor-ids.test.d.ts +2 -0
  64. package/dist/test/unit/bin/actor-ids.test.d.ts.map +1 -0
  65. package/dist/test/unit/bin/actor-ids.test.js +32 -0
  66. package/dist/test/unit/bin/actor-ids.test.js.map +1 -0
  67. package/dist/test/unit/bin/build-cli.test.js +8 -3
  68. package/dist/test/unit/bin/build-cli.test.js.map +1 -1
  69. package/dist/test/unit/bin/diff-changes.test.js +1 -1
  70. package/dist/test/unit/bin/diff-changes.test.js.map +1 -1
  71. package/dist/test/unit/bin/git.test.js +4 -142
  72. package/dist/test/unit/bin/git.test.js.map +1 -1
  73. package/dist/test/unit/bin/notify.test.d.ts +2 -0
  74. package/dist/test/unit/bin/notify.test.d.ts.map +1 -0
  75. package/dist/test/unit/bin/notify.test.js +222 -0
  76. package/dist/test/unit/bin/notify.test.js.map +1 -0
  77. package/dist/test/unit/bin/stdin-input.test.js +51 -9
  78. package/dist/test/unit/bin/stdin-input.test.js.map +1 -1
  79. package/dist/test/unit/bin/test-cli.test.d.ts +2 -0
  80. package/dist/test/unit/bin/test-cli.test.d.ts.map +1 -0
  81. package/dist/test/unit/bin/test-cli.test.js +115 -0
  82. package/dist/test/unit/bin/test-cli.test.js.map +1 -0
  83. package/dist/test/unit/bin/test-report.test.d.ts +2 -0
  84. package/dist/test/unit/bin/test-report.test.d.ts.map +1 -0
  85. package/dist/test/unit/bin/test-report.test.js +100 -0
  86. package/dist/test/unit/bin/test-report.test.js.map +1 -0
  87. package/dist/tsconfig.tsbuildinfo +1 -1
  88. package/docs/cli.md +131 -53
  89. package/docs/lib.md +21 -16
  90. package/docs/workflows.md +24 -23
  91. package/lib/lib.ts +5 -10
  92. package/package.json +1 -1
  93. package/test/bundle/cli-bundle.test.ts +47 -60
  94. package/test/e2e/cli-bundle.e2e.test.ts +18 -25
  95. package/test/e2e/git-build-release.e2e.test.ts +2 -2
  96. package/test/unit/bin/actor-ids.test.ts +43 -0
  97. package/test/unit/bin/build-cli.test.ts +9 -3
  98. package/test/unit/bin/diff-changes.test.ts +1 -1
  99. package/test/unit/bin/git.test.ts +3 -197
  100. package/test/unit/bin/notify.test.ts +299 -0
  101. package/test/unit/bin/stdin-input.test.ts +68 -9
  102. package/test/unit/bin/test-cli.test.ts +137 -0
  103. package/test/unit/bin/test-report.test.ts +118 -0
  104. package/dist/test/unit/bin/logging.test.d.ts +0 -2
  105. package/dist/test/unit/bin/logging.test.d.ts.map +0 -1
  106. package/dist/test/unit/bin/logging.test.js +0 -37
  107. package/dist/test/unit/bin/logging.test.js.map +0 -1
  108. package/dist/test/unit/bin/slack.test.d.ts +0 -2
  109. package/dist/test/unit/bin/slack.test.d.ts.map +0 -1
  110. package/dist/test/unit/bin/slack.test.js +0 -71
  111. package/dist/test/unit/bin/slack.test.js.map +0 -1
  112. package/test/unit/bin/logging.test.ts +0 -48
  113. package/test/unit/bin/slack.test.ts +0 -84
@@ -1,37 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { chmod, mkdtemp, rm, writeFile } from 'node:fs/promises';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import process from 'node:process';
6
- import { afterAll, beforeAll, describe, expect, it } from 'vitest';
7
- import { compileCli } from './compiled-cli.js';
8
- let cliPath;
9
- let cleanup;
10
- let gitStubDir;
11
- const sha = '1'.repeat(40);
12
- describe('CLI logging', () => {
13
- beforeAll(async () => {
14
- ({ cliPath, cleanup } = await compileCli());
15
- gitStubDir = await mkdtemp(path.join(os.tmpdir(), 'apify-cli-logging-'));
16
- const gitStub = path.join(gitStubDir, 'git');
17
- await writeFile(gitStub, `#!/bin/sh\nprintf '%s' '${sha}»¦«Test<test@example.com>»¦«Tue, 06 Oct 2026 00:00:00 +0000»¦«feature'\n`);
18
- await chmod(gitStub, 0o755);
19
- });
20
- afterAll(async () => {
21
- await cleanup?.();
22
- if (gitStubDir)
23
- await rm(gitStubDir, { recursive: true, force: true });
24
- });
25
- it.each(['info', 'silent'])('keeps JSON results intact with --log-level %s', (level) => {
26
- const result = spawnSync(cliPath, ['get-commits', '--source-branch', 'feature', '--target-branch', 'base', '--log-level', level], {
27
- encoding: 'utf8',
28
- stdio: ['ignore', 'pipe', 'pipe'],
29
- env: { ...process.env, PATH: `${gitStubDir}${path.delimiter}${process.env.PATH ?? ''}` },
30
- });
31
- expect(result.status, result.stderr).toBe(0);
32
- expect(result.stderr).toEqual(level === 'silent' ? '' : expect.stringContaining('Commits being returned:'));
33
- expect(JSON.parse(result.stdout)).toMatchObject([{ sha, date: expect.any(String), message: 'feature' }]);
34
- expect(result.stdout.endsWith('\n')).toBe(true);
35
- });
36
- });
37
- //# sourceMappingURL=logging.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logging.test.js","sourceRoot":"","sources":["../../../../test/unit/bin/logging.test.ts"],"names":[],"mappings":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- export {};
2
- //# sourceMappingURL=slack.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slack.test.d.ts","sourceRoot":"","sources":["../../../../test/unit/bin/slack.test.ts"],"names":[],"mappings":""}
@@ -1,71 +0,0 @@
1
- import { WebClient } from '@slack/web-api';
2
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
- import { notifyToSlack } from '../../../bin/slack.js';
4
- vi.mock('@slack/web-api', () => ({ WebClient: vi.fn() }));
5
- const TOKEN_ENV_VAR = 'SLACK_TOKEN_RELEASES_BOT';
6
- const postMessage = vi.fn();
7
- const authTest = vi.fn();
8
- const notify = async (overrides = {}) => notifyToSlack({
9
- repoUrl: 'git@github.com:owner/repo',
10
- changedFiles: ['src/main.ts'],
11
- changelog: '- Fixed a bug',
12
- commits: [{ sha: '1', author: 'Test<test@example.com>', date: '', message: 'fix: bug' }],
13
- dryRun: true,
14
- releaseSlackChannel: '#releases',
15
- reportSlackChannel: '#notif',
16
- ...overrides,
17
- });
18
- describe('notifyToSlack', () => {
19
- beforeEach(() => {
20
- vi.stubEnv(TOKEN_ENV_VAR, 'token');
21
- vi.mocked(WebClient).mockImplementation(function () {
22
- return { chat: { postMessage }, auth: { test: authTest } };
23
- });
24
- });
25
- afterEach(() => {
26
- vi.unstubAllEnvs();
27
- vi.clearAllMocks();
28
- });
29
- it('should verify the token but post nothing in a dry run', async () => {
30
- await notify();
31
- expect(authTest).toHaveBeenCalledTimes(1);
32
- expect(postMessage).not.toHaveBeenCalled();
33
- });
34
- it('should still require the token in a dry run', async () => {
35
- vi.stubEnv(TOKEN_ENV_VAR, '');
36
- await expect(notify()).rejects.toThrow(`${TOKEN_ENV_VAR} not defined`);
37
- });
38
- it('should fail a dry run when Slack rejects the token', async () => {
39
- authTest.mockRejectedValueOnce(new Error('An API error occurred: invalid_auth'));
40
- await expect(notify()).rejects.toThrow(`${TOKEN_ENV_VAR} was rejected by Slack`);
41
- });
42
- it('should not need a token when no channel is passed', async () => {
43
- vi.stubEnv(TOKEN_ENV_VAR, '');
44
- await notify({ dryRun: false, releaseSlackChannel: undefined, reportSlackChannel: undefined });
45
- expect(WebClient).not.toHaveBeenCalled();
46
- });
47
- it('should post to both channels outside of a dry run', async () => {
48
- await notify({ dryRun: false });
49
- expect(authTest).not.toHaveBeenCalled();
50
- expect(postMessage).toHaveBeenCalledTimes(2);
51
- });
52
- it('should announce nothing, and need no token, when there are no new commits', async () => {
53
- vi.stubEnv(TOKEN_ENV_VAR, '');
54
- await notify({ commits: [], dryRun: false });
55
- expect(WebClient).not.toHaveBeenCalled();
56
- });
57
- it('should announce the release by the author of the newest commit, named after the repository', async () => {
58
- const commit = (author, message) => ({ sha: '1', author, date: '', message });
59
- await notify({
60
- commits: [commit('Old<old@example.com>', 'fix: older'), commit('New<new@example.com>', 'feat: newer')],
61
- repoUrl: 'git@github.com:owner/my-repo',
62
- dryRun: false,
63
- releaseSlackChannel: undefined,
64
- });
65
- expect(postMessage).toHaveBeenCalledWith({
66
- channel: '#notif',
67
- text: expect.stringContaining('*my-repo* – New release (by New)'),
68
- });
69
- });
70
- });
71
- //# sourceMappingURL=slack.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slack.test.js","sourceRoot":"","sources":["../../../../test/unit/bin/slack.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAE1D,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,WAAW,GAAG,EAAE,CAA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E,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7C,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4FAA4F,EAAE,KAAK,IAAI,EAAE;QACxG,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9F,MAAM,MAAM,CAAC;YACT,OAAO,EAAE,CAAC,MAAM,CAAC,sBAAsB,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC;YACtG,OAAO,EAAE,8BAA8B;YACvC,MAAM,EAAE,KAAK;YACb,mBAAmB,EAAE,SAAS;SACjC,CAAC,CAAC;QACH,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;YACrC,OAAO,EAAE,QAAQ;YACjB,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,kCAAkC,CAAC;SACpE,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,48 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { chmod, mkdtemp, rm, writeFile } from 'node:fs/promises';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import process from 'node:process';
6
-
7
- import { afterAll, beforeAll, describe, expect, it } from 'vitest';
8
-
9
- import { compileCli } from './compiled-cli.js';
10
-
11
- let cliPath: string;
12
- let cleanup: (() => Promise<void>) | undefined;
13
- let gitStubDir: string | undefined;
14
- const sha = '1'.repeat(40);
15
-
16
- describe('CLI logging', () => {
17
- beforeAll(async () => {
18
- ({ cliPath, cleanup } = await compileCli());
19
- gitStubDir = await mkdtemp(path.join(os.tmpdir(), 'apify-cli-logging-'));
20
- const gitStub = path.join(gitStubDir, 'git');
21
- await writeFile(
22
- gitStub,
23
- `#!/bin/sh\nprintf '%s' '${sha}»¦«Test<test@example.com>»¦«Tue, 06 Oct 2026 00:00:00 +0000»¦«feature'\n`,
24
- );
25
- await chmod(gitStub, 0o755);
26
- });
27
-
28
- afterAll(async () => {
29
- await cleanup?.();
30
- if (gitStubDir) await rm(gitStubDir, { recursive: true, force: true });
31
- });
32
-
33
- it.each(['info', 'silent'])('keeps JSON results intact with --log-level %s', (level) => {
34
- const result = spawnSync(
35
- cliPath,
36
- ['get-commits', '--source-branch', 'feature', '--target-branch', 'base', '--log-level', level],
37
- {
38
- encoding: 'utf8',
39
- stdio: ['ignore', 'pipe', 'pipe'],
40
- env: { ...process.env, PATH: `${gitStubDir}${path.delimiter}${process.env.PATH ?? ''}` },
41
- },
42
- );
43
- expect(result.status, result.stderr).toBe(0);
44
- expect(result.stderr).toEqual(level === 'silent' ? '' : expect.stringContaining('Commits being returned:'));
45
- expect(JSON.parse(result.stdout)).toMatchObject([{ sha, date: expect.any(String), message: 'feature' }]);
46
- expect(result.stdout.endsWith('\n')).toBe(true);
47
- });
48
- });
@@ -1,84 +0,0 @@
1
- import { WebClient } from '@slack/web-api';
2
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
-
4
- import { notifyToSlack } from '../../../bin/slack.js';
5
-
6
- vi.mock('@slack/web-api', () => ({ WebClient: vi.fn() }));
7
-
8
- const TOKEN_ENV_VAR = 'SLACK_TOKEN_RELEASES_BOT';
9
- const postMessage = vi.fn();
10
- const authTest = vi.fn();
11
-
12
- const notify = async (overrides: Partial<Parameters<typeof notifyToSlack>[0]> = {}) =>
13
- notifyToSlack({
14
- repoUrl: 'git@github.com:owner/repo',
15
- changedFiles: ['src/main.ts'],
16
- changelog: '- Fixed a bug',
17
- commits: [{ sha: '1', author: 'Test<test@example.com>', date: '', message: 'fix: bug' }],
18
- dryRun: true,
19
- releaseSlackChannel: '#releases',
20
- reportSlackChannel: '#notif',
21
- ...overrides,
22
- });
23
-
24
- describe('notifyToSlack', () => {
25
- beforeEach(() => {
26
- vi.stubEnv(TOKEN_ENV_VAR, 'token');
27
- vi.mocked(WebClient).mockImplementation(function () {
28
- return { chat: { postMessage }, auth: { test: authTest } };
29
- } as never);
30
- });
31
-
32
- afterEach(() => {
33
- vi.unstubAllEnvs();
34
- vi.clearAllMocks();
35
- });
36
-
37
- it('should verify the token but post nothing in a dry run', async () => {
38
- await notify();
39
- expect(authTest).toHaveBeenCalledTimes(1);
40
- expect(postMessage).not.toHaveBeenCalled();
41
- });
42
-
43
- it('should still require the token in a dry run', async () => {
44
- vi.stubEnv(TOKEN_ENV_VAR, '');
45
- await expect(notify()).rejects.toThrow(`${TOKEN_ENV_VAR} not defined`);
46
- });
47
-
48
- it('should fail a dry run when Slack rejects the token', async () => {
49
- authTest.mockRejectedValueOnce(new Error('An API error occurred: invalid_auth'));
50
- await expect(notify()).rejects.toThrow(`${TOKEN_ENV_VAR} was rejected by Slack`);
51
- });
52
-
53
- it('should not need a token when no channel is passed', async () => {
54
- vi.stubEnv(TOKEN_ENV_VAR, '');
55
- await notify({ dryRun: false, releaseSlackChannel: undefined, reportSlackChannel: undefined });
56
- expect(WebClient).not.toHaveBeenCalled();
57
- });
58
-
59
- it('should post to both channels outside of a dry run', async () => {
60
- await notify({ dryRun: false });
61
- expect(authTest).not.toHaveBeenCalled();
62
- expect(postMessage).toHaveBeenCalledTimes(2);
63
- });
64
-
65
- it('should announce nothing, and need no token, when there are no new commits', async () => {
66
- vi.stubEnv(TOKEN_ENV_VAR, '');
67
- await notify({ commits: [], dryRun: false });
68
- expect(WebClient).not.toHaveBeenCalled();
69
- });
70
-
71
- it('should announce the release by the author of the newest commit, named after the repository', async () => {
72
- const commit = (author: string, message: string) => ({ sha: '1', author, date: '', message });
73
- await notify({
74
- commits: [commit('Old<old@example.com>', 'fix: older'), commit('New<new@example.com>', 'feat: newer')],
75
- repoUrl: 'git@github.com:owner/my-repo',
76
- dryRun: false,
77
- releaseSlackChannel: undefined,
78
- });
79
- expect(postMessage).toHaveBeenCalledWith({
80
- channel: '#notif',
81
- text: expect.stringContaining('*my-repo* – New release (by New)'),
82
- });
83
- });
84
- });