Skip to content

Commit 57496a5

Browse files
committed
Add tests for restoreFrameworkLinks
1 parent e66133c commit 57496a5

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

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

Lines changed: 94 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,99 @@ 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+
await restoreFrameworkLinks(frameworkPath);
317+
318+
const currentStat = await fs.promises.lstat(currentVersionPath);
319+
assert(
320+
currentStat.isSymbolicLink(),
321+
"Expected Current symlink to be restored",
322+
);
323+
assert.equal(
324+
await fs.promises.realpath(currentVersionPath),
325+
path.join(frameworkPath, "Versions", "A"),
326+
);
327+
328+
const binaryStat = await fs.promises.lstat(binaryLinkPath);
329+
assert(
330+
binaryStat.isSymbolicLink(),
331+
"Expected binary symlink to be restored",
332+
);
333+
assert.equal(await fs.promises.realpath(binaryLinkPath), realBinaryPath);
334+
});
335+
336+
it("throws on a flat framework", async (context) => {
337+
const tempDirectoryPath = setupTempDirectory(context, {
338+
"foo.framework": {
339+
"Info.plist": `
340+
<?xml version="1.0" encoding="UTF-8"?>
341+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
342+
<plist version="1.0">
343+
<dict>
344+
<key>CFBundlePackageType</key>
345+
<string>FMWK</string>
346+
<key>CFBundleInfoDictionaryVersion</key>
347+
<string>6.0</string>
348+
<key>CFBundleExecutable</key>
349+
<string>example-addon</string>
350+
</dict>
351+
</plist>
352+
`,
353+
},
354+
});
355+
356+
const frameworkPath = path.join(tempDirectoryPath, "foo.framework");
357+
358+
await assert.rejects(
359+
() => restoreFrameworkLinks(frameworkPath),
360+
/Expected "Versions" directory inside versioned framework/,
361+
);
362+
});
363+
});
270364
});
271365

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

0 commit comments

Comments
 (0)