|
1 | 1 | import { spawnSync } from 'node:child_process'; |
| 2 | +import { rm } from 'node:fs/promises'; |
2 | 3 | import { resolve } from 'node:path'; |
3 | 4 | import { fileURLToPath } from 'node:url'; |
4 | 5 |
|
5 | | -import { describe, expect, it } from 'vitest'; |
| 6 | +import { afterAll, describe, expect, it } from 'vitest'; |
6 | 7 |
|
7 | 8 | const __dirname = fileURLToPath(new URL('.', import.meta.url)); |
8 | 9 | const nodePath = process.execPath; |
9 | 10 | const actionPath = resolve(__dirname, '../dist/index.js'); |
10 | 11 | const tmpPath = resolve(__dirname, '../node_modules/.tmp'); |
| 12 | +const runnerToolCachePath = resolve(tmpPath, 'runner_tool_cache'); |
| 13 | +const runnerTempPath = resolve(tmpPath, 'runner_temp'); |
| 14 | + |
| 15 | +afterAll(async () => { |
| 16 | + await Promise.all( |
| 17 | + [runnerToolCachePath, runnerTempPath].map((path) => |
| 18 | + rm(path, { recursive: true, force: true }), |
| 19 | + ), |
| 20 | + ); |
| 21 | +}); |
11 | 22 |
|
12 | 23 | describe('integration', () => { |
13 | 24 | it('runs action', () => { |
14 | | - const env = { |
15 | | - 'INPUT_CLI-NAME': 'gh', |
16 | | - 'INPUT_CLI-VERSION': '2.27.0', |
17 | | - RUNNER_TOOL_CACHE: resolve(tmpPath, 'runner_tool_cache'), |
18 | | - RUNNER_TEMP: resolve(tmpPath, 'runner_temp'), |
19 | | - }; |
20 | | - |
21 | 25 | const result = spawnSync(nodePath, [actionPath], { |
22 | | - env, |
23 | | - stdio: 'ignore', // 'inherit' to stream output in real-time |
| 26 | + env: { |
| 27 | + ...process.env, |
| 28 | + 'INPUT_CLI-NAME': 'gh', |
| 29 | + 'INPUT_CLI-VERSION': '2.27.0', |
| 30 | + RUNNER_TOOL_CACHE: runnerToolCachePath, |
| 31 | + RUNNER_TEMP: runnerTempPath, |
| 32 | + }, |
| 33 | + stdio: 'pipe', |
24 | 34 | }); |
25 | 35 |
|
| 36 | + if (result.status !== 0) { |
| 37 | + /* eslint-disable no-console */ |
| 38 | + console.error('stdout:', result.stdout?.toString()); |
| 39 | + console.error('stderr:', result.stderr?.toString()); |
| 40 | + /* eslint-enable no-console */ |
| 41 | + } |
| 42 | + |
26 | 43 | expect(result.status).toBe(0); |
27 | 44 | }); |
28 | 45 | }); |
0 commit comments