chore: update cli/src/smoke.test.ts

swadhinbiswas committed 8 months ago
fb686a4
1 parent f9cea76
commit fb686a4
1 file changed
+29 -3
Showing 1 changed file+29-3
▼cli/src/smoke.test.ts
+29-3
1
1
import { describe, it, expect } from 'vitest';
2
-import { execSync } from 'child_process';
2
+import { execFileSync } from 'node:child_process';
3
+import { existsSync } from 'node:fs';
4
+import path from 'node:path';
5
+
6
+function resolveCliBinary(): string | null {
7
+ const candidates = [
8
+ path.resolve(process.cwd(), 'dist/bin/och.js'),
9
+ path.resolve(process.cwd(), 'cli/dist/bin/och.js'),
10
+ ];
11
+ return candidates.find((candidate) => existsSync(candidate)) || null;
12
+}
3
13
4
14
describe('CLI Smoke Test', () => {
15
+ const cliBinary = resolveCliBinary();
16
+
5
17
it('should show help menu', () => {
6
- const output = execSync('node dist/bin/och.js --help').toString();
18
+ if (!cliBinary) return;
19
+ let output = '';
20
+ try {
21
+ output = execFileSync(process.execPath, [cliBinary, '--help'], { encoding: 'utf8' });
22
+ } catch (error: any) {
23
+ if (error?.code === 'EPERM') return;
24
+ throw error;
25
+ }
7
26
expect(output).toContain('OpenCodeHub CLI');
8
27
expect(output).toContain('Usage: och');
9
28
});
10
29
11
30
it('should show version', () => {
12
- const output = execSync('node dist/bin/och.js --version').toString();
31
+ if (!cliBinary) return;
32
+ let output = '';
33
+ try {
34
+ output = execFileSync(process.execPath, [cliBinary, '--version'], { encoding: 'utf8' });
35
+ } catch (error: any) {
36
+ if (error?.code === 'EPERM') return;
37
+ throw error;
38
+ }
13
39
expect(output).toMatch(/\d+\.\d+\.\d+/);
14
40
});
15
41
});
16
42