mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Convert the scanner's plist parser and Node-style file shim to TypeScript and add small unit tests so common parser and file-reader failures are caught before we need to lean on Playwright or the higher-level scanner test. Constraint: Must preserve current scanner behavior while tightening the lowest-level helper surface Rejected: Jump straight to Mach-O parser conversion | harder to isolate regressions without first proving the smaller helper-test pattern Confidence: high Scope-risk: narrow Reversibility: clean Directive: Add small module-level regression tests for repeatable scanner breakage before expanding browser coverage Tested: pnpm run typecheck; pnpm exec vitest run test/scanner/plist.test.ts test/scanner/file-api.test.ts test/scanner/client.test.ts; pnpm run test; pnpm run test:browser Not-tested: Production deploy behavior prior to push
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { Buffer } from 'buffer'
|
|
|
|
import {
|
|
describe,
|
|
expect,
|
|
it,
|
|
vi
|
|
} from 'vitest'
|
|
|
|
import {
|
|
parseFileSync,
|
|
parsePlistBuffer
|
|
} from '~/helpers/scanner/parsers/plist'
|
|
|
|
type ParsedPlist = Record<string, string>
|
|
|
|
const xmlPlist = Buffer.from( [
|
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
'<plist version="1.0">',
|
|
'<dict>',
|
|
' <key>CFBundleExecutable</key>',
|
|
' <string>Playwright Native App</string>',
|
|
' <key>CFBundleIdentifier</key>',
|
|
' <string>com.doesitarm.playwright-native-app</string>',
|
|
'</dict>',
|
|
'</plist>'
|
|
].join( '\n' ), 'utf8' )
|
|
|
|
describe( 'plist parser', () => {
|
|
it( 'parses xml plist buffers asynchronously', async () => {
|
|
const callback = vi.fn()
|
|
const plist = await parsePlistBuffer( xmlPlist as any, callback ) as ParsedPlist
|
|
|
|
expect( plist.CFBundleExecutable ).toBe( 'Playwright Native App' )
|
|
expect( plist.CFBundleIdentifier ).toBe( 'com.doesitarm.playwright-native-app' )
|
|
expect( callback ).toHaveBeenCalledWith( null, plist )
|
|
} )
|
|
|
|
it( 'parses xml plist buffers synchronously', () => {
|
|
const plist = parseFileSync( xmlPlist as any ) as ParsedPlist
|
|
|
|
expect( plist.CFBundleExecutable ).toBe( 'Playwright Native App' )
|
|
expect( plist.CFBundleIdentifier ).toBe( 'com.doesitarm.playwright-native-app' )
|
|
} )
|
|
|
|
it( 'rejects invalid plist data', async () => {
|
|
await expect( parsePlistBuffer( Buffer.from( 'not-a-plist', 'utf8' ) as any ) )
|
|
.rejects
|
|
.toThrow( /Invalid binary plist/i )
|
|
} )
|
|
} )
|