@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
22import { describe , it } from "node:test" ;
33import path from "node:path" ;
44import fs from "node:fs" ;
5+ import { AssertionError } from "node:assert" ;
56
67import {
78 determineInfoPlistPath ,
@@ -87,10 +88,13 @@ describe("apple", () => {
8788 } ) ;
8889
8990 describe ( "updateInfoPlist" , ( ) => {
90- it ( "updates an xml plist" , async ( context ) => {
91- const infoPlistSubPath = "Info.plist" ;
92- const tempDirectoryPath = setupTempDirectory ( context , {
93- [ infoPlistSubPath ] : `
91+ it (
92+ "updates an xml plist" ,
93+ { skip : process . platform !== "darwin" } ,
94+ async ( context ) => {
95+ const infoPlistSubPath = "Info.plist" ;
96+ const tempDirectoryPath = setupTempDirectory ( context , {
97+ [ infoPlistSubPath ] : `
9498 <?xml version="1.0" encoding="UTF-8"?>
9599 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
96100 <plist version="1.0">
@@ -100,47 +104,81 @@ describe("apple", () => {
100104 </dict>
101105 </plist>
102106 ` ,
103- } ) ;
104-
105- await updateInfoPlist ( {
106- frameworkPath : tempDirectoryPath ,
107- oldLibraryName : "addon" ,
108- newLibraryName : "new-addon-name" ,
109- } ) ;
110-
111- const contents = await fs . promises . readFile (
112- path . join ( tempDirectoryPath , infoPlistSubPath ) ,
113- "utf-8" ,
114- ) ;
115- assert . match ( contents , / < \? x m l v e r s i o n = " 1 .0 " e n c o d i n g = " U T F - 8 " \? > / ) ;
116- assert . match (
117- contents ,
118- / < k e y > C F B u n d l e E x e c u t a b l e < \/ k e y > \s * < s t r i n g > n e w - a d d o n - n a m e < \/ s t r i n g > / ,
119- ) ;
120- } ) ;
121-
122- it ( "converts a binary plist to xml" , async ( context ) => {
123- const tempDirectoryPath = setupTempDirectory ( context , { } ) ;
124- // Write a binary plist file
125- const binaryPlistContents = Buffer . from (
126- "YnBsaXN0MDDfEBUBAgMEBQYHCAkKCwwNDg8QERITFBUWF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eFile ( binaryPlistPath , binaryPlistContents ) ;
131-
132- await updateInfoPlist ( {
133- frameworkPath : tempDirectoryPath ,
134- oldLibraryName : "addon" ,
135- newLibraryName : "new-addon-name" ,
136- } ) ;
137-
138- const contents = await fs . promises . readFile ( binaryPlistPath , "utf-8" ) ;
139- assert . match ( contents , / < \? x m l v e r s i o n = " 1 .0 " e n c o d i n g = " U T F - 8 " \? > / ) ;
140- assert . match (
141- contents ,
142- / < k e y > C F B u n d l e E x e c u t a b l e < \/ k e y > \s * < s t r i n g > n e w - a d d o n - n a m e < \/ s t r i n g > / ,
143- ) ;
144- } ) ;
107+ } ) ;
108+
109+ await updateInfoPlist ( {
110+ frameworkPath : tempDirectoryPath ,
111+ oldLibraryName : "addon" ,
112+ newLibraryName : "new-addon-name" ,
113+ } ) ;
114+
115+ const contents = await fs . promises . readFile (
116+ path . join ( tempDirectoryPath , infoPlistSubPath ) ,
117+ "utf-8" ,
118+ ) ;
119+ assert . match ( contents , / < \? x m l v e r s i o n = " 1 .0 " e n c o d i n g = " U T F - 8 " \? > / ) ;
120+ assert . match (
121+ contents ,
122+ / < k e y > C F B u n d l e E x e c u t a b l e < \/ k e y > \s * < s t r i n g > n e w - a d d o n - n a m e < \/ s t r i n g > / ,
123+ ) ;
124+ } ,
125+ ) ;
126+
127+ it (
128+ "converts a binary plist to xml" ,
129+ { skip : process . platform !== "darwin" } ,
130+ async ( context ) => {
131+ const tempDirectoryPath = setupTempDirectory ( context , { } ) ;
132+ // Write a binary plist file
133+ const binaryPlistContents = Buffer . from (
134+ "YnBsaXN0MDDfEBUBAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4cICEiIyQiJSYnJChfEBNCdWlsZE1hY2hpbmVPU0J1aWxkXxAZQ0ZCdW5kbGVEZXZlbG9wbWVudFJlZ2lvbl8QEkNGQnVuZGxlRXhlY3V0YWJsZV8QEkNGQnVuZGxlSWRlbnRpZmllcl8QHUNGQnVuZGxlSW5mb0RpY3Rpb25hcnlWZXJzaW9uXxATQ0ZCdW5kbGVQYWNrYWdlVHlwZV8QGkNGQnVuZGxlU2hvcnRWZXJzaW9uU3RyaW5nXxARQ0ZCdW5kbGVTaWduYXR1cmVfEBpDRkJ1bmRsZVN1cHBvcnRlZFBsYXRmb3Jtc18QD0NGQnVuZGxlVmVyc2lvbl8QFUNTUmVzb3VyY2VzRmlsZU1hcHBlZFpEVENvbXBpbGVyXxAPRFRQbGF0Zm9ybUJ1aWxkXkRUUGxhdGZvcm1OYW1lXxARRFRQbGF0Zm9ybVZlcnNpb25aRFRTREtCdWlsZFlEVFNES05hbWVXRFRYY29kZVxEVFhjb2RlQnVpbGRfEBBNaW5pbXVtT1NWZXJzaW9uXlVJRGV2aWNlRmFtaWx5VjI0RzIzMVdFbmdsaXNoVWFkZG9uXxAPZXhhbXBsZV82LmFkZG9uUzYuMFRGTVdLUzEuMFQ/Pz8/oR9fEA9pUGhvbmVTaW11bGF0b3IJXxAiY29tLmFwcGxlLmNvbXBpbGVycy5sbHZtLmNsYW5nLjFfMFYyMkMxNDZfEA9pcGhvbmVzaW11bGF0b3JUMTguMl8QE2lwaG9uZXNpbXVsYXRvcjE4LjJUMTYyMFgxNkM1MDMyYaEpEAEACAA1AEsAZwB8AJEAsQDHAOQA+AEVAScBPwFKAVwBawF/AYoBlAGcAakBvAHLAdIB2gHgAfIB9gH7Af8CBAIGAhgCGQI+AkUCVwJcAnICdwKAAoIAAAAAAAACAQAAAAAAAAAqAAAAAAAAAAAAAAAAAAAChA==" ,
135+ "base64" ,
136+ ) ;
137+ const binaryPlistPath = path . join ( tempDirectoryPath , "Info.plist" ) ;
138+ await fs . promises . writeFile ( binaryPlistPath , binaryPlistContents ) ;
139+
140+ await updateInfoPlist ( {
141+ frameworkPath : tempDirectoryPath ,
142+ oldLibraryName : "addon" ,
143+ newLibraryName : "new-addon-name" ,
144+ } ) ;
145+
146+ const contents = await fs . promises . readFile ( binaryPlistPath , "utf-8" ) ;
147+ assert . match ( contents , / < \? x m l v e r s i o n = " 1 .0 " e n c o d i n g = " U T F - 8 " \? > / ) ;
148+ assert . match (
149+ contents ,
150+ / < k e y > C F B u n d l e E x e c u t a b l e < \/ k e y > \s * < s t r i n g > n e w - a d d o n - n a m e < \/ s t r i n g > / ,
151+ ) ;
152+ } ,
153+ ) ;
154+
155+ it (
156+ "throws when not on darwin" ,
157+ { skip : process . platform === "darwin" } ,
158+ async ( context ) => {
159+ const tempDirectoryPath = setupTempDirectory ( context , {
160+ [ "Info.plist" ] : '<?xml version="1.0" encoding="UTF-8"?>' ,
161+ } ) ;
162+
163+ await assert . rejects (
164+ ( ) =>
165+ updateInfoPlist ( {
166+ frameworkPath : tempDirectoryPath ,
167+ oldLibraryName : "addon" ,
168+ newLibraryName : "new-addon-name" ,
169+ } ) ,
170+ ( err ) => {
171+ assert ( err instanceof Error ) ;
172+ assert . match ( err . message , / F a i l e d t o c o n v e r t I n f o .p l i s t a t p a t h / ) ;
173+ assert ( err . cause instanceof Error ) ;
174+ assert . match (
175+ err . cause . message ,
176+ / U p d a t i n g I n f o .p l i s t f i l e s a r e n o t s u p p o r t e d o n t h i s p l a t f o r m / ,
177+ ) ;
178+ return true ;
179+ } ,
180+ ) ;
181+ } ,
182+ ) ;
145183 } ) ;
146184} ) ;
0 commit comments