Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,43 @@

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '26'
- uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- run: yarn install
- run: yarn run playwright install --with-deps
- name: Install Playwright browsers
run: npx --yes --package=node@18.20.8 --call 'node node_modules/playwright-core/cli.js install --with-deps chromium firefox'
- run: yarn build

- name: Set Chrome Version
- name: Configure ChromeDriver
run: |
CHROMEVER="$(chromedriver --version | cut -d' ' -f2)"
echo "Actions ChromeDriver is $CHROMEVER"
driver_dir="node_modules/@theintern/digdug/selenium-standalone/${CHROMEVER}/x64"
mkdir -p "$driver_dir"
install -m 755 "$(command -v chromedriver)" "$driver_dir/chromedriver"
echo "CHROMEVER=${CHROMEVER}" >> $GITHUB_ENV

- name: Lint
run: yarn lint

- name: Unit Test
run: yarn test:unit

- name: Chrome Test
run: yarn test:browser --project=chrome

- name: Firefox Test
run: yarn test:browser --project=firefox

- name: Chrome With Trusted Types Test
run: yarn test:browser --project=chrome-with-trusted-types

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
2 changes: 1 addition & 1 deletion .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '26'
registry-url: 'https://registry.npmjs.org'
- uses: actions/cache@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"intern": "^4.10.1",
"multer": "^1.4.2",
"multer": "^2.2.0",
"prettier": "2.6.2",
"rollup": "^2.35.1",
"tslib": "^2.4.0",
Expand Down
4 changes: 2 additions & 2 deletions src/tests/fixtures/one.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<body>
<h1>One</h1>

<!--styles ensure that the element will be scrolled to top when navigated to via an anchored link -->
<a name="named-anchor"></a>
<!-- Styles ensure anchored elements begin outside the viewport. -->
<a name="named-anchor" style="display: block; margin-top: 100vh"></a>
<div id="element-id" style="margin-top: 1em; height: 200vh">An element with an ID</div>
<p><a id="redirection-link" href="/__turbo/redirect?path=/src/tests/fixtures/visit.html">Redirection link</a></p>

Expand Down
4 changes: 2 additions & 2 deletions src/tests/fixtures/two.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<body>
<h1>Two</h1>

<!--styles ensure that the element will be scrolled to top when navigated to via an anchored link -->
<a name="named-anchor"></a>
<!-- Styles ensure anchored elements begin outside the viewport. -->
<a name="named-anchor" style="display: block; margin-top: 100vh"></a>
<div id="element-id" style="margin-top: 1em; height: 200vh">An element with an ID</div>
</body>
</html>
13 changes: 11 additions & 2 deletions src/tests/functional/frame_navigation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,17 @@ test("test canceling frame requests don't mutate the history", async ({ page })
assert.equal(await page.getAttribute("#tab-frame", "complete"), "", "sets [complete]")

// This request will be canceled
page.click("#tab-1")
await page.click("#tab-3")
let releaseRequest = () => {}
const requestCanContinue = new Promise<void>((resolve) => {
releaseRequest = resolve
})
await page.route("**/src/tests/fixtures/tabs.html", async (route) => {
await requestCanContinue
await route.continue()
})
await Promise.all([page.waitForRequest("**/src/tests/fixtures/tabs.html"), page.click("#tab-1")])
await Promise.all([page.waitForRequest("**/src/tests/fixtures/tabs/three.html"), page.click("#tab-3")])
releaseRequest()

await nextEventOnTarget(page, "tab-frame", "turbo:frame-load")
await nextEventNamed(page, "turbo:load")
Expand Down
5 changes: 3 additions & 2 deletions src/tests/functional/navigation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
hash,
hasSelector,
isScrolledToSelector,
isSelectorInViewport,
nextAttributeMutationNamed,
nextBeat,
nextBody,
Expand Down Expand Up @@ -206,7 +207,7 @@ test("test following a same-origin link to a named anchor", async ({ page }) =>
assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html")
assert.equal(hash(page.url()), "#named-anchor")
assert.equal(await visitAction(page), "advance")
assert(await isScrolledToSelector(page, "[name=named-anchor]"))
assert(await isSelectorInViewport(page, "[name=named-anchor]"))
})

