From 4520f194e3067582fcdeaf6051c4b92833f90ac6 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Mon, 12 Aug 2024 16:43:18 +0200 Subject: [PATCH] puppeteer test --- test/frontend/__tests__/bonds.js | 66 ++++++++++++++++++- .../frontend/fixtures}/test_bind_dynamics.jl | 6 +- 2 files changed, 66 insertions(+), 6 deletions(-) rename {sample => test/frontend/fixtures}/test_bind_dynamics.jl (95%) diff --git a/test/frontend/__tests__/bonds.js b/test/frontend/__tests__/bonds.js index af633a3400..0050429d45 100644 --- a/test/frontend/__tests__/bonds.js +++ b/test/frontend/__tests__/bonds.js @@ -1,9 +1,18 @@ import puppeteer from "puppeteer" -import { saveScreenshot, createPage, paste } from "../helpers/common" -import { createNewNotebook, getPlutoUrl, runAllChanged, setupPlutoBrowser, shutdownCurrentNotebook, waitForPlutoToCalmDown } from "../helpers/pluto" +import { saveScreenshot, createPage, paste, waitForContentToBecome, waitForContent } from "../helpers/common" +import { + createNewNotebook, + getPlutoUrl, + importNotebook, + runAllChanged, + setupPlutoBrowser, + shutdownCurrentNotebook, + waitForCellOutput, + waitForPlutoToCalmDown, +} from "../helpers/pluto" // https://github.com/fonsp/Pluto.jl/issues/928 -describe("Bonds should run once when refreshing page", () => { +describe("@bind", () => { /** * Launch a shared browser instance for all tests. * I don't use jest-puppeteer because it takes away a lot of control and works buggy for me, @@ -78,4 +87,55 @@ numberoftimes = Ref(0) }) expect(output_after_reload).toBe(output_after_running_bonds) }) + + it("should ignore intermediate bond values while the notebook is running", async () => { + const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) + + const chill = async () => { + await wait(300) + await waitForPlutoToCalmDown(page) + await wait(1500) + await waitForPlutoToCalmDown(page) + } + + await importNotebook(page, "test_bind_dynamics.jl") + await chill() + await chill() + + const id = `029e1d1c-bf42-4e2c-a141-1e2eecc0800d` + const output_selector = `pluto-cell[id="${id}"] pluto-output` + + //page.click is stupid + const click = async (sel) => { + await page.waitForSelector(sel) + await page.evaluate((sel) => document.querySelector(sel).click(), sel) + } + + const reset = async () => { + await click(`#reset_xs_button`) + await wait(300) + await waitForPlutoToCalmDown(page) + await waitForContentToBecome(page, output_selector, "") + await wait(300) + await waitForPlutoToCalmDown(page) + await waitForContentToBecome(page, output_selector, "") + await wait(300) + } + + const start = async () => { + await click(`#add_x_button`) + await chill() + + return await waitForContent(page, output_selector) + } + + await reset() + await start() + + await chill() + + await reset() + const val = await start() + expect(val).toBe("1,done") + }) }) diff --git a/sample/test_bind_dynamics.jl b/test/frontend/fixtures/test_bind_dynamics.jl similarity index 95% rename from sample/test_bind_dynamics.jl rename to test/frontend/fixtures/test_bind_dynamics.jl index 7096c475db..0746d5c805 100644 --- a/sample/test_bind_dynamics.jl +++ b/test/frontend/fixtures/test_bind_dynamics.jl @@ -15,7 +15,7 @@ macro bind(def, element) end # ╔═╡ a0fe4e4d-eee5-4420-bd58-3f12749a9ed1 -@bind reset_xs html"" +@bind reset_xs html"" # ╔═╡ 58db6bd4-58a6-11ef-3795-fd6e57eceb68 @bind x html"""
@@ -46,7 +46,7 @@ btn.onclick = () => { go() } - +
""" # ╔═╡ 8568c646-0233-4a95-8332-2351e9c56027 @@ -86,6 +86,6 @@ end # ╟─58db6bd4-58a6-11ef-3795-fd6e57eceb68 # ╟─8568c646-0233-4a95-8332-2351e9c56027 # ╠═8a20fa4a-ac02-4a37-a54e-e4224628db66 -# ╠═29f1d840-574e-463c-87d3-4b938e123493 # ╟─3155b6e0-8e19-4583-b2ab-4ab2db1f10b9 # ╠═029e1d1c-bf42-4e2c-a141-1e2eecc0800d +# ╠═29f1d840-574e-463c-87d3-4b938e123493