RLesur / crrri

A Chrome Remote Interface written in R
https://rlesur.github.io/crrri/
Other
157 stars 12 forks source link

add setup and teardown to testthat for opening and closing chrome #53

Closed cderv closed 5 years ago

cderv commented 5 years ago

This is a small improvement trying to use the mechanism from testthat.

setup and teardown are in testthat to execute code before each files and at the end of each files. like on.exit or reg.finalizer. There is a mechanism for them to leave in their own setup-* and teardown-* files, executed before and after each test, but not run by load_all, (whereas similar helper-* files are run with load_all.

Here, as all the test file does not require chrome, we can't use the files feature. setup is not really useful, because code is executed imediately, in a clean environment. We must assign to global env... so not sure it is useful. However, teardown is a way for us to be sure to close connection by writing such code, just after we open, like a on.exit call you write just under file creation to be sure the file is deleted at the end.

I don't remove the object in teardown, because I believe each file is run in its own session but I am not sure... Removing with rm throws an error... Still investigating.

What do you think ?

Yeah, I know... Small things but I like to test new features! 😄


This change is Reviewable

cderv commented 5 years ago

the last commit would be the cleaner way to assign and be sure to remove the object. This is a way to know our test are clean.

Nota: the rm() was not working because teardown() was executing code in another environment and rm does not inherits by default. rm would have worked but I find rlang env_* function clearer.

this PR brings changes that are not strictly required so feel free to dismiss 😄

cderv commented 5 years ago

Do you think whether it is possible to write a single function embedding skip(), setup() and teardown()?

This is done now, and it is called setup_chrome_test(), in 44f39181509254588831dc9bfa8030bde4255f36