Skip to content

Commit

Permalink
Remove testing server randNum hack
Browse files Browse the repository at this point in the history
  • Loading branch information
krschacht committed Feb 27, 2024
1 parent 9fd1e9d commit a5a87e4
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
3 changes: 1 addition & 2 deletions src/tests/fixtures/frames.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
} else if (target.id == "add-refresh-morph-to-frame") {
target.closest("turbo-frame")?.setAttribute("refresh", "morph")
} else if (target.id == "add-src-to-frame") {
target.closest("turbo-frame")?.setAttribute("src", "/__turbo/frames")
target.closest("turbo-frame")?.setAttribute("src", "/src/tests/fixtures/frames.html")
}
})
</script>
Expand All @@ -29,7 +29,6 @@ <h1>Frames</h1>

<turbo-frame id="frame" data-loaded-from="/src/tests/fixtures/frames.html">
<h2>Frames: #frame</h2>
<h3>This text always changes ##randNum##</h3>

<form action="/src/tests/fixtures/frames/frame.html">
<button id="frame-form-get-no-redirect">Navigate #frame without a redirect</button>
Expand Down
6 changes: 0 additions & 6 deletions src/tests/functional/frame_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,20 @@ test("navigating turbo-frame[refresh=morph] from within morphs the contents", as
test("calling reload on a frame replaces the contents", async ({ page }) => {
await page.click("#add-src-to-frame")

const textBeforeReload = await page.textContent("#frame h3")
await page.evaluate(() => document.getElementById("frame").reload())
const textAfterReload = await page.textContent("#frame h3")

expect(await nextEventOnTarget(page, "frame", "turbo:before-frame-render")).toBeTruthy()
expect(await noNextEventOnTarget(page, "frame", "turbo:before-frame-morph")).toBeTruthy()
assert.notEqual(textBeforeReload, textAfterReload)
})

test("calling reload on a frame[refresh=morph] morphs the contents", async ({ page }) => {
await page.click("#add-src-to-frame")
await page.click("#add-refresh-morph-to-frame")

const textBeforeReload = await page.textContent("#frame h3")
await page.evaluate(() => document.getElementById("frame").reload())
const textAfterReload = await page.textContent("#frame h3")

expect(await nextEventOnTarget(page, "frame", "turbo:before-frame-render")).toBeTruthy()
expect(await nextEventOnTarget(page, "frame", "turbo:before-frame-morph")).toBeTruthy()
assert.notEqual(textBeforeReload, textAfterReload)
})

test("following a link in rapid succession cancels the previous request", async ({ page }) => {
Expand Down
14 changes: 0 additions & 14 deletions src/tests/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ router.use((request, response, next) => {
}
})

router.get('/frames', (req, res) => {
// The purpose of this route is to do a server-side replacement of ##randNum##. This way when we
// refresh this page we are guaranteed to see a change in content.
fs.readFile(path.join(__dirname, '../../src/tests/fixtures/frames.html'), 'utf8', (err, data) => {
if (err) {
console.error(err)
return res.status(500).send('Error reading file')
}
const randomNumber = Math.floor(Math.random() * 10000000)
const processedContent = data.replace('##randNum##', randomNumber.toString())
res.send(processedContent)
})
})

router.post("/redirect", (request, response) => {
const { path, sleep, ...query } = request.body
const { pathname, query: searchParams } = url.parse(
Expand Down

0 comments on commit a5a87e4

Please sign in to comment.