|
9 | 9 | readAndParsePlist, |
10 | 10 | readFrameworkInfo, |
11 | 11 | readXcframeworkInfo, |
| 12 | + restoreFrameworkLinks, |
12 | 13 | } from "./apple"; |
13 | 14 | import { setupTempDirectory } from "../test-utils"; |
14 | 15 |
|
@@ -267,6 +268,109 @@ describe("apple", { skip: process.platform !== "darwin" }, () => { |
267 | 268 | ); |
268 | 269 | }); |
269 | 270 | }); |
| 271 | + |
| 272 | + describe("restoreFrameworkLinks", () => { |
| 273 | + it("restores a versioned framework", async (context) => { |
| 274 | + const infoPlistContents = ` |
| 275 | + <?xml version="1.0" encoding="UTF-8"?> |
| 276 | + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 277 | + <plist version="1.0"> |
| 278 | + <dict> |
| 279 | + <key>CFBundlePackageType</key> |
| 280 | + <string>FMWK</string> |
| 281 | + <key>CFBundleInfoDictionaryVersion</key> |
| 282 | + <string>6.0</string> |
| 283 | + <key>CFBundleExecutable</key> |
| 284 | + <string>example-addon</string> |
| 285 | + </dict> |
| 286 | + </plist> |
| 287 | + `; |
| 288 | + |
| 289 | + const tempDirectoryPath = setupTempDirectory(context, { |
| 290 | + "foo.framework": { |
| 291 | + Versions: { |
| 292 | + A: { |
| 293 | + Resources: { |
| 294 | + "Info.plist": infoPlistContents, |
| 295 | + }, |
| 296 | + "example-addon": "", |
| 297 | + }, |
| 298 | + }, |
| 299 | + }, |
| 300 | + }); |
| 301 | + |
| 302 | + const frameworkPath = path.join(tempDirectoryPath, "foo.framework"); |
| 303 | + const currentVersionPath = path.join( |
| 304 | + frameworkPath, |
| 305 | + "Versions", |
| 306 | + "Current", |
| 307 | + ); |
| 308 | + const binaryLinkPath = path.join(frameworkPath, "example-addon"); |
| 309 | + const realBinaryPath = path.join( |
| 310 | + frameworkPath, |
| 311 | + "Versions", |
| 312 | + "A", |
| 313 | + "example-addon", |
| 314 | + ); |
| 315 | + |
| 316 | + async function assertVersionedFramework() { |
| 317 | + const currentStat = await fs.promises.lstat(currentVersionPath); |
| 318 | + assert( |
| 319 | + currentStat.isSymbolicLink(), |
| 320 | + "Expected Current symlink to be restored", |
| 321 | + ); |
| 322 | + assert.equal( |
| 323 | + await fs.promises.realpath(currentVersionPath), |
| 324 | + path.join(frameworkPath, "Versions", "A"), |
| 325 | + ); |
| 326 | + |
| 327 | + const binaryStat = await fs.promises.lstat(binaryLinkPath); |
| 328 | + assert( |
| 329 | + binaryStat.isSymbolicLink(), |
| 330 | + "Expected binary symlink to be restored", |
| 331 | + ); |
| 332 | + assert.equal( |
| 333 | + await fs.promises.realpath(binaryLinkPath), |
| 334 | + realBinaryPath, |
| 335 | + ); |
| 336 | + } |
| 337 | + |
| 338 | + await restoreFrameworkLinks(frameworkPath); |
| 339 | + await assertVersionedFramework(); |
| 340 | + |
| 341 | + // Calling again to expect a no-op |
| 342 | + await restoreFrameworkLinks(frameworkPath); |
| 343 | + await assertVersionedFramework(); |
| 344 | + }); |
| 345 | + |
| 346 | + it("throws on a flat framework", async (context) => { |
| 347 | + const tempDirectoryPath = setupTempDirectory(context, { |
| 348 | + "foo.framework": { |
| 349 | + "Info.plist": ` |
| 350 | + <?xml version="1.0" encoding="UTF-8"?> |
| 351 | + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 352 | + <plist version="1.0"> |
| 353 | + <dict> |
| 354 | + <key>CFBundlePackageType</key> |
| 355 | + <string>FMWK</string> |
| 356 | + <key>CFBundleInfoDictionaryVersion</key> |
| 357 | + <string>6.0</string> |
| 358 | + <key>CFBundleExecutable</key> |
| 359 | + <string>example-addon</string> |
| 360 | + </dict> |
| 361 | + </plist> |
| 362 | + `, |
| 363 | + }, |
| 364 | + }); |
| 365 | + |
| 366 | + const frameworkPath = path.join(tempDirectoryPath, "foo.framework"); |
| 367 | + |
| 368 | + await assert.rejects( |
| 369 | + () => restoreFrameworkLinks(frameworkPath), |
| 370 | + /Expected "Versions" directory inside versioned framework/, |
| 371 | + ); |
| 372 | + }); |
| 373 | + }); |
270 | 374 | }); |
271 | 375 |
|
272 | 376 | describe("apple on non-darwin", { skip: process.platform === "darwin" }, () => { |
|
0 commit comments