import { Buffer } from 'buffer' import { describe, expect, it, vi } from 'vitest' import { parseFileSync, parsePlistBuffer } from '~/helpers/scanner/parsers/plist-parser' type ParsedPlist = Record const xmlPlist = Buffer.from( [ '', '', '', '', ' CFBundleExecutable', ' Playwright Native App', ' CFBundleIdentifier', ' com.doesitarm.playwright-native-app', '', '' ].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 ) } ) } )