| 123456789101112131415161718192021 |
- import { test } from 'node:test';
- import assert from 'node:assert/strict';
- import { captureNativeScreenshot } from './android-webview-cdp.mjs';
- const png = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10, 0, 255, 13, 10]);
- test('native screenshot keeps exact PNG bytes and targets one explicit device', () => {
- let written = 0;
- captureNativeScreenshot('fixture.png', 'fixture-serial', {
- run(command, args, options) { assert.equal(command, 'adb'); assert.deepEqual(args, ['-s', 'fixture-serial', 'exec-out', 'screencap', '-p']); assert.equal(options.encoding, undefined); return { status: 0, stdout: png }; },
- write(file, data, options) { written++; assert.equal(file, 'fixture.png'); assert.deepEqual(data, png); assert.equal(options.flag, 'wx'); },
- });
- assert.equal(written, 1);
- });
- test('failed or text-corrupted capture must never write successful evidence', () => {
- for (const result of [{ status: 1, stdout: png }, { status: 0, stdout: png.toString() }]) {
- assert.throws(() => captureNativeScreenshot('fixture.png', 'fixture-serial', { run: () => result, write() { assert.fail('must not write failed screenshot'); } }));
- }
- });
- test('missing explicit device fails before invoking ADB', () => {
- assert.throws(() => captureNativeScreenshot('fixture.png', '', { run() { assert.fail('must not run'); } }));
- });
|