diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4fac9e523..31ecdee8d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -12,14 +12,13 @@ jobs: strategy: fail-fast: false matrix: - test-suite: [ renderer, compiler, CRAN ] + test-suite: [ R_coverage, JS_coverage, CRAN ] name: Test Suite ${{ matrix.test-suite }} env: TEST_SUITE: ${{ matrix.test-suite }} GITHUB_PAT: ${{ secrets.PAT_GITHUB }} GH_ACTION: "ENABLED" - COLLECT_COVERAGE: "TRUE" CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} steps: - uses: actions/checkout@v3 @@ -39,13 +38,13 @@ jobs: run: git config --global user.email toby.hocking@r-project.org - name: Setup Node.js - if: matrix.test-suite == 'renderer' + if: matrix.test-suite == 'JS_coverage' uses: actions/setup-node@v3 with: node-version: '18' - name: Install Node.js dependencies - if: matrix.test-suite == 'renderer' + if: matrix.test-suite == 'JS_coverage' run: | npm install v8-to-istanbul echo "Node modules installed" @@ -54,15 +53,16 @@ jobs: run: | if [ "$TEST_SUITE" == "CRAN" ]; then bash build.sh - elif [ "$TEST_SUITE" == "compiler" ]; then + elif [ "$TEST_SUITE" == "JS_coverage" ]; then + echo "Running testthat with JS coverage collection..." Rscript -e "source('tests/testthat.R', chdir = TRUE)" - Rscript -e 'covr::codecov(quiet = TRUE)' else - Rscript -e "source('tests/testthat.R', chdir = TRUE)" + echo "Running testthat with R coverage collection..." + Rscript -e 'covr::codecov(quiet = FALSE, type = "tests", test_files = "tests/testthat.R", flags = "r")' fi - name: Convert JS coverage to Istanbul format - if: matrix.test-suite == 'renderer' + if: matrix.test-suite == 'JS_coverage' run: | if [ -f "tests/testthat/js-coverage.json" ]; then echo "Converting JS coverage to LCOV format..." @@ -73,7 +73,7 @@ jobs: fi - name: Upload JS coverage to Codecov - if: matrix.test-suite == 'renderer' + if: matrix.test-suite == 'JS_coverage' run: | if [ -f "coverage-istanbul.json" ]; then curl -Os https://uploader.codecov.io/latest/linux/codecov diff --git a/tests/testthat.R b/tests/testthat.R index 15ab95263..091c571f9 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -5,26 +5,25 @@ setwd("testthat") source("helper-functions.R") source("helper-HTML.R") source("helper-plot-data.r") -filter <- Sys.getenv("TEST_SUITE") gh.action <- Sys.getenv("GH_ACTION") -collect.coverage <- Sys.getenv("COLLECT_COVERAGE", "FALSE") == "TRUE" && filter=="renderer" -if(filter == ""){ - filter <- NULL -} +is_js_coverage <- Sys.getenv("TEST_SUITE") == "JS_coverage" message(gh.action) tests_init() # Start coverage if enabled coverage_active <- FALSE -if(collect.coverage) { +if(is_js_coverage) { coverage_active <- start_js_coverage() if(coverage_active) { message("JS coverage collection started") } } # Run tests -tests_run(filter=filter) +message("\n=== Running COMPILER tests ===") +tests_run(filter = "compiler") +message("\n=== Running RENDERER tests ===") +tests_run(filter = "renderer") # Save coverage and cleanup if(coverage_active) { stop_js_coverage() } -tests_exit() +tests_exit() \ No newline at end of file diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 73963355a..b263c18f8 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -67,6 +67,7 @@ test_that("animint2pages() returns list of meta-data", { expect_Capture(update_list) }) +# This test is skipped under covr coverage collection due to environment manipulation. test_that("animint2pages raises an error if no GitHub token is present", { if (identical(Sys.getenv("R_COVR"), "true")) skip("Skip on covr: environment manipulation not supported") env.names <- c("GITHUB_PAT", "GITHUB_PAT_GITHUB_COM") diff --git a/tests/testthat/test-tt-inter.R b/tests/testthat/test-tt-inter.R deleted file mode 100644 index ae40f4e24..000000000 --- a/tests/testthat/test-tt-inter.R +++ /dev/null @@ -1,72 +0,0 @@ -acontext("tooltip-interactivity") -## !!! wercker has some problem with this test, so not using this !!! -data("WorldBank", package = "animint") -WorldBank1975 <- WorldBank[WorldBank$year == 1975, ] - -test_that("Interactivity does not mess up tooltip titles",{ - ## Take only first 3 chars of region names. Avoid non-alphanumerics - WorldBank1975$region <- tolower( - substring(as.character(WorldBank1975$region), 1, 3)) - - ex_plot <- ggplot() + - geom_point(aes(fertility.rate, life.expectancy, color = region, - tooltip = country, href = "https://github.com"), - data = WorldBank1975) - - viz <- list(ex = ex_plot) - info <- animint2HTML(viz) - - # Apply clickID with some time difference - apply_with_interval <- function(func, list, interval){ - for (elem in list){ - acontext(paste0("id - ", elem)) - Sys.sleep(interval) - func(elem) - } - } - # Hide some points first and check rendered titles - hide_these_first <- - c("plot_ex_region_variable_eas_label", - "plot_ex_region_variable_eur_label", - "plot_ex_region_variable_lat_label", - "plot_ex_region_variable_mid_label", - "plot_ex_region_variable_sub_label") - - b <- apply_with_interval(clickID, hide_these_first, 1) - - Sys.sleep(1) - info$html <- getHTML() - - displayed_regions <- WorldBank1975$region == "nor" | - WorldBank1975$region == "sou" - displayed_countries <- unique(WorldBank1975$country[displayed_regions]) - - title_nodes1 <- - getNodeSet(info$html, '//g[@class="geom1_point_ex"]//a//title') - rendered_titles1 <- sapply(title_nodes1, xmlValue) - expect_identical(sort(rendered_titles1), sort(displayed_countries)) - - # Hide all countries -> No titles - hide_these_second <- - c("plot_ex_region_variable_nor_label", - "plot_ex_region_variable_sou_label") - b <- apply_with_interval(clickID, hide_these_second, 1) - - Sys.sleep(2) - info$html <- getHTML() - - title_nodes2 <- - getNodeSet(info$html, '//g[@class="geom1_point_ex"]//a//title') - expect_equal(length(title_nodes2), 0) - - # Show previous points again and compare titles - b <- apply_with_interval(clickID, hide_these_second, 1) - - Sys.sleep(1) - info$html <- getHTML() - - title_nodes3 <- - getNodeSet(info$html, '//g[@class="geom1_point_ex"]//a//title') - rendered_titles3 <- sapply(title_nodes3, xmlValue) - expect_identical(sort(rendered_titles3), sort(displayed_countries)) -})