-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathcli-agent-cdp.test.ts
More file actions
92 lines (83 loc) · 2.44 KB
/
Copy pathcli-agent-cdp.test.ts
File metadata and controls
92 lines (83 loc) · 2.44 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
import fs from 'node:fs';
import assert from 'node:assert/strict';
import { afterEach, test, vi } from 'vitest';
vi.mock('../utils/exec.ts', () => ({
runCmdStreaming: vi.fn(),
}));
import { runCmdStreaming } from '../utils/exec.ts';
import {
AGENT_CDP_PACKAGE,
buildAgentCdpNpmExecArgs,
runAgentCdpCommand,
} from '../cli/commands/agent-cdp.ts';
afterEach(() => {
vi.clearAllMocks();
});
test('cdp wrapper pins agent-cdp package version', () => {
assert.equal(AGENT_CDP_PACKAGE, 'agent-cdp@1.6.0');
assert.deepEqual(
buildAgentCdpNpmExecArgs(['memory', 'usage', 'sample', '--label', 'baseline', '--gc']),
[
'exec',
'--yes',
'--package',
'agent-cdp@1.6.0',
'--',
'agent-cdp',
'memory',
'usage',
'sample',
'--label',
'baseline',
'--gc',
],
);
});
test('cdp docs hide the implementation package name', () => {
assert.doesNotMatch(fs.readFileSync('website/docs/docs/commands.md', 'utf8'), /agent-cdp/);
assert.doesNotMatch(
fs.readFileSync('website/docs/docs/debugging-profiling.md', 'utf8'),
/agent-cdp/,
);
});
test('cdp workflow docs live in debugging and profiling guide', () => {
assert.match(
fs.readFileSync('website/docs/docs/commands.md', 'utf8'),
/agent-device cdp memory usage sample --label baseline --gc/,
);
assert.doesNotMatch(
fs.readFileSync('website/docs/docs/commands.md', 'utf8'),
/React Native JS memory through CDP/,
);
assert.match(
fs.readFileSync('website/docs/docs/debugging-profiling.md', 'utf8'),
/React Native JS memory through CDP/,
);
});
test('cdp wrapper streams through npm exec and returns downstream exit code', async () => {
const env = { ...process.env };
vi.mocked(runCmdStreaming).mockResolvedValueOnce({
exitCode: 7,
stdout: '',
stderr: '',
});
const exitCode = await runAgentCdpCommand(['target', 'list'], {
cwd: '/tmp/project',
env,
});
assert.equal(exitCode, 7);
assert.equal(vi.mocked(runCmdStreaming).mock.calls[0]?.[0], 'npm');
assert.deepEqual(vi.mocked(runCmdStreaming).mock.calls[0]?.[1], [
'exec',
'--yes',
'--package',
'agent-cdp@1.6.0',
'--',
'agent-cdp',
'target',
'list',
]);
assert.equal(vi.mocked(runCmdStreaming).mock.calls[0]?.[2]?.cwd, '/tmp/project');
assert.equal(vi.mocked(runCmdStreaming).mock.calls[0]?.[2]?.env, env);
assert.equal(vi.mocked(runCmdStreaming).mock.calls[0]?.[2]?.allowFailure, true);
});