Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nbb UI tests: first cut #97

Merged
merged 52 commits into from
Mar 9, 2022
Merged

Nbb UI tests: first cut #97

merged 52 commits into from
Mar 9, 2022

Conversation

borkdude
Copy link
Collaborator

@borkdude borkdude commented Feb 22, 2022

This adds browser tests based on Nbb using playwright. It operates on the static build and browses through all notebooks and asserts that no errors are logged via js/console.errror.

@borkdude borkdude requested a review from mk February 22, 2022 18:43
Copy link
Member

@mk mk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general approach here is to browse to all notebooks in the static build and assert they don't log any console errors, correct?

Did you verify that viewer errors are logged and lead to a failure or should we still do that?

.github/workflows/main.yml Show resolved Hide resolved
nbb/package-lock.json Outdated Show resolved Hide resolved
nbb/playwright_tests.cljs Outdated Show resolved Hide resolved
bb/utils.clj Outdated Show resolved Hide resolved
@borkdude
Copy link
Collaborator Author

borkdude commented Mar 1, 2022

The general approach here is to browse to all notebooks in the static build and assert they don't log any console errors, correct?

Correct.

Did you verify that viewer errors are logged and lead to a failure or should we still do that?

I verified this in the REPL, but we can verify this by making a test commit which should trigger this. Do you know of anything that should trigger a console error in a clerk notebook?

@borkdude
Copy link
Collaborator Author

borkdude commented Mar 1, 2022

@mk Addressed everything, except one comment about the extra dir. Imo it's better to start coding in a separate file and use bb.edn only for hooking up code to task names, but given that the code is relatively thin, I'd be ok with moving it to the bb.edn for now. Just let me know.

@borkdude
Copy link
Collaborator Author

borkdude commented Mar 1, 2022

Hmm, somehow removing package lock json causes an error, I'll look into it.

@borkdude
Copy link
Collaborator Author

borkdude commented Mar 1, 2022

Running bb test:static-app bee6aa1bde9dfe88828171b1217e1c596d402ad9 locally works fine though.

@borkdude
Copy link
Collaborator Author

borkdude commented Mar 8, 2022

@mk We solved the problem that the viewer JS is "refreshed" as needed on google cloud before anything else runs. Having that in place, I could test and confirm that logging with js/console.error makes the tests fail:

https://github.com/nextjournal/clerk/runs/5467522586?check_suite_focus=true

I consider this PR mergeable. Let me know if you agree.

@mk
Copy link
Member

mk commented Mar 8, 2022

Was about to merge this until I saw that you added an explicit js/console.error in 0465c74. So I'd like to verify that the tests also catch other failure modes (sci read or eval errors, as well as runtime exceptions). I plan to do this first thing tomorrow and then ship it.

@borkdude
Copy link
Collaborator Author

borkdude commented Mar 8, 2022

I think you made a mistake with f71bcb4 since the tests contain a static build test which needs the JS asset to already be present. Triggering a rebuild will likely fail the tests.

@mk
Copy link
Member

mk commented Mar 8, 2022

@borkdude you mean this one?

(deftest static-app
(let [url* (volatile! nil)]
(with-redefs [clojure.java.browse/browse-url (fn [path]
(vreset! url* path))]
(testing "browser receives canonical url in this system arch"
(fs/with-temp-dir [temp {}]
(let [expected (-> (str/join (java.io.File/separator) [(.toString temp) "index.html"])
(str/replace (java.io.File/separator) "/"))]
(clerk/build-static-app! {:paths ["notebooks/hello.clj"]
:out-path temp})
(is (= expected @url*))))))))

If yes that should not be a problem since it's not asserting anything about this. In general, I'd like to keep the fast feedback loop the clojure tests currently bring and would prefer it if we managed to keep them without a dependency on the viewer js build.

@mk
Copy link
Member

mk commented Mar 8, 2022

Oh, I see what you mean now. The slurp will fail if the js hasn't been compiled yet. I guess we can pass an override setting for the tests.

@mk mk merged commit d08c260 into main Mar 9, 2022
@mk mk deleted the nbb-ui-tests branch March 9, 2022 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants