Skip to content

Commit

Permalink
Save HTML snapshots of all backend test notebooks (#2861)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Mar 28, 2024
1 parent f6fe3da commit 4b52f6e
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ jobs:
- uses: julia-actions/julia-runtest@v1
with:
coverage: false

- uses: actions/upload-artifact@v4
if: failure()
with:
name: test-snapshots-${{ matrix.julia-version }}-${{ matrix.os }}
path: ${{ github.workspace }}/test/snapshots/*.html
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ frontend/package-lock.json

# PProf
profile.pb.gz

test/snapshots
4 changes: 2 additions & 2 deletions test/Bonds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ import Malt
@test noerror(notebook.cells[36])
@test notebook.cells[37].output.body == "\"xx\""

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
🍭.options.evaluation.workspace_use_distributed = false


Expand Down Expand Up @@ -488,7 +488,7 @@ import Malt



WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)

end
end
34 changes: 17 additions & 17 deletions test/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ end
end


nb = SessionActions.open(🍭, basic_nb_path; as_sample=true)
notebook = SessionActions.open(🍭, basic_nb_path; as_sample=true)

simple_routes = [
("", "GET"),
("edit?id=$(nb.notebook_id)", "GET"),
("edit?id=$(notebook.notebook_id)", "GET"),
("editor.html", "GET"),
("notebookfile?id=$(nb.notebook_id)", "GET"),
("notebookexport?id=$(nb.notebook_id)", "GET"),
("statefile?id=$(nb.notebook_id)", "GET"),
("notebookfile?id=$(notebook.notebook_id)", "GET"),
("notebookexport?id=$(notebook.notebook_id)", "GET"),
("statefile?id=$(notebook.notebook_id)", "GET"),
]

function tempcopy(x)
Expand Down Expand Up @@ -209,15 +209,15 @@ end
@test shares_secret(r) # see reasoning in of https://github.com/fonsp/Pluto.jl/commit/20515dd46678a49ca90e042fcfa3eab1e5c8e162

new_ids = collect(keys(🍭.notebooks))
nb = 🍭.notebooks[only(setdiff(new_ids, old_ids))]
notebook = 🍭.notebooks[only(setdiff(new_ids, old_ids))]

if any(x -> occursin(x, suffix), ["new", "execution_allowed", "sample/Basic.jl"])
@test Pluto.will_run_code(nb)
@test Pluto.will_run_pkg(nb)
@test Pluto.will_run_code(notebook)
@test Pluto.will_run_pkg(notebook)
else
@test !Pluto.will_run_code(nb)
@test !Pluto.will_run_pkg(nb)
@test nb.process_status === Pluto.ProcessStatus.waiting_for_permission
@test !Pluto.will_run_code(notebook)
@test !Pluto.will_run_pkg(notebook)
@test notebook.process_status === Pluto.ProcessStatus.waiting_for_permission
end
end

Expand All @@ -232,18 +232,18 @@ end
PlutoRunner.is_mime_enabled(m::MIME"application/vnd.pluto.tree+object") = false
"""

nb = Pluto.Notebook([
notebook = Pluto.Notebook([
Pluto.Cell("x = [1, 2]")
Pluto.Cell("struct Foo; x; end")
Pluto.Cell("Foo(x)")
])

Pluto.update_run!(🍭, nb, nb.cells)
@test nb.cells[1].output.body == repr(MIME"text/plain"(), [1,2])
@test nb.cells[1].output.mime isa MIME"text/plain"
@test nb.cells[3].output.mime isa MIME"text/plain"
Pluto.update_run!(🍭, notebook, notebook.cells)
@test notebook.cells[1].output.body == repr(MIME"text/plain"(), [1,2])
@test notebook.cells[1].output.mime isa MIME"text/plain"
@test notebook.cells[3].output.mime isa MIME"text/plain"

Pluto.WorkspaceManager.unmake_workspace((🍭, nb))
cleanup(🍭, notebook)
end

end
2 changes: 1 addition & 1 deletion test/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,6 @@ end
@test isempty(notebook.cells[2].published_objects)
@test !isempty(notebook.cells[5].published_objects)

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end
end
2 changes: 1 addition & 1 deletion test/Firebasey.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import Pluto: ServerSession, update_run!, WorkspaceManager
# and also that Pluto can figure out the execution order on its own
@test all(noerror, notebook.cells)

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end
2 changes: 1 addition & 1 deletion test/Logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,5 @@ using Pluto.WorkspaceManager: poll
end
end

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end
4 changes: 2 additions & 2 deletions test/MacroAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ import Memoize: @memoize

@test cell(1) |> noerror

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
🍭.options.evaluation.workspace_use_distributed = false
end

Expand Down Expand Up @@ -677,7 +677,7 @@ import Memoize: @memoize
@test cell(1) |> noerror
@test cell(2) |> noerror

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)

🍭.options.evaluation.workspace_use_distributed = false
end
Expand Down
2 changes: 1 addition & 1 deletion test/Notebook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ end
@testset "$(name)" for (name, nb) in nbs
if name βˆ‰ expect_error
@test nb_is_runnable(🍭, nb)
WorkspaceManager.unmake_workspace((🍭, nb))
cleanup(🍭, nb)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/React.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ import Pluto.Configuration: Options, EvaluationOptions
@test notebook.cells[4] |> noerror
@test notebook.cells[1].output.body == "\"double_december = 24\""

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
🍭.options.evaluation.workspace_use_distributed = false
end

Expand Down
4 changes: 2 additions & 2 deletions test/RichOutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ import Pluto: update_run!, WorkspaceManager, ClientSession, ServerSession, Noteb
@test occursin("102", s)
@test occursin("103", s)

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
🍭.options.evaluation.workspace_use_distributed = false
end

Expand Down Expand Up @@ -322,7 +322,7 @@ import Pluto: update_run!, WorkspaceManager, ClientSession, ServerSession, Noteb

# TODO: test lazy loading more rows/cols

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
🍭.options.evaluation.workspace_use_distributed = false
end

Expand Down
2 changes: 1 addition & 1 deletion test/WorkspaceManager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ import Malt
update_run!(🍭, notebook, notebook.cells[5])
@test noerror(notebook.cells[5])

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end
end
6 changes: 3 additions & 3 deletions test/cell_disabling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ using Pluto: update_run!, ServerSession, ClientSession, Cell, Notebook, set_disa
update_run!(🍭, notebook, c([12]))
@test c(14).output.body == "3"

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end


Expand Down Expand Up @@ -343,7 +343,7 @@ end
update_run!(🍭, notebook, notebook.cells)
@test get_disabled_cells(notebook) == []

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

@testset "Disabled cells should stay in the topology (#2676)" begin
Expand Down Expand Up @@ -386,5 +386,5 @@ end
notebook2 = Pluto.load_notebook_nobackup(io, "mynotebook.jl")
@test length(notebook2.cells) == length(notebook.cells)

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end
16 changes: 16 additions & 0 deletions test/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,19 @@ const pluto_test_registry_spec = Pkg.RegistrySpec(;
name="PlutoPkgTestRegistry",
)

const snapshots_dir = joinpath(@__DIR__, "snapshots")

isdir(snapshots_dir) && rm(snapshots_dir; force=true, recursive=true)
mkdir(snapshots_dir)

function cleanup(session, notebook)
testset_stack = get(task_local_storage(), :__BASETESTNEXT__, Test.AbstractTestSet[])
name = replace(join((t.description for t in testset_stack), " – "), r"[\:\?\r\n<>\|\*]" => "-")

path = Pluto.numbered_until_new(joinpath(snapshots_dir, name); suffix=".html", create_file=true)

write(path, Pluto.generate_html(notebook))

WorkspaceManager.unmake_workspace((session, notebook))
end

24 changes: 12 additions & 12 deletions test/packages/Basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ import Malt
@test count("PlutoPkgTestD", ptoml_contents()) == 0


WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

simple_import_path = joinpath(@__DIR__, "simple_import.jl")
Expand All @@ -233,7 +233,7 @@ import Malt

@test notebook.cells[2].output.body == "0.2.2"

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

@testset "Package added by url" begin
Expand All @@ -258,7 +258,7 @@ import Malt

@test notebook.cells[2].output.body == "1.0.0"

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

future_notebook = read(joinpath(@__DIR__, "future_nonexisting_version.jl"), String)
Expand All @@ -283,7 +283,7 @@ import Malt

@test notebook.cells[2].output.body == "0.3.1"

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end


Expand Down Expand Up @@ -337,7 +337,7 @@ import Malt
@test notebook.nbpkg_restart_required_msg !== nothing
@test has_embedded_pkgfiles(notebook)

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

pkg_cell_notebook = read(joinpath(@__DIR__, "pkg_cell.jl"), String)
Expand Down Expand Up @@ -392,7 +392,7 @@ import Malt
@test notebook.nbpkg_restart_recommended_msg === nothing
@test notebook.nbpkg_restart_required_msg === nothing

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

@testset "DrWatson cell" begin
Expand Down Expand Up @@ -443,7 +443,7 @@ import Malt
@test notebook.nbpkg_restart_recommended_msg === nothing
@test notebook.nbpkg_restart_required_msg === nothing

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

@static if VERSION < v"1.10.0-0" # see https://github.com/fonsp/Pluto.jl/pull/2626#issuecomment-1671244510
Expand Down Expand Up @@ -596,7 +596,7 @@ import Malt

@test has_embedded_pkgfiles(notebook)

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

end
Expand Down Expand Up @@ -649,7 +649,7 @@ import Malt
wait.(running_tasks)
empty!(running_tasks)

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

@testset "PlutoRunner Syntax Error" begin
Expand All @@ -671,7 +671,7 @@ import Malt
@test !Pluto.is_just_text(notebook.topology, notebook.cells[2]) # Not a syntax error form
@test Pluto.is_just_text(notebook.topology, notebook.cells[3])

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

@testset "Precompilation" begin
Expand Down Expand Up @@ -758,7 +758,7 @@ import Malt
# Running the import should not have triggered additional precompilation, everything should have been precompiled during Pkg.precompile() (in sync_nbpkg).
@test after_sync == after_run

WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end
end

Expand All @@ -773,7 +773,7 @@ import Malt
@test isnothing(notebook.nbpkg_ctx)
@test notebook.cells[2].output.body == sprint(Base.show, LOAD_PATH[begin])
@test notebook.cells[3].output.body == sprint(Base.show, LOAD_PATH[end])
WorkspaceManager.unmake_workspace((🍭, notebook))
cleanup(🍭, notebook)
end

Pkg.Registry.rm(pluto_test_registry_spec)
Expand Down

0 comments on commit 4b52f6e

Please sign in to comment.