Skip to content

Commit

Permalink
Merge branch 'main' into wait-to-run
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Oct 21, 2023
2 parents 3436dc8 + ebebf3c commit 329d430
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 69 deletions.
2 changes: 2 additions & 0 deletions frontend/components/BottomRightPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export let BottomRightPanel = ({ desired_doc_query, on_update_doc_query, noteboo
"helpbox-process": true,
"active": open_tab === "process",
"busy": show_business_outline,
"something_is_happening": busy || !connected,
})}
id="process-status-tab-button"
onClick=${() => {
set_open_tab(open_tab === "process" ? null : "process")
}}
Expand Down
4 changes: 4 additions & 0 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@ patch: ${JSON.stringify(
// console.info("All scripts finished!")
this.send_queued_bond_changes()
})

// @ts-ignore This is for tests
document.body._js_init_set = this.js_init_set

/** Is the notebook ready to execute code right now? (i.e. are no cells queued or running?) */
this.notebook_is_idle = () => {
return !(
Expand Down
5 changes: 1 addition & 4 deletions test/frontend/__tests__/autocomplete_test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import puppeteer from "puppeteer"
import { lastElement, saveScreenshot, getTestScreenshotPath, createPage } from "../helpers/common"
import { lastElement, saveScreenshot, createPage } from "../helpers/common"
import {
getCellIds,
importNotebook,
waitForCellOutput,
getPlutoUrl,
prewarmPluto,
writeSingleLineInPlutoInput,
waitForNoUpdateOngoing,
shutdownCurrentNotebook,
setupPlutoBrowser,
} from "../helpers/pluto"
Expand Down Expand Up @@ -42,7 +40,6 @@ describe("PlutoAutocomplete", () => {

it("should get the correct autocomplete suggestions", async () => {
await importNotebook(page, "autocomplete_notebook.jl")
await waitForNoUpdateOngoing(page, { polling: 100 })
const importedCellIds = await getCellIds(page)
await Promise.all(importedCellIds.map((cellId) => waitForCellOutput(page, cellId)))

Expand Down
9 changes: 5 additions & 4 deletions test/frontend/__tests__/bonds.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import puppeteer from "puppeteer"
import { saveScreenshot, createPage, paste } from "../helpers/common"
import { createNewNotebook, getPlutoUrl, prewarmPluto, setupPlutoBrowser, shutdownCurrentNotebook, waitForNoUpdateOngoing } from "../helpers/pluto"
import { createNewNotebook, getPlutoUrl, setupPlutoBrowser, shutdownCurrentNotebook, waitForPlutoToCalmDown } from "../helpers/pluto"

// https://github.com/fonsp/Pluto.jl/issues/928
describe("Bonds should run once when refreshing page", () => {
Expand Down Expand Up @@ -51,7 +51,7 @@ describe("Bonds should run once when refreshing page", () => {
await page.click(`.runallchanged`)

await page.waitForSelector(`pluto-cell.running`, { visible: true, timeout: 0 })
await waitForNoUpdateOngoing(page)
await waitForPlutoToCalmDown(page)

await paste(
page,
Expand All @@ -66,9 +66,10 @@ numberoftimes = Ref(0)

await page.waitForSelector(`.runallchanged`, { visible: true, polling: 200, timeout: 0 })
await page.click(`.runallchanged`)
await waitForPlutoToCalmDown(page)
await page.waitForFunction(() => Boolean(document.querySelector("pluto-cell:nth-of-type(5) pluto-output")?.textContent))
await waitForPlutoToCalmDown(page)

await waitForNoUpdateOngoing(page)
let output_after_running_bonds = await page.evaluate(() => {
return document.querySelector("pluto-cell:nth-of-type(5) pluto-output")?.textContent
})
Expand All @@ -77,7 +78,7 @@ numberoftimes = Ref(0)
// Let's refresh and see
await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] })
await page.waitForFunction(() => Boolean(document.querySelector("pluto-cell:nth-of-type(5) pluto-output")?.textContent))
await waitForNoUpdateOngoing(page)
await waitForPlutoToCalmDown(page)
let output_after_reload = await page.evaluate(() => {
return document.querySelector("pluto-cell:nth-of-type(5) pluto-output")?.textContent
})
Expand Down
25 changes: 6 additions & 19 deletions test/frontend/__tests__/javascript_api.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import puppeteer from "puppeteer"
import { waitForContent, lastElement, saveScreenshot, getTestScreenshotPath, waitForContentToBecome, createPage, paste, countCells } from "../helpers/common"
import {
createNewNotebook,
getCellIds,
waitForCellOutput,
waitForNoUpdateOngoing,
getPlutoUrl,
prewarmPluto,
waitForCellOutputToChange,
keyboardPressInPlutoInput,
writeSingleLineInPlutoInput,
manuallyEnterCells,
shutdownCurrentNotebook,
setupPlutoBrowser,
} from "../helpers/pluto"
import { saveScreenshot, waitForContentToBecome, createPage, paste } from "../helpers/common"
import { createNewNotebook, waitForNoUpdateOngoing, getPlutoUrl, shutdownCurrentNotebook, setupPlutoBrowser, waitForPlutoToCalmDown } from "../helpers/pluto"

describe("JavaScript API", () => {
/**
Expand Down Expand Up @@ -62,7 +49,7 @@ describe("JavaScript API", () => {
timeout: 0,
})
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
const initialLastCellContent = await waitForContentToBecome(page, `pluto-cell:last-child pluto-output`, expected)
expect(initialLastCellContent).toBe(expected)
})
Expand All @@ -83,7 +70,7 @@ describe("JavaScript API", () => {
timeout: 0,
})
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
let initialLastCellContent = await waitForContentToBecome(page, `pluto-cell:last-child pluto-output`, expected)
expect(initialLastCellContent).toBe(expected)

Expand All @@ -103,7 +90,7 @@ describe("JavaScript API", () => {
timeout: 0,
})
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
initialLastCellContent = await waitForContentToBecome(page, `pluto-cell:last-child pluto-output`, expected)
expect(initialLastCellContent).toBe(expected)
})
Expand Down Expand Up @@ -136,7 +123,7 @@ describe("JavaScript API", () => {
timeout: 0,
})
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
await waitForContentToBecome(page, `pluto-cell:nth-child(2) pluto-output`, "emitter")
page.waitForTimeout(2000)

Expand Down
7 changes: 3 additions & 4 deletions test/frontend/__tests__/new_notebook_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { waitForContent, lastElement, saveScreenshot, waitForContentToBecome, cr
import {
createNewNotebook,
getCellIds,
waitForNoUpdateOngoing,
getPlutoUrl,
prewarmPluto,
waitForCellOutputToChange,
keyboardPressInPlutoInput,
writeSingleLineInPlutoInput,
shutdownCurrentNotebook,
setupPlutoBrowser,
waitForPlutoToCalmDown,
} from "../helpers/pluto"

const manuallyEnterCells = async (page, cells) => {
Expand Down Expand Up @@ -80,7 +79,7 @@ describe("PlutoNewNotebook", () => {
const plutoCellIds = await manuallyEnterCells(page, cells)
await page.waitForSelector(`.runallchanged`, { visible: true, polling: 200, timeout: 0 })
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
const content = await waitForContentToBecome(page, `pluto-cell[id="${plutoCellIds[3]}"] pluto-output`, "6")
expect(content).toBe("6")
})
Expand All @@ -90,7 +89,7 @@ describe("PlutoNewNotebook", () => {
const plutoCellIds = await manuallyEnterCells(page, cells)
await page.waitForSelector(`.runallchanged`, { visible: true, polling: 200, timeout: 0 })
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
const initialLastCellContent = await waitForContentToBecome(page, `pluto-cell[id="${plutoCellIds[3]}"] pluto-output`, "6")
expect(initialLastCellContent).toBe("6")

Expand Down
8 changes: 4 additions & 4 deletions test/frontend/__tests__/paste_test.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
createNewNotebook,
getCellIds,
waitForCellOutput,
waitForNoUpdateOngoing,
waitForPlutoToCalmDown,
getPlutoUrl,
prewarmPluto,
waitForCellOutputToChange,
Expand Down Expand Up @@ -46,7 +46,7 @@ describe("Paste Functionality", () => {
const plutoCellIds = await manuallyEnterCells(page, cells)
await page.waitForSelector(`.runallchanged`, { visible: true, polling: 200, timeout: 0 })
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
const initialLastCellContent = await waitForContentToBecome(page, `pluto-cell[id="${plutoCellIds[3]}"] pluto-output`, "6")
expect(initialLastCellContent).toBe("6")

Expand Down Expand Up @@ -77,7 +77,7 @@ describe("Paste Functionality", () => {
const plutoCellIds = await manuallyEnterCells(page, cells)
await page.waitForSelector(`.runallchanged`, { visible: true, polling: 200, timeout: 0 })
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
const initialLastCellContent = await waitForContentToBecome(page, `pluto-cell[id="${plutoCellIds[3]}"] pluto-output`, "6")
expect(initialLastCellContent).toBe("6")

Expand Down Expand Up @@ -119,7 +119,7 @@ describe("Paste Functionality", () => {
const plutoCellIds = await manuallyEnterCells(page, cells)
await page.waitForSelector(`.runallchanged`, { visible: true, polling: 200, timeout: 0 })
await page.click(`.runallchanged`)
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
const initialLastCellContent = await waitForContentToBecome(page, `pluto-cell[id="${plutoCellIds[3]}"] pluto-output`, "6")
expect(initialLastCellContent).toBe("6")

Expand Down
18 changes: 4 additions & 14 deletions test/frontend/__tests__/published_to_js.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
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"
import { saveScreenshot, createPage } from "../helpers/common"
import { importNotebook, getPlutoUrl, shutdownCurrentNotebook, setupPlutoBrowser } from "../helpers/pluto"

describe("published_to_js", () => {
/**
Expand Down Expand Up @@ -42,7 +32,7 @@ describe("published_to_js", () => {

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
})
Expand All @@ -53,6 +43,6 @@ describe("published_to_js", () => {
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!")
expect(log_of_published).toBe("[4,5,6] MAGIC!")
})
})
13 changes: 2 additions & 11 deletions test/frontend/__tests__/slide_controls.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import puppeteer from "puppeteer"
import { saveScreenshot, createPage, waitForContent } from "../helpers/common"
import {
createNewNotebook,
getPlutoUrl,
manuallyEnterCells,
prewarmPluto,
setupPlutoBrowser,
shutdownCurrentNotebook,
waitForNoUpdateOngoing,
} from "../helpers/pluto"
import { createNewNotebook, getPlutoUrl, manuallyEnterCells, setupPlutoBrowser, shutdownCurrentNotebook, waitForPlutoToCalmDown } from "../helpers/pluto"

describe("slideControls", () => {
let browser = null
Expand Down Expand Up @@ -38,7 +29,7 @@ describe("slideControls", () => {
const plutoCellIds = await manuallyEnterCells(page, cells)
await page.waitForSelector(".runallchanged", { visible: true, polling: 200, timeout: 0 })
await page.click(".runallchanged")
await waitForNoUpdateOngoing(page, { polling: 100 })
await waitForPlutoToCalmDown(page, { polling: 100 })
const content = await waitForContent(page, `pluto-cell[id="${plutoCellIds[1]}"] pluto-output`)
expect(content).toBe("Slide 2")

Expand Down
24 changes: 15 additions & 9 deletions test/frontend/helpers/pluto.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const createNewNotebook = async (page) => {
const newNotebookSelector = 'a[href="new"]'
await page.waitForSelector(newNotebookSelector)
await clickAndWaitForNavigation(page, newNotebookSelector)
await page.waitForTimeout(1000)
await waitForPlutoToCalmDown(page)
await page.waitForSelector("pluto-input", { visible: true })
}
Expand All @@ -100,6 +101,7 @@ export const importNotebook = async (page, notebookName, { permissionToRunCode =
await clickAndWaitForNavigation(page, openFileButton)
// Give permission to run code in this notebook
if (permissionToRunCode) await restartProcess(page)
await page.waitForTimeout(1000)
await waitForPlutoToCalmDown(page)
}

Expand All @@ -112,17 +114,21 @@ export const getCellIds = (page) => page.evaluate(() => Array.from(document.quer
* @param {Page} page
*/
export const restartProcess = async (page) => {
//@ts-ignore
await page.waitForFunction(() => document?.querySelector(`a#restart-process-button`).click())
await page.click(`a#restart-process-button`)
}

/**
* @param {Page} page
*/
export const waitForPlutoToCalmDown = async (page) => {
await page.waitForTimeout(1000)
//@ts-ignore
await page.waitForFunction(() => document?.body?._update_is_ongoing === false && document?.querySelector(`pluto-cell.running, pluto-cell.queued`) === null)
export const waitForPlutoToCalmDown = async (/** @type {puppeteer.Page} */ page, /** @type {{ polling: string | number; timeout?: number; }} */ options) => {
await page.waitForFunction(
() =>
//@ts-ignore
document?.body?._update_is_ongoing === false &&
//@ts-ignore
document?.body?._js_init_set?.size === 0 &&
document?.body?.classList?.contains("loading") === false &&
document?.querySelector(`#process-status-tab-button.something_is_happening`) == null &&
document?.querySelector(`pluto-cell.running, pluto-cell.queued`) === null,
options
)
}

/**
Expand Down

0 comments on commit 329d430

Please sign in to comment.