test: resolve nation office assets across worktrees

This commit is contained in:
2026-07-26 04:37:14 +00:00
parent 200d883b5b
commit e6a6dbb221
+10 -6
View File
@@ -14,16 +14,16 @@ type FixtureState = {
const artifactRoot = process.env.OFFICE_PARITY_ARTIFACT_DIR ? resolve(process.env.OFFICE_PARITY_ARTIFACT_DIR) : null; const artifactRoot = process.env.OFFICE_PARITY_ARTIFACT_DIR ? resolve(process.env.OFFICE_PARITY_ARTIFACT_DIR) : null;
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../..'); const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
const imageRoots = [resolve(repositoryRoot, '../image/game'), resolve(repositoryRoot, '../../image/game')]; const imageRoots = [resolve(repositoryRoot, '../image'), resolve(repositoryRoot, '../../image')];
const referenceImage = async (filename: string): Promise<Buffer> => { const referenceAsset = async (relativePath: string): Promise<Buffer> => {
for (const root of imageRoots) { for (const root of imageRoots) {
try { try {
return await readFile(resolve(root, filename)); return await readFile(resolve(root, relativePath));
} catch { } catch {
// Nested worktrees and the primary checkout have different image parents. // Nested worktrees and the primary checkout have different image parents.
} }
} }
throw new Error(`Reference image not found: ${filename}`); throw new Error(`Reference image not found: ${relativePath}`);
}; };
const response = (data: unknown) => ({ result: { data } }); const response = (data: unknown) => ({ result: { data } });
const errorResponse = (path: string, message: string, code = 'BAD_REQUEST') => ({ const errorResponse = (path: string, message: string, code = 'BAD_REQUEST') => ({
@@ -170,14 +170,18 @@ const installFixture = async (page: Page, state: FixtureState) => {
}); });
for (const filename of ['back_walnut.jpg', 'back_green.jpg', 'back_blue.jpg']) { for (const filename of ['back_walnut.jpg', 'back_green.jpg', 'back_blue.jpg']) {
await page.route(`**/image/game/${filename}`, async (route) => await page.route(`**/image/game/${filename}`, async (route) =>
route.fulfill({ status: 200, contentType: 'image/jpeg', body: await referenceImage(filename) }) route.fulfill({
status: 200,
contentType: 'image/jpeg',
body: await referenceAsset(`game/${filename}`),
})
); );
} }
await page.route('**/image/icons/**', async (route) => await page.route('**/image/icons/**', async (route) =>
route.fulfill({ route.fulfill({
status: 200, status: 200,
contentType: 'image/jpeg', contentType: 'image/jpeg',
body: await readFile(resolve(repositoryRoot, '../../image/icons/default.jpg')), body: await referenceAsset('icons/default.jpg'),
}) })
); );
await page.route('**/che/api/trpc/**', async (route) => { await page.route('**/che/api/trpc/**', async (route) => {