Skip to content

Implementing code coverage #208

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

Merged
merged 53 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
407162c
initial implementation for code coverage
suhaani-agarwal Jun 19, 2025
117dc25
added covr package
suhaani-agarwal Jun 19, 2025
8004af8
checking only js coverage
suhaani-agarwal Jun 19, 2025
94049e2
updated tests.yaml
suhaani-agarwal Jun 19, 2025
30ebdb4
updated tests.yaml
suhaani-agarwal Jun 23, 2025
b94919c
testing only r coverage
suhaani-agarwal Jun 23, 2025
d82f2cd
trying out a simpler approach
suhaani-agarwal Jun 23, 2025
d3dc471
updated tests.yaml
suhaani-agarwal Jun 23, 2025
2805a59
deleted unnecessary file
suhaani-agarwal Jun 24, 2025
cdf6b9c
trying out another method
suhaani-agarwal Jun 24, 2025
3359121
updated tests.yaml
suhaani-agarwal Jun 24, 2025
e8fe132
removed syntax error
suhaani-agarwal Jun 24, 2025
208c16c
added coverage
suhaani-agarwal Jun 24, 2025
8267779
added js coverage collection
suhaani-agarwal Jun 25, 2025
7108024
added codecov token to repository secrets
suhaani-agarwal Jul 1, 2025
9808c80
seperated coverage and increased chromote timeout
suhaani-agarwal Jul 1, 2025
ac28106
increased chromote timeout
suhaani-agarwal Jul 1, 2025
2b0f4a9
checking if the implementation works without the test causing timeout
suhaani-agarwal Jul 1, 2025
caa7f98
corrected js coverage collection
suhaani-agarwal Jul 2, 2025
fbe1f8c
removed syntax error in tests.yaml
suhaani-agarwal Jul 2, 2025
5812b69
updated testthat.R for correct JS coverage
suhaani-agarwal Jul 2, 2025
1383f40
corrected path for js coverage file save
suhaani-agarwal Jul 2, 2025
4f4db04
removed error from tests.yaml
suhaani-agarwal Jul 2, 2025
e2f1375
removed npx
suhaani-agarwal Jul 2, 2025
946b536
removed -g in installation
suhaani-agarwal Jul 2, 2025
0e0a638
replaced npx with paths
suhaani-agarwal Jul 2, 2025
03aa950
corrected node installation path
suhaani-agarwal Jul 3, 2025
fc2e1a1
corrected node installation path
suhaani-agarwal Jul 3, 2025
d528af2
shifted installation of node to last step
suhaani-agarwal Jul 3, 2025
b684b6c
replaced npx
suhaani-agarwal Jul 3, 2025
9aaf93d
using /usr/bin/sudo
suhaani-agarwal Jul 3, 2025
731ee38
installing node with different approach
suhaani-agarwal Jul 3, 2025
4c48e59
installing node
suhaani-agarwal Jul 4, 2025
6f962e8
updated installing node
suhaani-agarwal Jul 4, 2025
7ff84ae
manually converting raw coverage to lcov
suhaani-agarwal Jul 4, 2025
070d92b
updated conversion function for all js files
suhaani-agarwal Jul 4, 2025
0ac7a38
added test to check if the coverage conversion works correctly
suhaani-agarwal Jul 4, 2025
e4d8ac8
updated conversion function
suhaani-agarwal Jul 4, 2025
f15d318
using v8-to-istanbul.js
suhaani-agarwal Jul 8, 2025
9449b09
removed unnecessary changes and ignoring files under vendor/
suhaani-agarwal Jul 8, 2025
ca8ebb1
added Node.js related files to .Rbuildignore
suhaani-agarwal Jul 8, 2025
4ed642a
bringing the PredictedPeaks test back (caused problem - chromote time…
suhaani-agarwal Jul 8, 2025
50ef480
cran check will now fail for WARNING and NOTE
suhaani-agarwal Jul 8, 2025
9618971
updated build.sh to add cran check fail for warnings and notes
suhaani-agarwal Jul 8, 2025
2e54580
added v8-to-istanbul.js to .Rbuildignore
suhaani-agarwal Jul 9, 2025
aa40873
added echo in build.sh and increased chromote timeout
suhaani-agarwal Jul 9, 2025
3bf89cf
made PredictedPeaks test lighter
suhaani-agarwal Jul 10, 2025
a4333bd
updated repo name in README and removed addition of empty spaces
suhaani-agarwal Jul 10, 2025
1e46b2e
added copy of dataset, improved indentations, brought back 2 deleted …
suhaani-agarwal Jul 10, 2025
54eeac5
added test case for chroms and oneChrom for 2nd viz
suhaani-agarwal Jul 10, 2025
94d0b0e
updated NEWS.md
suhaani-agarwal Jul 10, 2025
cba32ec
updated NEWS.md
suhaani-agarwal Jul 10, 2025
1065d7f
version++
suhaani-agarwal Jul 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ test-compiler-gist.R
^docs$
^pkgdown$
^\.github$
^package\.json$
^package-lock\.json$
^node_modules/
^v8-to-istanbul\.js$
47 changes: 46 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
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
- name: install and update texlive
Expand All @@ -35,6 +37,49 @@ jobs:

- name: git config user.email
run: git config --global user.email [email protected]

- name: Setup Node.js
if: matrix.test-suite == 'renderer'
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install Node.js dependencies
if: matrix.test-suite == 'renderer'
run: |
npm install v8-to-istanbul
echo "Node modules installed"

- name: run tests
run: if [ "$TEST_SUITE" == "CRAN" ];then bash build.sh;else Rscript -e "source('tests/testthat.R', chdir = TRUE)";fi
run: |
if [ "$TEST_SUITE" == "CRAN" ]; then
bash build.sh
elif [ "$TEST_SUITE" == "compiler" ]; then
Rscript -e "source('tests/testthat.R', chdir = TRUE)"
Rscript -e 'covr::codecov(quiet = TRUE)'
else
Rscript -e "source('tests/testthat.R', chdir = TRUE)"
fi

- name: Convert JS coverage to Istanbul format
if: matrix.test-suite == 'renderer'
run: |
if [ -f "tests/testthat/js-coverage.json" ]; then
echo "Converting JS coverage to LCOV format..."
node v8-to-istanbul.js
else
echo "No JS coverage file found"
exit 1
fi

- name: Upload JS coverage to Codecov
if: matrix.test-suite == 'renderer'
run: |
if [ -f "coverage-istanbul.json" ]; then
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -f coverage-istanbul.json -t ${{ secrets.CODECOV_TOKEN }} --flags javascript
else
echo "No coverage file found"
exit 1
fi
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
*ANIMINT_TEST_FOO
*pids.txt
*~
.vscode/settings.json
.vscode/settings.jsonnode_modules/
node_modules/
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: animint2
Title: Animated Interactive Grammar of Graphics
Version: 2025.6.28
Version: 2025.7.10
URL: https://animint.github.io/animint2/
BugReports: https://github.com/animint/animint2/issues
Authors@R: c(
Expand Down Expand Up @@ -89,6 +89,7 @@ Suggests:
sp,
gistr (>= 0.2),
shiny,
covr,
RColorBrewer,
htmltools,
rmarkdown,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Changes in version 2025.7.10 (PR#208)

- Added Codecov integration for both R and JavaScript tests; coverage reports now available at https://app.codecov.io/github/animint/animint2

# Changes in version 2025.6.28 (PR#204)

- The geom_raster implementation has been removed.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Play around with [this interactive data visualization of data from the World Ban

To learn how to generate your own interactive data visualizations, go to the official [Animint2 Manual](https://rcdata.nau.edu/genomic-ml/animint2-manual/Ch00-preface.html). If you encounter problems, please see the [animint2 wiki](https://github.com/animint/animint2/wiki) or [report them](https://github.com/animint/animint2/issues).

[![codecov](https://codecov.io/gh/animint/animint2/branch/main/graph/badge.svg)](https://codecov.io/gh/animint/animint2)

## Installation

``` r
Expand Down
17 changes: 16 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -o errexit
set -o pipefail
R -e 'devtools::document()'
cd ..
rm -rf animint2-release
Expand Down Expand Up @@ -30,4 +31,18 @@ EOF
PKG_TGZ=$(R CMD build animint2-release|grep building|sed "s/.*\(animint2.*.tar.gz\).*/\1/")
echo built $PKG_TGZ so now we INSTALL
R CMD INSTALL $PKG_TGZ
R CMD check --as-cran $PKG_TGZ
echo "Running R CMD check --as-cran $PKG_TGZ"
check_output=$(R CMD check --as-cran $PKG_TGZ 2>&1)
check_status=$?
echo "$check_output"
# Check for WARNINGs or NOTEs in the output
if echo "$check_output" | grep -q -E "WARNING|NOTE"; then
echo "CRAN check generated WARNINGs or NOTEs:"
exit 1
fi
# Exit with original status if no WARNINGs/NOTEs but check failed
if [ $check_status -ne 0 ]; then
echo "R CMD check failed with status $check_status"
exit $check_status
fi
echo "CRAN check completed successfully"
9 changes: 9 additions & 0 deletions inst/htmljs/animint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,15 @@
}
return selected_values;
};

// DEAD CODE FOR COVERAGE TESTING
function deadCodeForCoverage() {
// This function is never called and should show as uncovered in coverage reports.
var unused = 42;
if (unused === 43) {
console.log("This should never be printed.");
}
}

Check warning on line 1728 in inst/htmljs/animint.js

View check run for this annotation

Codecov / codecov/patch

inst/htmljs/animint.js#L1723-L1728

Added lines #L1723 - L1728 were not covered by tests

// update scales for the plots that have update_axes option in
// theme_animint
Expand Down
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "animint2",
"version": "1.0.0",
"description": "<a href=\"https://github.com/tdhock/animint2/actions/workflows/tests.yaml\"> \t<img src=\"https://github.com/tdhock/animint2/actions/workflows/tests.yaml/badge.svg\" \t alt=\"A badge verifying if this package has passed all its tests.\"> </a> <!-- Feel free to change the HTML block above this comment into Markdown. It's just in HTML cuz I couldn't be arsed to figure out how to correctly combine an image and a link in Github-flavored Markdown. -->",
"main": "index.js",
"directories": {
"doc": "docs",
"man": "man",
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/animint/animint2.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/animint/animint2/issues"
},
"homepage": "https://github.com/animint/animint2#readme",
"dependencies": {
"v8-to-istanbul": "^9.3.0"
}
}
26 changes: 23 additions & 3 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,30 @@ source("helper-plot-data.r")
filter <- Sys.getenv("TEST_SUITE")
gh.action <- Sys.getenv("GH_ACTION")
use.browser <- grepl("renderer", filter)
collect.coverage <- Sys.getenv("COLLECT_COVERAGE", "FALSE") == "TRUE"
if(filter == ""){
filter <- NULL
}
message(gh.action)
if(use.browser)tests_init()
tests_run(filter=filter)
if(use.browser)tests_exit()

if(use.browser) {
tests_init()
# Start coverage if enabled
coverage_active <- FALSE
if(collect.coverage) {
coverage_active <- start_js_coverage()
if(coverage_active) {
message("JS coverage collection started")
}
}
# Run tests
tests_run(filter=filter)
# Save coverage and cleanup
if(coverage_active) {
stop_js_coverage()
}
tests_exit()
} else {
# Non-browser tests
tests_run(filter=filter)
}
37 changes: 37 additions & 0 deletions tests/testthat/helper-HTML.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ tests_init <- function(dir = ".", ...) {
unlink(testDir, recursive = TRUE)
options(chromote.timeout = 120)
chrome.session <- chromote::ChromoteSession$new()
# Enable required DevTools domains for coverage
chrome.session$Runtime$enable()
chrome.session$Profiler$enable()

chrome.session$view()
chrome.session$refresh <- function(){
## from https://github.com/rstudio/chromote?tab=readme-ov-file#loading-a-page-reliably
Expand Down Expand Up @@ -104,3 +108,36 @@ getClassBound <- function(geom.class, position){
Sys.sleep(2)
runtime_evaluate(script=script.txt)
}

# JS Coverage collection functions
start_js_coverage <- function() {
tryCatch({
remDr$Profiler$enable()
remDr$Profiler$startPreciseCoverage(
callCount = TRUE,
detailed = TRUE
)
TRUE
}, error = function(e) {
warning("Failed to start JS coverage: ", e$message)
FALSE
})
}

stop_js_coverage <- function() {
tryCatch({
cov <- remDr$Profiler$takePreciseCoverage()
outfile <- "js-coverage.json"
# Ensure the format matches what v8-to-istanbul expects
coverage_data <- list(
result = cov$result,
url = "http://localhost:4848/animint-htmltest/animint.js"
)
jsonlite::write_json(coverage_data, outfile, auto_unbox = TRUE)
message("JS coverage saved to ", normalizePath(outfile))
TRUE
}, error = function(e) {
warning("Failed to save JS coverage: ", e$message)
FALSE
})
}
1 change: 1 addition & 0 deletions tests/testthat/test-compiler-ghpages.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ test_that("animint2pages() returns list of meta-data", {
})

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")
env.old <- Sys.getenv(env.names)
Sys.unsetenv(env.names)
Expand Down
Loading