Skip to content

Commit 98b6411

Browse files
test: fix PATH in integration test
- Spread process.env to inherit PATH for tar executable - Use stdio: pipe to capture output on failure - Clean tmp directories in afterAll Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
1 parent 4b5bc2e commit 98b6411

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/index.integration.test.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
import { spawnSync } from 'node:child_process';
2+
import { rm } from 'node:fs/promises';
23
import { resolve } from 'node:path';
34
import { fileURLToPath } from 'node:url';
45

5-
import { describe, expect, it } from 'vitest';
6+
import { afterAll, describe, expect, it } from 'vitest';
67

78
const __dirname = fileURLToPath(new URL('.', import.meta.url));
89
const nodePath = process.execPath;
910
const actionPath = resolve(__dirname, '../dist/index.js');
1011
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+
});
1122

1223
describe('integration', () => {
1324
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-
2125
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',
2434
});
2535

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+
2643
expect(result.status).toBe(0);
2744
});
2845
});

0 commit comments

Comments
 (0)