Skip to content

Commit 30a5c2f

Browse files
committed
Document the process of testing the API and storing vignette inputs
1 parent 0ebe6ed commit 30a5c2f

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

R-packages/covidcast/DEVELOP.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A short checklist for submitting pull requests:
66
2. If you have added any new features (new functions, new options, etc.), add a
77
brief description to `NEWS.md` to the next listed version number. Also ensure
88
that new functions or datasets are listed in the reference in `_pkgdown.yml`
9-
so they appear in a good place in the documentation website.
9+
so they appear in a good place in the function reference page.
1010
3. If you changed any documentation, rebuild the documentation with
1111
`devtools::document()` and then `pkgdown::build_site()`. (This can be slow,
1212
because our vignettes take a long time to build.)
@@ -25,6 +25,17 @@ when you open a pull request, as part of running `R CMD check`. Failed tests and
2525
check errors will both result in the build failing and errors being visible in
2626
the pull request.
2727

28+
### Testing API access
29+
30+
Unit tests should *not* require Internet access. This poses a problem for
31+
testing of functions like `covidcast_signal()`. In testing, it is also helpful
32+
to be able to test different custom responses from the API server.
33+
34+
The [httptest package](https://enpiar.com/r/httptest/index.html) solves these
35+
problems by hooking in to the `httr` package and replacing API requests with the
36+
contents of specially named files. See `tests/testthat/test-covidcast.R` for
37+
details and examples.
38+
2839
### Testing plots
2940

3041
We test our plots and maps with the [vdiffr](https://github.com/r-lib/vdiffr)
@@ -78,3 +89,22 @@ After changing a vignette or documentation, you'll need to rebuild the
7889
documentation. Use `devtools::document()` to do this. Then
7990
`pkgdown::build_site(".")` (from within the package directory) will rebuild the
8091
HTML documentation site.
92+
93+
### Vignettes
94+
95+
Our vignettes can take quite a while to render; much of this time is spent in
96+
downloading data from the COVIDcast API. This can make the package inconvenient
97+
to install, take up time on our CI servers, and may cause issues when we
98+
eventually submit to CRAN.
99+
100+
We hence use [httptest's vignette
101+
features](https://enpiar.com/r/httptest/articles/vignettes.html) to record API
102+
requests and serve them from static JSON files in the repository, instead of
103+
actual API queries. This cuts the time dramatically. See the httptest
104+
documentation for more details on how this works, and ensure that any new
105+
vignettes use this feature.
106+
107+
To re-download all data for the vignettes, simply delete the corresponding
108+
folder in `vignettes/` and re-build the vignette. For example, delete
109+
`vignettes/plotting-signals/` and then rebuild `plotting-signals.Rmd` to have
110+
httptest re-download and save the data.

0 commit comments

Comments
 (0)