Skip to content

Commit

Permalink
add frontend test for published_to_js
Browse files Browse the repository at this point in the history
  • Loading branch information
disberd committed Jul 16, 2023
1 parent a4e85f7 commit ce919be
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/frontend/__tests__/published_to_js.js
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("publish_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, but not 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!")
})
})
49 changes: 49 additions & 0 deletions test/frontend/fixtures/published_to_js.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
### A Pluto.jl notebook ###
# v0.19.27

using Markdown
using InteractiveUtils

# ╔═║ 2d69377e-23f8-11ee-116b-fb6a8f328528
begin
using Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/disberd/AbstractPlutoDingetjes.jl", rev="published_to_js")
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

0 comments on commit ce919be

Please sign in to comment.