|
1 | | -import * as cp from 'child_process' |
2 | | -import * as path from 'path' |
3 | | -import * as process from 'process' |
| 1 | +import * as cp from 'node:child_process' |
| 2 | +import * as path from 'node:path' |
| 3 | +import * as process from 'node:process' |
| 4 | +import {expect, test} from 'vitest' |
4 | 5 |
|
5 | 6 | // The available iOS device lineup shifts as the CI runner's Xcode version |
6 | 7 | // changes, so a hardcoded model (e.g. a fixed "iPhone 16") can disappear. |
@@ -29,39 +30,60 @@ function findAnyAvailableIOSModel(): string { |
29 | 30 | ) |
30 | 31 | } |
31 | 32 |
|
32 | | -test('boots a device', () => { |
33 | | - process.env['INPUT_OS_VERSION'] = '>=10.0' |
34 | | - const nodeProcess = process.execPath |
35 | | - const actionMain = path.join(__dirname, '..', 'lib', 'main.js') |
36 | | - const options: cp.ExecFileSyncOptions = { |
37 | | - env: process.env |
38 | | - } |
| 33 | +test.runIf(process.platform === 'darwin')( |
| 34 | + 'boots a device', |
| 35 | + () => { |
| 36 | + try { |
| 37 | + process.env['INPUT_OS_VERSION'] = '>=17.0' |
| 38 | + const nodeProcess = process.execPath |
| 39 | + const actionMain = path.join( |
| 40 | + import.meta.dirname, |
| 41 | + '..', |
| 42 | + 'dist', |
| 43 | + 'index.js' |
| 44 | + ) |
| 45 | + const options: cp.ExecFileSyncOptions = { |
| 46 | + env: process.env |
| 47 | + } |
39 | 48 |
|
40 | | - const firstRunOutput = cp |
41 | | - .execFileSync(nodeProcess, [actionMain], options) |
42 | | - .toString() |
43 | | - expect(firstRunOutput).toContain('Booting device') |
44 | | - expect(firstRunOutput).not.toContain('Waiting for the Simulator to settle') |
| 49 | + const firstRunOutput = cp |
| 50 | + .execFileSync(nodeProcess, [actionMain], options) |
| 51 | + .toString() |
| 52 | + expect(firstRunOutput).toContain('Booting device') |
| 53 | + expect(firstRunOutput).not.toContain( |
| 54 | + 'Waiting for the Simulator to settle' |
| 55 | + ) |
45 | 56 |
|
46 | | - // lower-cased on purpose: also exercises the case-insensitive model match |
47 | | - process.env['INPUT_MODEL'] = findAnyAvailableIOSModel().toLowerCase() |
48 | | - expect( |
49 | | - cp.execFileSync(nodeProcess, [actionMain], options).toString() |
50 | | - ).toContain('Booting device') |
| 57 | + // lower-cased on purpose: also exercises the case-insensitive model match |
| 58 | + process.env['INPUT_MODEL'] = findAnyAvailableIOSModel().toLowerCase() |
| 59 | + expect( |
| 60 | + cp.execFileSync(nodeProcess, [actionMain], options).toString() |
| 61 | + ).toContain('Booting device') |
51 | 62 |
|
52 | | - process.env['INPUT_WAIT_FOR_BOOT'] = 'true' |
53 | | - expect( |
54 | | - cp.execFileSync(nodeProcess, [actionMain], options).toString() |
55 | | - ).toContain('Waiting for device to finish booting') |
| 63 | + process.env['INPUT_WAIT_FOR_BOOT'] = 'true' |
| 64 | + expect( |
| 65 | + cp.execFileSync(nodeProcess, [actionMain], options).toString() |
| 66 | + ).toContain('Waiting for device to finish booting') |
56 | 67 |
|
57 | | - process.env['INPUT_SETTLE_TIMEOUT_SECONDS'] = '5' |
58 | | - process.env['INPUT_SETTLE_CHECK_INTERVAL_SECONDS'] = '1' |
59 | | - expect( |
60 | | - cp.execFileSync(nodeProcess, [actionMain], options).toString() |
61 | | - ).toContain('Waiting for the Simulator to settle') |
62 | | - delete process.env['INPUT_SETTLE_TIMEOUT_SECONDS'] |
63 | | - delete process.env['INPUT_SETTLE_CHECK_INTERVAL_SECONDS'] |
| 68 | + process.env['INPUT_SETTLE_TIMEOUT_SECONDS'] = '5' |
| 69 | + process.env['INPUT_SETTLE_CHECK_INTERVAL_SECONDS'] = '1' |
| 70 | + expect( |
| 71 | + cp.execFileSync(nodeProcess, [actionMain], options).toString() |
| 72 | + ).toContain('Waiting for the Simulator to settle') |
| 73 | + delete process.env['INPUT_SETTLE_TIMEOUT_SECONDS'] |
| 74 | + delete process.env['INPUT_SETTLE_CHECK_INTERVAL_SECONDS'] |
64 | 75 |
|
65 | | - process.env['INPUT_MODEL'] = 'Pixel 4' |
66 | | - expect(() => cp.execFileSync(nodeProcess, [actionMain], options)).toThrow() |
67 | | -}) |
| 76 | + process.env['INPUT_MODEL'] = 'Pixel 4' |
| 77 | + expect(() => |
| 78 | + cp.execFileSync(nodeProcess, [actionMain], options) |
| 79 | + ).toThrow() |
| 80 | + } finally { |
| 81 | + delete process.env['INPUT_OS_VERSION'] |
| 82 | + delete process.env['INPUT_MODEL'] |
| 83 | + delete process.env['INPUT_WAIT_FOR_BOOT'] |
| 84 | + delete process.env['INPUT_SETTLE_TIMEOUT_SECONDS'] |
| 85 | + delete process.env['INPUT_SETTLE_CHECK_INTERVAL_SECONDS'] |
| 86 | + } |
| 87 | + }, |
| 88 | + 600_000 |
| 89 | +) |
0 commit comments