-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapple.test.ts
More file actions
184 lines (165 loc) · 6.99 KB
/
apple.test.ts
File metadata and controls
184 lines (165 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import path from "node:path";
import fs from "node:fs";
import {
determineInfoPlistPath,
readInfoPlist,
updateInfoPlist,
} from "./apple";
import { setupTempDirectory } from "../test-utils";
describe("apple", () => {
describe("determineInfoPlistPath", () => {
it("should find Info.plist files in unversioned frameworks", (context) => {
const infoPlistContents = `<?xml version="1.0" encoding="UTF-8"?>...`;
const infoPlistSubPath = "Info.plist";
const tempDirectoryPath = setupTempDirectory(context, {
[infoPlistSubPath]: infoPlistContents,
});
assert.strictEqual(
determineInfoPlistPath(tempDirectoryPath),
path.join(tempDirectoryPath, infoPlistSubPath),
);
});
it("should find Info.plist files in versioned frameworks", (context) => {
const infoPlistContents = `<?xml version="1.0" encoding="UTF-8"?>...`;
const infoPlistSubPath = "Versions/Current/Resources/Info.plist";
const tempDirectoryPath = setupTempDirectory(context, {
[infoPlistSubPath]: infoPlistContents,
});
assert.strictEqual(
determineInfoPlistPath(tempDirectoryPath),
path.join(tempDirectoryPath, infoPlistSubPath),
);
});
it("should throw if Info.plist is missing from framework", (context) => {
const tempDirectoryPath = setupTempDirectory(context, {});
assert.throws(
() => determineInfoPlistPath(tempDirectoryPath),
/Unable to locate an Info.plist file within framework./,
);
});
});
describe("readInfoPlist", () => {
it("should read Info.plist contents", async (context) => {
const infoPlistContents = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>ExecutableFileName</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
</dict>
</plist>
`;
const infoPlistSubPath = "Info.plist";
const tempDirectoryPath = setupTempDirectory(context, {
[infoPlistSubPath]: infoPlistContents,
});
const infoPlistPath = path.join(tempDirectoryPath, infoPlistSubPath);
const contents = await readInfoPlist(infoPlistPath);
assert.deepEqual(contents, {
CFBundleExecutable: "ExecutableFileName",
CFBundleIconFile: "AppIcon",
});
});
it("should throw if Info.plist doesn't exist", async (context) => {
const tempDirectoryPath = setupTempDirectory(context, {});
const infoPlistPath = path.join(tempDirectoryPath, "Info.plist");
await assert.rejects(
() => readInfoPlist(infoPlistPath),
/Unable to read Info.plist at path/,
);
});
});
describe("updateInfoPlist", () => {
it(
"updates an xml plist",
{ skip: process.platform !== "darwin" },
async (context) => {
const infoPlistSubPath = "Info.plist";
const tempDirectoryPath = setupTempDirectory(context, {
[infoPlistSubPath]: `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>addon</string>
</dict>
</plist>
`,
});
await updateInfoPlist({
frameworkPath: tempDirectoryPath,
oldLibraryName: "addon",
newLibraryName: "new-addon-name",
});
const contents = await fs.promises.readFile(
path.join(tempDirectoryPath, infoPlistSubPath),
"utf-8",
);
assert.match(contents, /<\?xml version="1.0" encoding="UTF-8"\?>/);
assert.match(
contents,
/<key>CFBundleExecutable<\/key>\s*<string>new-addon-name<\/string>/,
);
},
);
it(
"converts a binary plist to xml",
{ skip: process.platform !== "darwin" },
async (context) => {
const tempDirectoryPath = setupTempDirectory(context, {});
// Write a binary plist file
const binaryPlistContents = Buffer.from(
// Generated running "base64 -i <path-to-binary-plist>" on a plist file from a framework in the node-examples package
"YnBsaXN0MDDfEBUBAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4cICEiIyQiJSYnJChfEBNCdWlsZE1hY2hpbmVPU0J1aWxkXxAZQ0ZCdW5kbGVEZXZlbG9wbWVudFJlZ2lvbl8QEkNGQnVuZGxlRXhlY3V0YWJsZV8QEkNGQnVuZGxlSWRlbnRpZmllcl8QHUNGQnVuZGxlSW5mb0RpY3Rpb25hcnlWZXJzaW9uXxATQ0ZCdW5kbGVQYWNrYWdlVHlwZV8QGkNGQnVuZGxlU2hvcnRWZXJzaW9uU3RyaW5nXxARQ0ZCdW5kbGVTaWduYXR1cmVfEBpDRkJ1bmRsZVN1cHBvcnRlZFBsYXRmb3Jtc18QD0NGQnVuZGxlVmVyc2lvbl8QFUNTUmVzb3VyY2VzRmlsZU1hcHBlZFpEVENvbXBpbGVyXxAPRFRQbGF0Zm9ybUJ1aWxkXkRUUGxhdGZvcm1OYW1lXxARRFRQbGF0Zm9ybVZlcnNpb25aRFRTREtCdWlsZFlEVFNES05hbWVXRFRYY29kZVxEVFhjb2RlQnVpbGRfEBBNaW5pbXVtT1NWZXJzaW9uXlVJRGV2aWNlRmFtaWx5VjI0RzIzMVdFbmdsaXNoVWFkZG9uXxAPZXhhbXBsZV82LmFkZG9uUzYuMFRGTVdLUzEuMFQ/Pz8/oR9fEA9pUGhvbmVTaW11bGF0b3IJXxAiY29tLmFwcGxlLmNvbXBpbGVycy5sbHZtLmNsYW5nLjFfMFYyMkMxNDZfEA9pcGhvbmVzaW11bGF0b3JUMTguMl8QE2lwaG9uZXNpbXVsYXRvcjE4LjJUMTYyMFgxNkM1MDMyYaEpEAEACAA1AEsAZwB8AJEAsQDHAOQA+AEVAScBPwFKAVwBawF/AYoBlAGcAakBvAHLAdIB2gHgAfIB9gH7Af8CBAIGAhgCGQI+AkUCVwJcAnICdwKAAoIAAAAAAAACAQAAAAAAAAAqAAAAAAAAAAAAAAAAAAAChA==",
"base64",
);
const binaryPlistPath = path.join(tempDirectoryPath, "Info.plist");
await fs.promises.writeFile(binaryPlistPath, binaryPlistContents);
await updateInfoPlist({
frameworkPath: tempDirectoryPath,
oldLibraryName: "addon",
newLibraryName: "new-addon-name",
});
const contents = await fs.promises.readFile(binaryPlistPath, "utf-8");
assert.match(contents, /<\?xml version="1.0" encoding="UTF-8"\?>/);
assert.match(
contents,
/<key>CFBundleExecutable<\/key>\s*<string>new-addon-name<\/string>/,
);
},
);
it(
"throws when not on darwin",
{ skip: process.platform === "darwin" },
async (context) => {
const tempDirectoryPath = setupTempDirectory(context, {
["Info.plist"]: '<?xml version="1.0" encoding="UTF-8"?>',
});
await assert.rejects(
() =>
updateInfoPlist({
frameworkPath: tempDirectoryPath,
oldLibraryName: "addon",
newLibraryName: "new-addon-name",
}),
(err) => {
assert(err instanceof Error);
assert.match(err.message, /Failed to convert Info.plist at path/);
assert(err.cause instanceof Error);
assert.match(
err.cause.message,
/Updating Info.plist files are not supported on this platform/,
);
return true;
},
);
},
);
});
});