-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest-issue-18-pid.cjs
More file actions
75 lines (62 loc) · 2.33 KB
/
test-issue-18-pid.cjs
File metadata and controls
75 lines (62 loc) · 2.33 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
/**
* TDD tests for issue #18: chrome-ws pid / chrome-ws info command
*
* Tests getChromePid() export and getBrowserMode() pid field.
* Run: node test-issue-18-pid.cjs
*/
const assert = require('assert');
const lib = require('./skills/browsing/chrome-ws-lib.js');
let passed = 0;
let failed = 0;
function test(name, fn) {
try {
fn();
console.log(` PASS: ${name}`);
passed++;
} catch (e) {
console.log(` FAIL: ${name}`);
console.log(` ${e.message}`);
failed++;
}
}
async function asyncTest(name, fn) {
try {
await fn();
console.log(` PASS: ${name}`);
passed++;
} catch (e) {
console.log(` FAIL: ${name}`);
console.log(` ${e.message}`);
failed++;
}
}
console.log('\n=== Issue #18: getChromePid() export ===\n');
test('getChromePid is exported', () => {
assert.strictEqual(typeof lib.getChromePid, 'function', 'getChromePid should be a function in module.exports');
});
test('getChromePid returns null when Chrome is not running', () => {
const pid = lib.getChromePid();
assert.strictEqual(pid, null, `getChromePid() should return null when Chrome is not running, got: ${pid}`);
});
test('getChromePid returns a number or null (never undefined)', () => {
const pid = lib.getChromePid();
assert.ok(pid === null || typeof pid === 'number', `getChromePid() should return null or a number, got: ${typeof pid}`);
});
console.log('\n=== Issue #18: getBrowserMode() includes pid ===\n');
(async () => {
await asyncTest('getBrowserMode returns pid field', async () => {
const mode = await lib.getBrowserMode();
assert.ok('pid' in mode, `getBrowserMode() result should have a 'pid' field, got keys: ${Object.keys(mode).join(', ')}`);
});
await asyncTest('getBrowserMode pid is null when Chrome not running', async () => {
const mode = await lib.getBrowserMode();
assert.strictEqual(mode.pid, null, `getBrowserMode().pid should be null when Chrome not running, got: ${mode.pid}`);
});
await asyncTest('getBrowserMode pid is a number or null', async () => {
const mode = await lib.getBrowserMode();
assert.ok(mode.pid === null || typeof mode.pid === 'number',
`getBrowserMode().pid should be null or number, got: ${typeof mode.pid}`);
});
console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`);
process.exit(failed > 0 ? 1 : 0);
})();