-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-smoke.test.mjs
More file actions
106 lines (86 loc) · 3.53 KB
/
cli-smoke.test.mjs
File metadata and controls
106 lines (86 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// SPDX-License-Identifier: AGPL-3.0-or-later
// Smoke tests for CLI tools (verify they can be invoked)
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
// Helper to spawn CLI and immediately terminate
async function smokeTestCLI(script, args = []) {
return new Promise((resolve) => {
const proc = spawn('node', [script, ...args], {
cwd: process.cwd(),
timeout: 500,
});
let stdout = '';
let stderr = '';
proc.stdout.on('data', (data) => {
stdout += data.toString();
});
proc.stderr.on('data', (data) => {
stderr += data.toString();
});
// Kill after seeing first prompt
const checkTimer = setInterval(() => {
if (stdout.length > 0 || stderr.length > 0) {
clearInterval(checkTimer);
proc.kill('SIGTERM');
}
}, 100);
proc.on('close', (code, signal) => {
clearInterval(checkTimer);
resolve({ code, signal, stdout, stderr, started: stdout.length > 0 || stderr.length > 0 });
});
// Fallback timeout
setTimeout(() => {
clearInterval(checkTimer);
proc.kill('SIGTERM');
}, 500);
});
}
test('CLI smoke: CaptureCLI.res.js - starts and shows prompt (quick mode)', async () => {
const result = await smokeTestCLI('src-rescript/CaptureCLI.res.js', ['quick']);
assert.ok(result.started, 'CLI should start and produce output');
assert.ok(
result.stdout.includes('UbiCity') || result.stdout.includes('WHO'),
'Should show UbiCity header or first prompt'
);
});
test('CLI smoke: CaptureCLI.res.js - starts and shows prompt (full mode)', async () => {
const result = await smokeTestCLI('src-rescript/CaptureCLI.res.js', ['full']);
assert.ok(result.started, 'CLI should start and produce output');
assert.ok(
result.stdout.includes('UbiCity') || result.stdout.includes('WHO'),
'Should show UbiCity header or first prompt'
);
});
test('CLI smoke: CaptureCLI.res.js - template mode generates JSON', async () => {
return new Promise((resolve) => {
const proc = spawn('node', ['src-rescript/CaptureCLI.res.js', 'template'], {
cwd: process.cwd(),
});
let stdout = '';
proc.stdout.on('data', (data) => {
stdout += data.toString();
});
proc.on('close', () => {
assert.ok(stdout.includes('your-pseudonym'), 'Should output template JSON with learner ID');
assert.ok(stdout.includes('Location Name'), 'Should output template location');
assert.ok(stdout.includes('experiment'), 'Should output template experience type');
resolve();
});
});
});
test('CLI smoke: Capture module exports', async () => {
const Capture = await import('../src-rescript/Capture.res.js');
assert.ok(Capture.CaptureSession, 'Should export CaptureSession module');
assert.ok(typeof Capture.CaptureSession.make === 'function', 'Should export make function');
assert.ok(typeof Capture.CaptureSession.capture === 'function', 'Should export capture function');
});
test('CLI smoke: CaptureCLI module structure', async () => {
// CaptureCLI.res.js runs main() on import, so we can't import it directly
// Just verify the file exists and is valid JS
const { readFile } = await import('node:fs/promises');
const content = await readFile('src-rescript/CaptureCLI.res.js', 'utf-8');
assert.ok(content.includes('parseMode'), 'Should contain parseMode function');
assert.ok(content.includes('main'), 'Should contain main function');
assert.ok(content.includes('Capture.CaptureSession'), 'Should reference CaptureSession');
});