Skip to content

Commit dd34a52

Browse files
committed
use IRdisplay publishing rather than a comm
1 parent e8ad019 commit dd34a52

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
Package: IRkernel.testthat
22
Title: What the Package Does (one line, title case)
3-
Version: 0.0.1
3+
Version: 0.0.2
44
Authors@R: person("Michael", "Chow", email = "michael@datacamp.com", role = c("aut", "cre"))
55
Description: Implements reporter for communicating testthat results to a jupyter client.
66
License: All Rights Reserved
77
Depends: R (>= 3.3.1)
88
Imports:
99
testthat,
10-
IRkernel
10+
IRkernel,
11+
IRdisplay,
12+
jsonlite
1113
Encoding: UTF-8
1214
LazyData: true
1315
RoxygenNote: 6.0.1

R/reporter-project.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
ProjectReporter <- R6::R6Class("ProjectReporter", inherit = testthat::ListReporter,
88
public = list(
99
all_tests = NULL,
10-
comm = NULL,
11-
initialize = function(..., comm) {
10+
initialize = function(...) {
1211
super$initialize(...)
13-
self$comm <- comm
1412
self$all_tests = testthat:::Stack$new()
1513
},
1614
end_reporter = function() {
@@ -30,8 +28,10 @@ ProjectReporter <- R6::R6Class("ProjectReporter", inherit = testthat::ListReport
3028
summary = summary,
3129
tests = test_res
3230
)
33-
34-
self$comm$send(payload)
31+
# Note: may want to use repr package instead
32+
IRdisplay::publish_mimebundle(list(
33+
'application/json' = jsonlite::toJSON(payload, auto_unbox = TRUE)
34+
))
3535

3636
payload
3737
},
@@ -63,11 +63,10 @@ ProjectReporter <- R6::R6Class("ProjectReporter", inherit = testthat::ListReport
6363
#'
6464
#' @export
6565
run_tests <- function(test_expr) {
66-
comm <- IRkernel::comm_manager()$new_comm('dc_project')
67-
comm$open()
68-
69-
reporter <- ProjectReporter$new(comm = comm)
66+
# create reporter
67+
reporter <- ProjectReporter$new()
7068
reporter$start_file('some name')
69+
# setup and run tests
7170
env = testthat::test_env()
7271
tests <- substitute(test_expr)
7372
testthat::with_reporter(

inst/R-projects-test-example.ipynb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@
1111
"To see this in action, paste this javascript into your console:\n",
1212
"\n",
1313
"```\n",
14-
"Jupyter.notebook.kernel.comm_manager.register_target('dc_project',\n",
15-
" function(comm, msg) {\n",
16-
" // comm is the frontend comm instance\n",
17-
" // msg is the comm_open message, which can carry data\n",
18-
"\n",
19-
" // Register handlers for later messages:\n",
20-
" comm.on_msg(function(msg) { console.log('msg:', msg)} );\n",
21-
" comm.on_close(function(msg) { console.log('close msg:', msg)});\n",
22-
" //comm.send({'foo': 0});\n",
23-
" })\n",
14+
"Jupyter.notebook.events.on(\n",
15+
" \"finished_execute.CodeCell\",\n",
16+
" (event, { cell } ) => console.log(cell)\n",
17+
")\n",
2418
"```"
2519
]
2620
},
2721
{
2822
"cell_type": "code",
2923
"execution_count": null,
30-
"metadata": {},
24+
"metadata": {
25+
"tags": [
26+
"tests"
27+
]
28+
},
3129
"outputs": [],
3230
"source": [
3331
"# TODO: load testthat funcs into an envir, or make parent?\n",
@@ -52,6 +50,7 @@
5250
}
5351
],
5452
"metadata": {
53+
"celltoolbar": "Edit Metadata",
5554
"kernelspec": {
5655
"display_name": "R",
5756
"language": "R",

0 commit comments

Comments
 (0)