also looking at this
Test the built native CLI startup in CI
#317
3 files
+54
-2
| @@ -0,0 +1,27 @@ | ||
| 1 | import { afterEach, expect, test } from 'bun:test' | |
| 2 | import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' | |
| 3 | import { tmpdir } from 'node:os' | |
| 4 | import { join } from 'node:path' | |
| 5 | import { verifyNativeStartup } from './verify-native-startup' | |
| 6 | ||
| 7 | const roots: string[] = [] | |
| 8 | afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }) }) | |
| 9 | ||
| 10 | function executable(body: string): string { | |
| 11 | const root = mkdtempSync(join(tmpdir(), 'craft-native-startup-test-')) | |
| 12 | roots.push(root) | |
| 13 | const path = join(root, 'craft') | |
| 14 | writeFileSync(path, `#!/bin/sh\n${body}\n`) | |
| 15 | chmodSync(path, 0o755) | |
| 16 | return path | |
| 17 | } | |
| 18 | ||
| 19 | test('accepts a running native CLI with the requested version', () => { | |
| 20 | expect(() => verifyNativeStartup(executable("printf 'craft version 1.2.3\\nBuilt with Zig\\n'"), '1.2.3')).not.toThrow() | |
| 21 | }) | |
| 22 | ||
| 23 | test('rejects a stale binary, startup failure, and missing executable', () => { | |
| 24 | expect(() => verifyNativeStartup(executable("printf 'craft version 1.2.2\\n'"), '1.2.3')).toThrow('reported') | |
| 25 | expect(() => verifyNativeStartup(executable('exit 7'), '1.2.3')).toThrow('failed to start') | |
| 26 | expect(() => verifyNativeStartup('/path/that/does/not/exist', '1.2.3')).toThrow() | |
| 27 | }) | |