-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-server): support server css and fix FOUC (#54)
- Loading branch information
Showing
12 changed files
with
430 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import fs from "fs"; | ||
import { type Page, expect, test } from "@playwright/test"; | ||
|
||
export const testNoJs = test.extend({ | ||
javaScriptEnabled: ({}, use) => use(false), | ||
}); | ||
|
||
const pageErrorsMap = new WeakMap<Page, Error[]>(); | ||
|
||
test.afterEach(({ page }) => { | ||
const errors = pageErrorsMap.get(page); | ||
if (errors) { | ||
expect(errors).toEqual([]); | ||
} | ||
}); | ||
|
||
export function usePageErrorChecker(page: Page) { | ||
const pageErrors: Error[] = []; | ||
pageErrorsMap.set(page, pageErrors); | ||
page.on("pageerror", (e) => pageErrors.push(e)); | ||
} | ||
|
||
export async function createEditor(filepath: string) { | ||
let init = await fs.promises.readFile(filepath, "utf-8"); | ||
let data = init; | ||
return { | ||
async edit(editFn: (data: string) => Promise<string> | string) { | ||
data = await editFn(data); | ||
await fs.promises.writeFile(filepath, data); | ||
}, | ||
async [Symbol.asyncDispose]() { | ||
await fs.promises.writeFile(filepath, init); | ||
}, | ||
}; | ||
} | ||
|
||
export async function createReloadChecker(page: Page) { | ||
async function reset() { | ||
await page.evaluate(() => { | ||
const el = document.createElement("meta"); | ||
el.setAttribute("name", "x-reload-check"); | ||
document.head.append(el); | ||
}); | ||
} | ||
|
||
async function check() { | ||
await expect(page.locator(`meta[name="x-reload-check"]`)).toBeAttached({ | ||
timeout: 1, | ||
}); | ||
} | ||
|
||
await reset(); | ||
|
||
return { | ||
check, | ||
reset, | ||
[Symbol.asyncDispose]: check, | ||
}; | ||
} | ||
|
||
export async function waitForHydration(page: Page) { | ||
await page.getByText("hydrated: true").click(); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.