Skip to content

Commit edb09ca

Browse files
committed
Add tests for restoreFrameworkLinks
1 parent e66133c commit edb09ca

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

packages/host/src/node/cli/apple.test.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
readAndParsePlist,
1010
readFrameworkInfo,
1111
readXcframeworkInfo,
12+
restoreFrameworkLinks,
1213
} from "./apple";
1314
import { setupTempDirectory } from "../test-utils";
1415

@@ -267,6 +268,109 @@ describe("apple", { skip: process.platform !== "darwin" }, () => {
267268
);
268269
});
269270
});
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+
});
270374
});
271375

272376
describe("apple on non-darwin", { skip: process.platform === "darwin" }, () => {

0 commit comments

Comments
 (0)