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

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/eslint.config.mjs CHANGED
@@ -6,7 +6,7 @@ import tsEslint from 'typescript-eslint';
6
6
 
7
7
  // eslint-disable-next-line import/no-default-export
8
8
  export default [
9
- { ignores: ['**/dist', 'eslint.config.mjs', 'vitest.config.ts', '.github'] },
9
+ { ignores: ['**/dist', 'eslint.config.mjs', 'vitest.config.ts', '.github', '.cli-test-*'] },
10
10
  ...apify,
11
11
  prettier,
12
12
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-test-tools",
3
- "version": "0.10.2-beta.12",
3
+ "version": "0.10.2-beta.13",
4
4
  "type": "module",
5
5
  "description": "TBD",
6
6
  "repository": {
@@ -7,11 +7,17 @@ import { fileURLToPath } from 'node:url';
7
7
  const projectRoot = fileURLToPath(new URL('../../../', import.meta.url));
8
8
  const compilerPath = fileURLToPath(new URL('../../../node_modules/typescript/bin/tsc', import.meta.url));
9
9
 
10
- /** Compiles the CLI from the sources into a temporary directory, so tests run it the way users do. */
10
+ /** Compiles the CLI from the sources into a temporary directory, so tests run it the way npm users do. */
11
11
  export const compileCli = async () => {
12
12
  const buildDir = await mkdtemp(path.join(projectRoot, '.cli-test-'));
13
- execFileSync(process.execPath, [compilerPath, '--outDir', buildDir], { cwd: projectRoot });
14
- const cliPath = path.join(buildDir, 'bin/main.js');
15
- await chmod(cliPath, 0o755);
16
- return { cliPath, cleanup: async () => rm(buildDir, { recursive: true, force: true }) };
13
+ const cleanup = async () => rm(buildDir, { recursive: true, force: true });
14
+ try {
15
+ execFileSync(process.execPath, [compilerPath, '--outDir', buildDir], { cwd: projectRoot });
16
+ const cliPath = path.join(buildDir, 'bin/main.js');
17
+ await chmod(cliPath, 0o755);
18
+ return { cliPath, cleanup };
19
+ } catch (error) {
20
+ await cleanup();
21
+ throw error;
22
+ }
17
23
  };
@@ -1,25 +1,21 @@
1
- import { execFileSync, spawnSync } from 'node:child_process';
1
+ import { spawnSync } from 'node:child_process';
2
2
  import { chmod, mkdtemp, rm, writeFile } from 'node:fs/promises';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import process from 'node:process';
6
- import { fileURLToPath } from 'node:url';
7
6
 
8
7
  import { afterAll, beforeAll, describe, expect, it } from 'vitest';
9
8
 
10
- const projectRoot = fileURLToPath(new URL('../../../', import.meta.url));
11
- const compilerPath = fileURLToPath(new URL('../../../node_modules/typescript/bin/tsc', import.meta.url));
9
+ import { compileCli } from './compiled-cli.js';
10
+
12
11
  let cliPath: string;
13
- let buildDir: string | undefined;
12
+ let cleanup: (() => Promise<void>) | undefined;
14
13
  let gitStubDir: string | undefined;
15
14
  const sha = '1'.repeat(40);
16
15
 
17
16
  describe('CLI logging', () => {
18
17
  beforeAll(async () => {
19
- buildDir = await mkdtemp(path.join(projectRoot, '.cli-test-'));
20
- execFileSync(process.execPath, [compilerPath, '--outDir', buildDir], { cwd: projectRoot });
21
- cliPath = path.join(buildDir, 'bin/main.js');
22
- await chmod(cliPath, 0o755);
18
+ ({ cliPath, cleanup } = await compileCli());
23
19
  gitStubDir = await mkdtemp(path.join(os.tmpdir(), 'apify-cli-logging-'));
24
20
  const gitStub = path.join(gitStubDir, 'git');
25
21
  await writeFile(
@@ -30,7 +26,7 @@ describe('CLI logging', () => {
30
26
  });
31
27
 
32
28
  afterAll(async () => {
33
- if (buildDir) await rm(buildDir, { recursive: true, force: true });
29
+ await cleanup?.();
34
30
  if (gitStubDir) await rm(gitStubDir, { recursive: true, force: true });
35
31
  });
36
32