-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add frontend test for published_to_js
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 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
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!") | ||
}) | ||
}) |
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,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 |