test("test following a cross-origin unannotated link", async ({ page }) => {
Expand All @@ -226,7 +227,7 @@ test("test following a same-origin [target] link", async ({ page }) => {
test("test following a same-origin [download] link", async ({ page }) => {
assert.notOk<boolean>(
await willChangeBody(page, async () => {
await page.click("#same-origin-download-link")
await page.click("#same-origin-download-link", { noWaitAfter: true })
await nextBeat()
})
)
Expand Down
4 changes: 2 additions & 2 deletions src/tests/functional/rendering_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test("test reloads when tracked elements change", async ({ page }) => {
})

test("test reloads when tracked elements change due to failed form submission", async ({ page }) => {
await page.click("#tracked-asset-change-form button")
await Promise.all([page.waitForNavigation(), page.click("#tracked-asset-change-form button")])
await page.evaluate(() => {
window.addEventListener(
"turbo:reload",
Expand All @@ -86,7 +86,7 @@ test("test reloads when tracked elements change due to failed form submission",
)
})

await page.click("#tracked-asset-change-form button")
await Promise.all([page.waitForNavigation(), page.click("#tracked-asset-change-form button")])

const reason = await page.evaluate(() => localStorage.getItem("reason"))
const unloaded = await page.evaluate(() => localStorage.getItem("unloaded"))
Expand Down
2 changes: 1 addition & 1 deletion src/tests/functional/scroll_restoration_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test("test reloading after scrolling", async ({ page }) => {
const { y: yAfterScrolling } = await scrollPosition(page)
assert.notEqual(yAfterScrolling, 0)

await page.reload()
await Promise.all([page.waitForNavigation(), page.evaluate(() => window.location.reload())])
const { y: yAfterReloading } = await scrollPosition(page)
assert.notEqual(yAfterReloading, 0)
})
Expand Down
5 changes: 2 additions & 3 deletions src/tests/functional/visit_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test("test programmatically visiting a same-origin location", async ({ page }) =

test("skip programmatically visiting a cross-origin location falls back to window.location", async ({ page }) => {
const urlBeforeVisit = page.url()
await visitLocation(page, "about:blank")
await Promise.all([page.waitForNavigation(), visitLocation(page, "about:blank")])

const urlAfterVisit = page.url()
assert.notEqual(urlBeforeVisit, urlAfterVisit)
Expand All @@ -53,8 +53,7 @@ test("skip programmatically visiting a cross-origin location falls back to windo

test("test visiting a location served with a non-HTML content type", async ({ page }) => {
const urlBeforeVisit = page.url()
await visitLocation(page, "/src/tests/fixtures/svg.svg")
await nextBeat()
await Promise.all([page.waitForNavigation(), visitLocation(page, "/src/tests/fixtures/svg.svg")])

const url = page.url()
const contentType = await contentTypeOfURL(url)
Expand Down
37 changes: 26 additions & 11 deletions src/tests/helpers/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ export async function isScrolledToSelector(page: Page, selector: string): Promis
}
}

export function isSelectorInViewport(page: Page, selector: string): Promise<boolean> {
return page.locator(selector).evaluate((element) => {
const { top, bottom } = element.getBoundingClientRect()
return top >= 0 && bottom <= window.innerHeight
})
}

export function nextBeat() {
return sleep(100)
}
Expand Down Expand Up @@ -161,17 +168,25 @@ export function propertyForSelector(page: Page, selector: string, propertyName:
}

async function readArray<T>(page: Page, identifier: string, length?: number): Promise<T[]> {
return page.evaluate(
({ identifier, length }) => {
const records = (window as any)[identifier]
if (records != null && typeof records.splice == "function") {
return records.splice(0, typeof length === "undefined" ? records.length : length)
} else {
return []
}
},
{ identifier, length }
)
try {
return await page.evaluate(
({ identifier, length }) => {
const records = (window as any)[identifier]
if (records != null && typeof records.splice == "function") {
return records.splice(0, typeof length === "undefined" ? records.length : length)
} else {
return []
}
},
{ identifier, length }
)
} catch (error) {
if (!(error instanceof Error) || !error.message.includes("Execution context was destroyed")) {
throw error
}
await nextBeat()
return readArray(page, identifier, length)
}
}

export function readEventLogs(page: Page, length?: number): Promise<EventLog[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/helpers/trusted_type_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ test.beforeEach(async ({ page }, workerInfo) => {
})

test.afterEach(async ({ page }) => {
await page.evaluate(() => window.Turbo.setCSPTrustedTypesPolicy(null))
await page.evaluate(() => window.Turbo?.setCSPTrustedTypesPolicy(null))
})
Loading
Loading