Skip to content

Commit 74fc68a

Browse files
committed
1 parent 501fe35 commit 74fc68a

File tree

3 files changed

+633
-0
lines changed

3 files changed

+633
-0
lines changed

test/cli.test.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { spawn } from 'node:child_process';
2+
import { fileURLToPath } from 'node:url';
3+
import { suite } from 'uvu';
4+
import * as assert from 'uvu/assert';
5+
6+
const testSuite = suite('cli');
7+
const cliPath = fileURLToPath(new URL('../bin/cli.js', import.meta.url));
8+
9+
testSuite('should spawn hugo process with version command', async() => {
10+
const result = await new Promise((resolve, reject) => {
11+
const child = spawn('node', [cliPath, 'version'], {
12+
stdio: 'pipe'
13+
});
14+
15+
let stdout = '';
16+
let stderr = '';
17+
18+
child.stdout.on('data', data => {
19+
stdout += data.toString();
20+
});
21+
22+
child.stderr.on('data', data => {
23+
stderr += data.toString();
24+
});
25+
26+
child.on('error', reject);
27+
28+
child.on('exit', code => {
29+
resolve({ code, stdout, stderr });
30+
});
31+
});
32+
33+
// The CLI should execute successfully (exit code 0 or 1 depending on output redirection)
34+
assert.ok(result.code !== null);
35+
assert.ok(result.stdout.includes('hugo') || result.stderr.includes('hugo'));
36+
});
37+
38+
testSuite('should spawn hugo process with help command', async() => {
39+
const result = await new Promise((resolve, reject) => {
40+
const child = spawn('node', [cliPath, 'help'], {
41+
stdio: 'pipe'
42+
});
43+
44+
let stdout = '';
45+
let stderr = '';
46+
47+
child.stdout.on('data', data => {
48+
stdout += data.toString();
49+
});
50+
51+
child.stderr.on('data', data => {
52+
stderr += data.toString();
53+
});
54+
55+
child.on('error', reject);
56+
57+
child.on('exit', code => {
58+
resolve({ code, stdout, stderr });
59+
});
60+
});
61+
62+
// The CLI should execute (exit code can vary based on platform/config)
63+
assert.ok(result.code !== null);
64+
const output = result.stdout + result.stderr;
65+
assert.ok(output.includes('hugo') || output.includes('Hugo') || output.includes('usage'));
66+
});
67+
68+
testSuite('should pass arguments to hugo binary', async() => {
69+
const result = await new Promise((resolve, reject) => {
70+
const child = spawn('node', [cliPath, '--help'], {
71+
stdio: 'pipe'
72+
});
73+
74+
let stdout = '';
75+
let stderr = '';
76+
77+
child.stdout.on('data', data => {
78+
stdout += data.toString();
79+
});
80+
81+
child.stderr.on('data', data => {
82+
stderr += data.toString();
83+
});
84+
85+
child.on('error', reject);
86+
87+
child.on('exit', code => {
88+
resolve({ code, stdout, stderr });
89+
});
90+
});
91+
92+
// Should execute and return output
93+
assert.ok(result.code !== null);
94+
const output = result.stdout + result.stderr;
95+
assert.ok(output.length > 0);
96+
});
97+
98+
testSuite.run();

0 commit comments

Comments
 (0)