From 6b0684de90be4b065bac797daf42afda2976f6de Mon Sep 17 00:00:00 2001 From: Kamil Zyla Date: Thu, 18 Jan 2024 17:11:24 +0100 Subject: [PATCH] test: Add E2E test for RHINO_NPM env var --- .github/workflows/e2e-test.yml | 7 +++++++ tests/e2e/test-custom-npm.R | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/e2e/test-custom-npm.R diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 9ff2ecdf..2be0b0f1 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -65,6 +65,13 @@ jobs: cd RhinoApp Rscript ../test-dependencies.R + - name: Node.js commands should respect RHINO_NPM + # Skip this test on Windows because it requires a Unix shell. + if: runner.os != 'Windows' + run: | + cd RhinoApp + Rscript ../test-custom-npm.R + - name: lint_r() should detect lint errors in R scripts if: always() run: | diff --git a/tests/e2e/test-custom-npm.R b/tests/e2e/test-custom-npm.R new file mode 100644 index 00000000..91f43a44 --- /dev/null +++ b/tests/e2e/test-custom-npm.R @@ -0,0 +1,22 @@ +local({ + tmp <- withr::local_tempdir() + wrapper_path <- fs::path(tmp, "wrapper") + touch_path <- fs::path(tmp, "it_works") + + # Prepare a wrapper script which creates an "it_works" file and runs npm. + fs::file_create(wrapper_path, mode = "u=rwx") + writeLines( + c( + "#!/bin/sh", + paste("touch", touch_path), + 'exec npm "$@"' + ), + wrapper_path + ) + + # Use the wrapper script instead of npm. + withr::local_envvar(RHINO_NPM = wrapper_path) + rhino:::npm("--version") + + testthat::expect_true(fs::file_exists(touch_path)) +})