mirror of
https://github.com/morluto/rea.git
synced 2026-10-26 17:35:11 +00:00
perf(tests): share native Interface Builder encoding production
This commit is contained in:
1 parent
78f8eca531
commit
aedd394471
1 file changed
+50
-10
+50
-10
@@ -44,6 +44,49 @@ const oracleSchema = z.strictObject({
|
||||
});
|
||||
type Oracle = z.infer<typeof oracleSchema>;
|
||||
|
||||
interface NativeEncodingFixtures {
|
||||
readonly archives: ReadonlyMap<Encoding, Buffer>;
|
||||
readonly oracle: Oracle;
|
||||
}
|
||||
|
||||
// Retain only native-produced data in this worker, never paths owned by a test.
|
||||
// Consumers copy buffers and the oracle so one case cannot alter later inputs.
|
||||
let nativeEncodingFixtures: Promise<NativeEncodingFixtures> | undefined;
|
||||
|
||||
const produceNativeEncodingFixtures =
|
||||
async (): Promise<NativeEncodingFixtures> => {
|
||||
const directory = await createTestTempDirectory("rea-ib-native-encodings-");
|
||||
await promisify(execFile)("/usr/bin/xcrun", [
|
||||
"swift",
|
||||
"tests/conformance/native/interface-builder-encoding.swift",
|
||||
directory,
|
||||
]);
|
||||
const oracle = oracleSchema.parse(
|
||||
JSON.parse(await readFile(join(directory, "oracle.json"), "utf8")),
|
||||
);
|
||||
const archives = new Map(
|
||||
await Promise.all(
|
||||
[...interfaceBuilderEncodings, ...invalidInterfaceBuilderEncodings].map(
|
||||
async (encoding) =>
|
||||
[
|
||||
encoding,
|
||||
await readFile(join(directory, `${encoding}.nib`)),
|
||||
] as const,
|
||||
),
|
||||
),
|
||||
);
|
||||
return { archives, oracle };
|
||||
};
|
||||
|
||||
const readNativeEncodingFixtures = (): Promise<NativeEncodingFixtures> =>
|
||||
(nativeEncodingFixtures ??= produceNativeEncodingFixtures().catch(
|
||||
(cause: unknown) => {
|
||||
// A failed or partial native run cannot serve another case.
|
||||
nativeEncodingFixtures = undefined;
|
||||
throw cause;
|
||||
},
|
||||
));
|
||||
|
||||
/** Check actual NSView identities and links from the independent Foundation oracle. */
|
||||
const expectNativeViewHierarchy = (result: Analysis, oracle: Oracle) => {
|
||||
for (const { uid, identifier } of oracle.views) {
|
||||
@@ -84,21 +127,15 @@ const expectNativeViewHierarchy = (result: Analysis, oracle: Oracle) => {
|
||||
export const createInterfaceBuilderEncodingFixture = async (
|
||||
encoding: Encoding,
|
||||
) => {
|
||||
const native = await readNativeEncodingFixtures();
|
||||
const directory = await createTestTempDirectory("rea-ib-encoding-");
|
||||
await promisify(execFile)("/usr/bin/xcrun", [
|
||||
"swift",
|
||||
"tests/conformance/native/interface-builder-encoding.swift",
|
||||
directory,
|
||||
]);
|
||||
const oracle = oracleSchema.parse(
|
||||
JSON.parse(await readFile(join(directory, "oracle.json"), "utf8")),
|
||||
);
|
||||
const oracle = structuredClone(native.oracle);
|
||||
expect(oracle.views.map(({ identifier }) => identifier)).toEqual([
|
||||
"Café",
|
||||
"Left",
|
||||
"Right",
|
||||
]);
|
||||
const createBundle = async (name: string, selected: string) => {
|
||||
const createBundle = async (name: string, selected: Encoding) => {
|
||||
const app = join(directory, `${name}.app`);
|
||||
const contents = join(app, "Contents");
|
||||
await mkdir(join(contents, "Resources"), { recursive: true });
|
||||
@@ -112,7 +149,10 @@ export const createInterfaceBuilderEncodingFixture = async (
|
||||
join(contents, "Info.plist"),
|
||||
"<plist><dict><key>CFBundleExecutable</key><string>App</string><key>CFBundleIdentifier</key><string>com.example.encoding</string></dict></plist>",
|
||||
);
|
||||
const bytes = await readFile(join(directory, `${selected}.nib`));
|
||||
const retained = native.archives.get(selected);
|
||||
if (retained === undefined)
|
||||
throw new Error(`Native fixture omitted the ${selected} archive.`);
|
||||
const bytes = Buffer.from(retained);
|
||||
await writeFile(join(contents, "Resources", "Panel.nib"), bytes);
|
||||
return { app, bytes };
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user