apify-test-tools 0.10.1-beta.5 → 0.10.1-beta.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-test-tools",
3
- "version": "0.10.1-beta.5",
3
+ "version": "0.10.1-beta.6",
4
4
  "type": "module",
5
5
  "description": "TBD",
6
6
  "repository": {
@@ -1,5 +1,3 @@
1
- import type * as ChildProcessModule from 'node:child_process';
2
- import { spawnSync } from 'node:child_process';
3
1
  import fs from 'node:fs/promises';
4
2
  import os from 'node:os';
5
3
  import path from 'node:path';
@@ -17,20 +15,8 @@ import {
17
15
  } from '../../../bin/build-from-local.js';
18
16
  import * as Utils from '../../../bin/utils.js';
19
17
 
20
- // Defaults to the real spawnSync so `git init`/`git ls-files` calls made by the code under test
21
- // (and by test setup below) actually run — individual tests override this via mockReturnValue
22
- // where they need to fake git's output, and vi.restoreAllMocks() reverts back to this passthrough.
23
- vi.mock('node:child_process', async (importOriginal) => {
24
- const actual = await importOriginal<typeof ChildProcessModule>();
25
- return { ...actual, spawnSync: vi.fn(actual.spawnSync) };
26
- });
27
-
28
18
  const mkTempDir = async (prefix: string) => fs.mkdtemp(path.join(os.tmpdir(), prefix));
29
19
 
30
- const initGitRepo = (dir: string) => {
31
- spawnSync('git', ['init', '-q'], { cwd: dir });
32
- };
33
-
34
20
  describe('build-from-local helpers', () => {
35
21
  const tempDirs: string[] = [];
36
22
 
@@ -43,15 +29,13 @@ describe('build-from-local helpers', () => {
43
29
  it('drops secret-pattern files and gitignored files, keeps everything else', async () => {
44
30
  const rootDir = await mkTempDir('apify-test-tools-collect-');
45
31
  tempDirs.push(rootDir);
46
- initGitRepo(rootDir);
47
32
 
48
33
  await fs.writeFile(path.join(rootDir, 'main.js'), 'console.log(1)');
49
34
  await fs.writeFile(path.join(rootDir, '.env'), 'SECRET=1');
50
35
  await fs.mkdir(path.join(rootDir, 'sub'));
51
36
  await fs.writeFile(path.join(rootDir, 'sub', 'ignored.log'), 'log');
52
37
 
53
- // Only the gitignore side is mocked — isSecretFile runs for real, so this also
54
- // proves the secret-pattern backstop applies independently of .gitignore.
38
+ vi.spyOn(Utils, 'listRepoFilePaths').mockResolvedValue(['main.js', '.env', 'sub/ignored.log']);
55
39
  vi.spyOn(Utils, 'getGitignoredPaths').mockImplementation(
56
40
  async (relativePaths) => new Set(relativePaths.filter((p) => p.endsWith('.log'))),
57
41
  );
@@ -146,7 +130,6 @@ describe('build-from-local helpers', () => {
146
130
  it("always collects the actor's own .actor/actor.json for a monorepo actor, since flattenMonorepoContext depends on it", async () => {
147
131
  const repoRoot = await mkTempDir('apify-test-tools-collect-source-');
148
132
  tempDirs.push(repoRoot);
149
- initGitRepo(repoRoot);
150
133
 
151
134
  const originalCwd = process.cwd();
152
135
  // We simulate the working directory being the repo root, since collectSourceFiles uses relative paths to the repo root.
@@ -161,6 +144,14 @@ describe('build-from-local helpers', () => {
161
144
  );
162
145
  await fs.writeFile(path.join(cwd, 'package.json'), '{}');
163
146
 
147
+ vi.spyOn(Utils, 'listRepoFilePaths').mockResolvedValue([
148
+ 'actors/owner_actor/.actor/actor.json',
149
+ 'package.json',
150
+ ]);
151
+ vi.spyOn(Utils, 'getGitignoredPaths').mockResolvedValue(
152
+ new Set(['actors/owner_actor/.actor/actor.json']),
153
+ );
154
+
164
155
  const sourceFiles = await collectSourceFiles('owner/actor', actorDir);
165
156
  expect(sourceFiles.map((file) => file.name)).toContain('.actor/actor.json');
166
157
  } finally {
@@ -1,71 +1,30 @@
1
- import os from 'node:os';
2
- import path from 'node:path';
3
-
4
1
  import { describe, expect, it } from 'vitest';
5
2
 
6
- import { getGitignoredPaths, GitCommandError, listRepoFilePaths, runGitCommand } from '../../../bin/utils.js';
3
+ import { GitCommandError, runGitCommand } from '../../../bin/utils.js';
7
4
 
8
5
  describe('runGitCommand', () => {
9
- it('returns trimmed Git output', async () => {
10
- await expect(
11
- runGitCommand(['rev-parse', '--is-inside-work-tree'], {
12
- cwd: process.cwd(),
13
- operation: 'check whether the current directory is in a Git repository',
14
- }),
15
- ).resolves.toBe('true');
6
+ it('returns trimmed Git output without requiring a repository', async () => {
7
+ await expect(runGitCommand(['--version'])).resolves.toMatch(/^git version /);
16
8
  });
17
9
 
18
- it('rejects on git exit code, not stderr', async () => {
19
- const error: unknown = await runGitCommand(['rev-parse', '--verify', '--quiet'], {
20
- cwd: process.cwd(),
21
- operation: 'verify a commit',
10
+ it('wraps a Git failure with the command and operation', async () => {
11
+ const error: unknown = await runGitCommand(['--definitely-invalid-option'], {
12
+ operation: 'check error handling',
22
13
  }).catch((failure: unknown) => failure);
14
+
23
15
  expect(error).toBeInstanceOf(GitCommandError);
24
16
  if (error instanceof GitCommandError) {
25
- expect(error.exitCode).toBe(1);
26
- expect(error.gitError).toContain('Command failed: git rev-parse --verify --quiet');
27
- expect(error.message).toContain('Failed to verify a commit.\nCommand:');
28
- expect(error.stack).toContain('Failed to verify a commit.');
17
+ expect(error.exitCode).not.toBe(0);
18
+ expect(error.message).toContain('Failed to check error handling.\n');
19
+ expect(error.message).toContain('Command: git "--definitely-invalid-option"\n');
20
+ expect(error.gitError).toContain('--definitely-invalid-option');
29
21
  expect(error.cause).toBeInstanceOf(Error);
30
22
  }
31
23
  });
32
24
 
33
- it('passes arguments literally and rejects Git failures', async () => {
34
- await expect(
35
- runGitCommand(['rev-parse', '--verify', 'HEAD; echo injected'], {
36
- operation: 'verify a commit reference',
37
- }),
38
- ).rejects.toThrow('Command: git "rev-parse" "--verify" "HEAD; echo injected"\nGit error:');
39
- });
40
- });
41
-
42
- describe('listRepoFilePaths', () => {
43
- it('lists files under a subdirectory relative to the repository root', async () => {
44
- const repoRoot = process.cwd();
45
- await expect(listRepoFilePaths(repoRoot, path.join(repoRoot, 'bin'))).resolves.toContain('bin/utils.ts');
46
- });
47
- });
48
-
49
- describe('getGitignoredPaths', () => {
50
- it('returns an empty set for no paths', async () => {
51
- await expect(getGitignoredPaths([])).resolves.toStrictEqual(new Set());
52
- });
53
-
54
- it('returns only paths ignored by the repository rules', async () => {
55
- await expect(
56
- getGitignoredPaths(['node_modules/example.js', 'bin/utils.ts', '.DS_Store'], process.cwd()),
57
- ).resolves.toStrictEqual(new Set(['node_modules/example.js', '.DS_Store']));
58
- });
59
-
60
- it('returns an empty set when Git exits with code 1', async () => {
61
- await expect(getGitignoredPaths(['bin/utils.ts'], process.cwd())).resolves.toStrictEqual(new Set());
62
- });
63
-
64
- it('rejects unexpected Git errors', async () => {
65
- await expect(getGitignoredPaths(['bin/utils.ts'], os.tmpdir())).rejects.toThrow(
66
- 'Failed to check which repository paths are ignored.\n' +
67
- 'Command: git "check-ignore" "--" "bin/utils.ts"\n' +
68
- 'Git error: fatal: not a git repository',
25
+ it('passes arguments literally instead of running them through a shell', async () => {
26
+ await expect(runGitCommand(['--version; echo injected'])).rejects.toThrow(
27
+ 'Command: git "--version; echo injected"\nGit error:',
69
28
  );
70
29
  });
71
30
  });