Skip to content

Commit fe123c0

Browse files
committed
refactor: centralize live artifact assertions
1 parent 9ef5bf1 commit fe123c0

3 files changed

Lines changed: 20 additions & 33 deletions

File tree

‎test/integration/android-emulator-e2e/live-assertions.ts‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
import assert from 'node:assert/strict';
2-
import fs from 'node:fs';
3-
42
import { PUBLIC_COMMANDS } from '../../../src/command-catalog.ts';
53
import type { RawSnapshotNode } from '@agent-device/kernel/snapshot';
64
import type { SnapshotDiffLine } from '../../../src/snapshot/snapshot-diff.ts';
7-
import { isPlayableVideo } from '../../../src/utils/video.ts';
85
import {
96
assertFilesDiffer,
107
assertJsonContains,
8+
assertMp4File,
9+
assertNonEmptyFile,
1110
createLiveDeviceAssertions,
1211
} from '../live-device-e2e/assertions.ts';
1312
import type { CliJsonResult } from '../cli-json.ts';
1413
import type { AndroidEmulatorBehaviorId } from './behavior-coverage.ts';
1514
import { type LiveContext, runStep, verifyCommand } from './live-harness.ts';
1615

17-
export { assertFilesDiffer, assertJsonContains };
18-
19-
export function assertNonEmptyFile(filePath: string, name: string): void {
20-
assert.ok(fs.statSync(filePath).size > 0, `${name} artifact is empty: ${filePath}`);
21-
}
22-
23-
export async function assertMp4File(filePath: string): Promise<void> {
24-
assertNonEmptyFile(filePath, 'recording');
25-
assert.equal(
26-
await isPlayableVideo(filePath),
27-
true,
28-
`recording is not a finalized playable video: ${filePath}`,
29-
);
30-
}
16+
export { assertFilesDiffer, assertJsonContains, assertMp4File, assertNonEmptyFile };
3117

3218
export const { assertElementText, assertWaitSelector, assertWaitText, capturePng } =
3319
createLiveDeviceAssertions<AndroidEmulatorBehaviorId, LiveContext>(

‎test/integration/ios-simulator-e2e/live-assertions.ts‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import assert from 'node:assert/strict';
2-
import fs from 'node:fs';
32

43
import { PUBLIC_COMMANDS } from '../../../src/command-catalog.ts';
5-
import { isPlayableVideo } from '../../../src/utils/video.ts';
64
import {
75
assertFilesDiffer,
86
assertJsonContains,
7+
assertMp4File,
8+
assertNonEmptyFile,
99
createLiveDeviceAssertions,
1010
} from '../live-device-e2e/assertions.ts';
1111
import type { CliJsonResult } from '../cli-json.ts';
1212
import type { IosSimulatorBehaviorId } from './behavior-coverage.ts';
1313
import { type LiveContext, runStep, verifyCommand } from './live-harness.ts';
1414

15-
export { assertFilesDiffer, assertJsonContains };
15+
export { assertFilesDiffer, assertJsonContains, assertMp4File, assertNonEmptyFile };
1616

1717
export const { assertElementText, assertWaitText, capturePng } = createLiveDeviceAssertions<
1818
IosSimulatorBehaviorId,
@@ -40,19 +40,6 @@ export async function assertElementTextAfterScrolling(
4040
assert.fail(`${selector} did not become visible after scrolling`);
4141
}
4242

43-
export function assertNonEmptyFile(filePath: string, name: string): void {
44-
assert.ok(fs.statSync(filePath).size > 0, `${name} artifact is empty: ${filePath}`);
45-
}
46-
47-
export async function assertMp4File(filePath: string): Promise<void> {
48-
assertNonEmptyFile(filePath, 'recording');
49-
assert.equal(
50-
await isPlayableVideo(filePath),
51-
true,
52-
`recording is not a finalized playable video: ${filePath}`,
53-
);
54-
}
55-
5643
function requireNode(
5744
result: CliJsonResult,
5845
identifier: string,

‎test/integration/live-device-e2e/assertions.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
22
import fs from 'node:fs';
33

44
import { assertPngFile } from '../provider-scenarios/assertions.ts';
5+
import { isPlayableVideo } from '../../../src/utils/video.ts';
56
import type { CliJsonResult } from '../cli-json.ts';
67
import type { LiveDeviceContext } from './runtime.ts';
78

@@ -65,3 +66,16 @@ export function assertJsonContains(result: CliJsonResult, expected: string, mess
6566
export function assertFilesDiffer(first: string, second: string, message: string): void {
6667
assert.notDeepEqual(fs.readFileSync(first), fs.readFileSync(second), message);
6768
}
69+
70+
export function assertNonEmptyFile(filePath: string, name: string): void {
71+
assert.ok(fs.statSync(filePath).size > 0, `${name} artifact is empty: ${filePath}`);
72+
}
73+
74+
export async function assertMp4File(filePath: string): Promise<void> {
75+
assertNonEmptyFile(filePath, 'recording');
76+
assert.equal(
77+
await isPlayableVideo(filePath),
78+
true,
79+
`recording is not a finalized playable video: ${filePath}`,
80+
);
81+
}

0 commit comments

Comments
 (0)