-
Notifications
You must be signed in to change notification settings - Fork 13
chore(internal): enable chromium gpu access for test runners #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coryrylan
wants to merge
1
commit into
main
Choose a base branch
from
topic-gpu-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import { preview, build } from 'vite'; | |
|
|
||
| const resolve = rel => path.resolve(process.cwd(), rel); | ||
| const DEFAULT_PORT = 4176; | ||
| export const VIEWPORT_WIDTH = 1180; | ||
| export const VIEWPORT_HEIGHT = 820; | ||
|
|
||
| process.env.NODE_ENV = 'production'; | ||
|
|
||
|
|
@@ -26,6 +28,10 @@ export class VitePlaywrightRunner { | |
| return this.#page; | ||
| } | ||
|
|
||
| get browserVersion() { | ||
| return this.#browser?.version(); | ||
| } | ||
|
|
||
| get port() { | ||
| return this.#serverPort ?? this.#storedPort ?? DEFAULT_PORT; | ||
| } | ||
|
|
@@ -96,7 +102,9 @@ export class VitePlaywrightRunner { | |
| throw error; | ||
| }); | ||
| console.log('playwright-runner: creating context'); | ||
| this.#page = await (await this.#browser.newContext({ viewport: { width: 1180, height: 820 } })).newPage(); | ||
| this.#page = await ( | ||
| await this.#browser.newContext({ viewport: { width: VIEWPORT_WIDTH, height: VIEWPORT_HEIGHT } }) | ||
| ).newPage(); | ||
| this.#page.on('crash', data => console.error('playwright-runner: browser crashed', data)); | ||
| console.log('playwright-runner: creating server'); | ||
| this.#server = await preview({ | ||
|
|
@@ -137,8 +145,7 @@ export async function buildPage(testName, runnerID, render) { | |
| if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir, { recursive: true }); | ||
|
|
||
| let scriptIdx = 0; | ||
| const scriptRe = /<script\s+type=["']module["']>([\s\S]*?)<\/script>/g; | ||
| html = html.replace(scriptRe, (_match, content) => { | ||
| html = replaceInlineModuleScripts(html, content => { | ||
| const name = `_entry${scriptIdx++}.js`; | ||
| fs.writeFileSync(path.join(tmpDir, name), content.trim()); | ||
| return `<script type="module" src="./${name}"></script>`; | ||
|
|
@@ -177,3 +184,56 @@ export async function buildPage(testName, runnerID, render) { | |
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| /** Replaces inline module scripts with a forward-only scan of the HTML. */ | ||
| export function replaceInlineModuleScripts(html, replaceScript) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit overkill to satisfy the security bot check |
||
| const parts = []; | ||
| let copiedUntil = 0; | ||
| let searchFrom = 0; | ||
|
|
||
| while (searchFrom < html.length) { | ||
| const scriptStart = html.indexOf('<script', searchFrom); | ||
| if (scriptStart === -1) break; | ||
|
|
||
| const contentStart = getInlineModuleScriptContentStart(html, scriptStart); | ||
| if (contentStart === undefined) { | ||
| searchFrom = scriptStart + '<script'.length; | ||
| continue; | ||
| } | ||
|
|
||
| const scriptEnd = html.indexOf('</script>', contentStart); | ||
| if (scriptEnd === -1) break; | ||
|
|
||
| parts.push(html.slice(copiedUntil, scriptStart)); | ||
| parts.push(replaceScript(html.slice(contentStart, scriptEnd))); | ||
| copiedUntil = scriptEnd + '</script>'.length; | ||
| searchFrom = copiedUntil; | ||
| } | ||
|
|
||
| parts.push(html.slice(copiedUntil)); | ||
| return parts.join(''); | ||
| } | ||
|
|
||
| function getInlineModuleScriptContentStart(html, scriptStart) { | ||
| let cursor = scriptStart + '<script'.length; | ||
| if (!isWhitespace(html[cursor])) return undefined; | ||
|
|
||
| while (isWhitespace(html[cursor])) cursor += 1; | ||
| if (!html.startsWith('type=', cursor)) return undefined; | ||
| cursor += 'type='.length; | ||
|
|
||
| const quote = html[cursor]; | ||
| if (quote !== '"' && quote !== "'") return undefined; | ||
|
|
||
| const moduleStart = cursor + 1; | ||
| const moduleEnd = moduleStart + 'module'.length; | ||
| if (!html.startsWith('module', moduleStart) || html[moduleEnd] !== quote || html[moduleEnd + 1] !== '>') { | ||
| return undefined; | ||
| } | ||
|
|
||
| return moduleEnd + 2; | ||
| } | ||
|
|
||
| function isWhitespace(character) { | ||
| return character !== undefined && character.trim() === ''; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a chromium change I think here. Not specific to this PR I don't think as I hit this in another wip PR as well.