|
| 1 | +import { test } from 'vitest'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import { normalizeOpenDevice } from '../client-normalizers.ts'; |
| 4 | +import { PLATFORMS } from '../utils/device.ts'; |
| 5 | + |
| 6 | +test('normalizeOpenDevice accepts exactly the canonical leaf platforms', () => { |
| 7 | + for (const platform of PLATFORMS) { |
| 8 | + const result = normalizeOpenDevice({ |
| 9 | + platform, |
| 10 | + id: 'device-1', |
| 11 | + device: 'Device One', |
| 12 | + }); |
| 13 | + assert.ok(result, `expected platform "${platform}" to be accepted`); |
| 14 | + assert.equal(result.platform, platform); |
| 15 | + } |
| 16 | + // Lock the membership so the derived check cannot silently widen/narrow. |
| 17 | + assert.deepEqual([...PLATFORMS], ['ios', 'macos', 'android', 'linux', 'web']); |
| 18 | +}); |
| 19 | + |
| 20 | +test('normalizeOpenDevice rejects the apple selector and unknown platforms', () => { |
| 21 | + // `apple` is a selector, not a concrete device platform, so it must be rejected here. |
| 22 | + assert.equal( |
| 23 | + normalizeOpenDevice({ platform: 'apple', id: 'device-1', device: 'Device One' }), |
| 24 | + undefined, |
| 25 | + ); |
| 26 | + assert.equal( |
| 27 | + normalizeOpenDevice({ platform: 'windows', id: 'device-1', device: 'Device One' }), |
| 28 | + undefined, |
| 29 | + ); |
| 30 | + assert.equal( |
| 31 | + normalizeOpenDevice({ platform: undefined, id: 'device-1', device: 'Device One' }), |
| 32 | + undefined, |
| 33 | + ); |
| 34 | +}); |
| 35 | + |
| 36 | +test('normalizeOpenDevice preserves per-platform identifier shaping', () => { |
| 37 | + const ios = normalizeOpenDevice({ |
| 38 | + platform: 'ios', |
| 39 | + id: 'udid-1', |
| 40 | + device: 'iPhone', |
| 41 | + ios_simulator_device_set: '/tmp/set', |
| 42 | + }); |
| 43 | + assert.deepEqual(ios?.ios, { udid: 'udid-1', simulatorSetPath: '/tmp/set' }); |
| 44 | + assert.equal(ios?.android, undefined); |
| 45 | + |
| 46 | + const android = normalizeOpenDevice({ |
| 47 | + platform: 'android', |
| 48 | + id: 'serial-1', |
| 49 | + device: 'Pixel', |
| 50 | + serial: 'explicit-serial', |
| 51 | + }); |
| 52 | + assert.deepEqual(android?.android, { serial: 'explicit-serial' }); |
| 53 | + assert.equal(android?.ios, undefined); |
| 54 | +}); |
0 commit comments