-
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
published_to_js
(now publish_to_js
) official API through Abs…
…tractPlutoDingetjes.jl (v2) (#2608) Co-authored-by: Fons van der Plas <fonsvdplas@gmail.com>
- Loading branch information
Showing
4 changed files
with
216 additions
and
73 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,58 @@ | ||
import puppeteer from "puppeteer" | ||
import { lastElement, saveScreenshot, getTestScreenshotPath, createPage } from "../helpers/common" | ||
import { | ||
getCellIds, | ||
importNotebook, | ||
waitForCellOutput, | ||
getPlutoUrl, | ||
prewarmPluto, | ||
writeSingleLineInPlutoInput, | ||
waitForNoUpdateOngoing, | ||
shutdownCurrentNotebook, | ||
setupPlutoBrowser, | ||
} from "../helpers/pluto" | ||
|
||
describe("published_to_js", () => { | ||
/** | ||
* 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, | ||
* so I need to manually create the shared browser. | ||
* @type {puppeteer.Browser} | ||
*/ | ||
let browser = null | ||
/** @type {puppeteer.Page} */ | ||
let page = null | ||
beforeAll(async () => { | ||
browser = await setupPlutoBrowser() | ||
}) | ||
beforeEach(async () => { | ||
page = await createPage(browser) | ||
await page.goto(getPlutoUrl(), { waitUntil: "networkidle0" }) | ||
}) | ||
afterEach(async () => { | ||
await saveScreenshot(page) | ||
await shutdownCurrentNotebook(page) | ||
await page.close() | ||
page = null | ||
}) | ||
afterAll(async () => { | ||
await browser.close() | ||
browser = null | ||
}) | ||
|
||
it("Should correctly show published_to_js in cell output, and in logs", async () => { | ||
await importNotebook(page, "published_to_js.jl") | ||
await waitForNoUpdateOngoing(page, { polling: 100 }) | ||
let output_of_published = await page.evaluate(() => { | ||
return document.querySelector("#to_cell_output")?.textContent | ||
}) | ||
expect(output_of_published).toBe("[1,2,3] MAGIC!") | ||
|
||
// The log content is not shown, so #to_cell_log does not exist | ||
let log_of_published = await page.evaluate(() => { | ||
return document.querySelector("#to_cell_log")?.textContent | ||
}) | ||
// This test is currently broken, due to https://github.com/fonsp/Pluto.jl/issues/2092 | ||
// expect(log_of_published).toBe("[4,5,6] MAGIC!") | ||
}) | ||
}) |
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,50 @@ | ||
### A Pluto.jl notebook ### | ||
# v0.19.27 | ||
|
||
using Markdown | ||
using InteractiveUtils | ||
|
||
# ╔═╡ 2d69377e-23f8-11ee-116b-fb6a8f328528 | ||
begin | ||
using Pkg | ||
Pkg.activate(temp=true) | ||
# the latest versions of these packages: | ||
Pkg.add(url="https://github.com/JuliaPluto/AbstractPlutoDingetjes.jl", rev="main") | ||
Pkg.add("HypertextLiteral") | ||
end | ||
|
||
# ╔═╡ 2ea26a4b-2d1e-4bcb-8b7b-cace79f7926a | ||
begin | ||
using AbstractPlutoDingetjes.Display: published_to_js | ||
using HypertextLiteral | ||
end | ||
|
||
# ╔═╡ 043829fc-af3a-40b9-bb4f-f848ab50eb25 | ||
a = [1,2,3]; | ||
|
||
# ╔═╡ 2f4609fd-7361-4048-985a-2cc74bb25606 | ||
@htl """ | ||
<script> | ||
const a = JSON.stringify($(published_to_js(a))) + " MAGIC!" | ||
return html`<div id='to_cell_output'>\${a}</div>` | ||
</script> | ||
""" | ||
|
||
# ╔═╡ 28eba9fd-0416-49b8-966e-03a381c19ca7 | ||
b = [4,5,6]; | ||
|
||
# ╔═╡ 0a4e8a19-6d43-4161-bb8c-1ebf8f8f68ba | ||
@info @htl """ | ||
<script> | ||
const a = JSON.stringify($(published_to_js(b))) + " MAGIC!" | ||
return html`<div id='to_cell_log'>\${a}</div>` | ||
</script> | ||
""" | ||
|
||
# ╔═╡ Cell order: | ||
# ╠═2d69377e-23f8-11ee-116b-fb6a8f328528 | ||
# ╠═2ea26a4b-2d1e-4bcb-8b7b-cace79f7926a | ||
# ╠═043829fc-af3a-40b9-bb4f-f848ab50eb25 | ||
# ╠═2f4609fd-7361-4048-985a-2cc74bb25606 | ||
# ╠═28eba9fd-0416-49b8-966e-03a381c19ca7 | ||
# ╠═0a4e8a19-6d43-4161-bb8c-1ebf8f8f68ba |