Skip to content

Commit 835b59f

Browse files
authored
Improve integration failure diagnostics (#40)
1 parent 613974a commit 835b59f

5 files changed

Lines changed: 271 additions & 51 deletions

File tree

.github/workflows/android.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ jobs:
5454
path: |
5555
${{ steps.android-agent-home.outputs.dir }}/daemon.log
5656
${{ steps.android-agent-home.outputs.dir }}/sessions/**
57+
test/artifacts/**
5758
test/screenshots/**

.github/workflows/ios.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,5 @@ jobs:
9898
path: |
9999
${{ steps.ios-agent-home.outputs.dir }}/daemon.log
100100
${{ steps.ios-agent-home.outputs.dir }}/sessions/**
101+
test/artifacts/**
101102
test/screenshots/**

test/integration/android.test.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import test from 'node:test';
2-
import assert from 'node:assert/strict';
3-
import { formatResultDebug, runCliJson } from './test-helpers.ts';
2+
import { createIntegrationTestContext, runCliJson } from './test-helpers.ts';
43

54
const session = ['--session', 'android-test'];
65

@@ -9,35 +8,34 @@ test.after(() => {
98
});
109

1110
test('android settings commands', () => {
12-
const openArgs = ['open', 'Settings', '--platform', 'android', ...session];
13-
const open = runCliJson(openArgs);
14-
assert.equal(open.status, 0, formatResultDebug('open settings', openArgs, open));
11+
const integration = createIntegrationTestContext({
12+
platform: 'android',
13+
testName: 'android settings commands',
14+
});
15+
const openArgs = ['open', 'Settings', '--platform', 'android', '--json', ...session];
16+
integration.runStep('open settings', openArgs);
1517

1618
const snapshotArgs = ['snapshot', '-i', '--json', ...session];
17-
const snapshot = runCliJson(snapshotArgs);
18-
assert.equal(snapshot.status, 0, formatResultDebug('snapshot', snapshotArgs, snapshot));
19-
assert.ok(
20-
Array.isArray(snapshot.json?.data?.nodes),
21-
formatResultDebug('snapshot nodes', snapshotArgs, snapshot),
22-
);
19+
const snapshot = integration.runStep('snapshot', snapshotArgs);
20+
integration.assertResult(Array.isArray(snapshot.json?.data?.nodes), 'snapshot nodes', snapshotArgs, snapshot, {
21+
detail: 'expected snapshot to include a nodes array',
22+
});
2323

24-
const clickAppsArgs = ['click', '@e13', ...session];
25-
const clickApps = runCliJson(clickAppsArgs);
26-
assert.equal(clickApps.status, 0, formatResultDebug('click apps', clickAppsArgs, clickApps));
24+
const clickAppsArgs = ['click', '@e13', '--json', ...session];
25+
integration.runStep('click apps', clickAppsArgs);
2726

2827
const snapshotAppsArgs = ['snapshot', '-i', '--json', ...session];
29-
const snapshotApps = runCliJson(snapshotAppsArgs);
30-
assert.equal(
31-
snapshotApps.status,
32-
0,
33-
formatResultDebug('snapshot apps', snapshotAppsArgs, snapshotApps),
34-
);
35-
assert.ok(
28+
const snapshotApps = integration.runStep('snapshot apps', snapshotAppsArgs);
29+
integration.assertResult(
3630
Array.isArray(snapshotApps.json?.data?.nodes),
37-
formatResultDebug('snapshot apps nodes', snapshotAppsArgs, snapshotApps),
31+
'snapshot apps nodes',
32+
snapshotAppsArgs,
33+
snapshotApps,
34+
{
35+
detail: 'expected snapshot after click to include a nodes array',
36+
},
3837
);
3938

40-
const backArgs = ['back', ...session];
41-
const back = runCliJson(backArgs);
42-
assert.equal(back.status, 0, formatResultDebug('back', backArgs, back));
39+
const backArgs = ['back', '--json', ...session];
40+
integration.runStep('back', backArgs);
4341
});

test/integration/ios.test.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import test from 'node:test';
2-
import assert from 'node:assert/strict';
32
import { existsSync } from 'node:fs';
43
import path from 'node:path';
5-
import { formatResultDebug, runCliJson } from './test-helpers.ts';
4+
import { createIntegrationTestContext, runCliJson } from './test-helpers.ts';
65

76
const session = ['--session', 'ios-test'];
87

@@ -11,53 +10,60 @@ test.after(() => {
1110
});
1211

1312
test('ios settings commands', { skip: shouldSkipIos() }, async () => {
13+
const integration = createIntegrationTestContext({
14+
platform: 'ios',
15+
testName: 'ios settings commands',
16+
});
1417
const openArgs = ['open', 'com.apple.Preferences', '--platform', 'ios', '--json', ...session];
15-
const open = runCliJson(openArgs);
16-
assert.equal(open.status, 0, formatResultDebug('open settings', openArgs, open));
18+
integration.runStep('open settings', openArgs);
1719

1820
const outPath = path.resolve('test/screenshots/ios-settings.png');
1921
const shotArgs = ['screenshot', outPath, '--platform', 'ios', '--json', ...session];
20-
const shot = runCliJson(shotArgs);
21-
assert.equal(shot.status, 0, formatResultDebug('screenshot settings', shotArgs, shot));
22-
assert.ok(existsSync(outPath), formatResultDebug('screenshot file missing', shotArgs, shot));
22+
const shot = integration.runStep('screenshot settings', shotArgs);
23+
integration.assertResult(existsSync(outPath), 'screenshot file missing', shotArgs, shot, {
24+
detail: `expected screenshot file at ${outPath}`,
25+
});
2326

2427
const snapshotArgs = ['snapshot', '-i', '--json', ...session];
25-
const snapshot = runCliJson(snapshotArgs);
26-
assert.equal(snapshot.status, 0, formatResultDebug('snapshot', snapshotArgs, snapshot));
27-
assert.ok(
28-
Array.isArray(snapshot.json?.data?.nodes),
29-
formatResultDebug('snapshot nodes', snapshotArgs, snapshot),
30-
);
28+
const snapshot = integration.runStep('snapshot', snapshotArgs);
29+
integration.assertResult(Array.isArray(snapshot.json?.data?.nodes), 'snapshot nodes', snapshotArgs, snapshot, {
30+
detail: 'expected snapshot to include a nodes array',
31+
});
3132

3233
const clickArgs = ['click', '@e21', '--json', ...session];
33-
const click = runCliJson(clickArgs);
34-
assert.equal(click.status, 0, formatResultDebug('click @e13', clickArgs, click));
34+
integration.runStep('click @e21', clickArgs);
3535

36-
const snapshotGeneral = runCliJson(['snapshot', '--json', ...session]);
36+
const snapshotGeneralArgs = ['snapshot', '--json', ...session];
37+
const snapshotGeneral = integration.runStep('snapshot general', snapshotGeneralArgs);
3738
const generalDescription = 'Manage your overall setup and preferences';
3839
const generalNodes = Array.isArray(snapshotGeneral.json?.data?.nodes)
3940
? snapshotGeneral.json.data.nodes
4041
: [];
41-
assert.ok(
42+
integration.assertResult(
4243
generalNodes.some(
4344
(node: { label?: string }) =>
4445
typeof node?.label === 'string' && node.label.includes(generalDescription),
4546
),
46-
formatResultDebug('snapshot shows general page description', snapshotArgs, snapshotGeneral),
47+
'snapshot shows general page description',
48+
snapshotGeneralArgs,
49+
snapshotGeneral,
50+
{
51+
detail: `expected a node label containing ${JSON.stringify(generalDescription)}`,
52+
},
4753
);
4854

4955
const findTextArgs = ['find', 'text', generalDescription, 'exists', '--json', ...session];
50-
const findText = runCliJson(findTextArgs);
51-
assert.equal(findText.status, 0, formatResultDebug('find text', findTextArgs, findText));
52-
assert.equal(
56+
const findText = integration.runStep('find text', findTextArgs);
57+
integration.assertResult(
5358
findText.json?.success,
54-
true,
55-
formatResultDebug('find text success', findTextArgs, findText),
59+
'find text success',
60+
findTextArgs,
61+
findText,
62+
{ detail: 'expected find command to return success=true' },
5663
);
5764

58-
const backArgs = ['back', ...session];
59-
const back = runCliJson(backArgs);
60-
assert.equal(back.status, 0, formatResultDebug('back', backArgs, back));
65+
const backArgs = ['back', '--json', ...session];
66+
integration.runStep('back', backArgs);
6167
});
6268

6369
function shouldSkipIos(): boolean {

0 commit comments

Comments
 (0)