Skip to content

Commit 6c8a9b1

Browse files
authored
Merge pull request #13939 from quarto-dev/tests/configure-test-new-deps
Improve scripts for test environment configuration
2 parents f14ae36 + 2b3244f commit 6c8a9b1

8 files changed

Lines changed: 307 additions & 54 deletions

File tree

.github/workflows/test-smokes.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
9595
- name: Install node dependencies
9696
if: ${{ runner.os != 'Windows' || github.event_name == 'schedule' }}
97-
run: yarn
97+
run: npm install --loglevel=error --no-audit
9898
working-directory: ./tests/integration/playwright
9999
shell: bash
100100

@@ -105,7 +105,7 @@ jobs:
105105

106106
- name: Install MECA validator
107107
if: ${{ runner.os != 'Windows' }}
108-
run: npm install -g meca
108+
run: npm install -g meca --loglevel=error --no-audit
109109

110110
- name: Set RENV_PATHS_ROOT
111111
shell: bash

tests/README.md

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,44 @@ Running tests require to have a local environment setup with Quarto development,
3535
To help with this configuration, the `tests/` folder contains `configure-test-env.sh` and `configure-test-env.ps1`. It will check for the tools and update the dependencies to what is used by Quarto tests.
3636
Running the script at least one will insure you are correctly setup. Then, it is run as part of running the tests so that dependencies are always updated. Set `QUARTO_TESTS_NO_CONFIG` to skip this step when running tests.
3737

38+
#### Optional test dependencies
39+
40+
The configure scripts also check for optional tools that some tests require. Tests will gracefully skip when these tools are not available, but having them installed enables full test coverage:
41+
42+
**Java** (version 8, 11, 17, or 21)
43+
44+
- Required for: PDF standard validation tests using veraPDF
45+
- The script will install veraPDF automatically if Java is found using `quarto install verapdf`
46+
47+
**Node.js** (version 18 or later) and **npm**
48+
49+
- Required for: Playwright integration tests and JATS/MECA validation
50+
- Installation: Download from https://nodejs.org/ or use a version manager like nvm
51+
- The script will:
52+
- Check Node.js version and warn if < 18
53+
- Install the `meca` package globally for MECA validation
54+
- Install Playwright and its dependencies
55+
- Set up the multiplex server for Playwright tests
56+
- Install Playwright browsers (Chrome, Firefox, etc.)
57+
58+
**pdftotext** (from poppler)
59+
60+
- Required for: Some PDF text extraction tests
61+
- Installation:
62+
- Ubuntu/Debian: `sudo apt-get install poppler-utils`
63+
- macOS: `brew install poppler`
64+
- Windows: `scoop install poppler` (auto-installed if Scoop is available)
65+
66+
**rsvg-convert** (from librsvg)
67+
68+
- Required for: PDF tests with SVG image conversion
69+
- Installation:
70+
- Ubuntu/Debian: `sudo apt-get install librsvg2-bin`
71+
- macOS: `brew install librsvg`
72+
- Windows: `scoop install librsvg` (auto-installed if Scoop is available)
73+
74+
On Windows, the scripts will attempt to auto-install poppler and librsvg via Scoop if it's available on your system.
75+
3876
Dependencies are managed using the following tools:
3977

4078
#### R
@@ -102,20 +140,80 @@ Tests are run using `run-tests.sh` on UNIX, and `run-tests.ps1` on Windows.
102140
./run-tests.ps1 smoke/extensions/extension-render-doc.test.ts
103141
```
104142

105-
#### Prevent configuration for dependencies (R, Julia, Python, ...)
143+
#### Test environment variables
144+
145+
The test scripts support several environment variables to control their behavior:
106146

107-
Those files will run `configure-test-env` scripts to check for requirements and set up dependencies (except on Github Action as this is done in the workflow file directly).
108-
You can prevent test configuration locally by setting `QUARTO_TESTS_NO_CONFIG` environment variable to a non-empty value.
147+
**QUARTO_TESTS_NO_CONFIG**
148+
- Skip running `configure-test-env` scripts
149+
- Useful for faster test runs when environment is already configured
150+
- Tests will still activate `.venv` if present
109151

110152
```bash
111153
QUARTO_TESTS_NO_CONFIG="true" ./run-tests.sh
112154
```
113155

114156
```powershell
115-
$env:QUARTO_TESTS_NO_CONFIG=$true
157+
$env:QUARTO_TESTS_NO_CONFIG="true"
158+
./run-tests.ps1
159+
```
160+
161+
**QUARTO_TESTS_FORCE_NO_VENV** (replaces deprecated `QUARTO_TESTS_FORCE_NO_PIPENV`)
162+
- Skip activating the `.venv` virtual environment
163+
- Tests will use system Python packages instead of UV-managed dependencies
164+
- Use with caution: Python tests may fail if dependencies aren't in system Python
165+
166+
```bash
167+
QUARTO_TESTS_FORCE_NO_VENV="true" ./run-tests.sh
168+
```
169+
170+
```powershell
171+
$env:QUARTO_TESTS_FORCE_NO_VENV="true"
116172
./run-tests.ps1
117173
```
118174

175+
**Quick test runs with run-fast-tests scripts**
176+
177+
For convenience, `run-fast-tests.sh` and `run-fast-tests.ps1` are provided to skip environment configuration:
178+
179+
```bash
180+
# Linux/macOS
181+
./run-fast-tests.sh
182+
183+
# Windows
184+
./run-fast-tests.ps1
185+
```
186+
187+
These scripts set `QUARTO_TESTS_NO_CONFIG` automatically. Use after running `configure-test-env` at least once.
188+
189+
**QUARTO_TEST_KEEP_OUTPUTS** (or use `--keep-outputs`/`-k` flag)
190+
- Keep test output artifacts instead of cleaning them up
191+
- Useful for debugging test failures or inspecting generated files
192+
- Can be set via environment variable or command-line flag
193+
194+
```bash
195+
# Using flag
196+
./run-tests.sh --keep-outputs
197+
./run-tests.sh -k
198+
199+
# Using environment variable
200+
QUARTO_TEST_KEEP_OUTPUTS="true" ./run-tests.sh
201+
```
202+
203+
```powershell
204+
# Using flag
205+
./run-tests.ps1 --keep-outputs
206+
./run-tests.ps1 -k
207+
208+
# Using environment variable
209+
$env:QUARTO_TEST_KEEP_OUTPUTS="true"
210+
./run-tests.ps1
211+
```
212+
213+
**Other environment variables**
214+
- `QUARTO_TEST_VERBOSE` - Enable verbose test output
215+
- `QUARTO_TESTS_NO_CHECK` - Not currently used (legacy variable)
216+
119217
#### About smoke-all tests
120218

121219
`docs/smoke-all/` is a specific folder to run some tests written directly within `.qmd`, `.md` or `.ipynb` files (but files starting with `_` will be ignored). They are run through the `smoke/smoke-all.tests.ts` script. To ease running smoke-all tests, `run-tests.sh` has a special behavior where it will run `./smoke/smoke-all.tests.ts` when passed a `.qmd`, `.md` or `.ipynb` file, not starting with `_`.
@@ -284,6 +382,7 @@ _quarto:
284382
The snapshot file should be saved alongside the output with a `.snapshot` extension (e.g., `output.html.snapshot`).
285383

286384
When a snapshot test fails:
385+
287386
- A **unified diff** is displayed with colored output (red for removed, green for added)
288387
- A **word-level diff** shows changes with surrounding context
289388
- For **whitespace-only changes**, special markers visualize invisible characters:

tests/configure-test-env.ps1

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,68 @@ If ([string]::IsNullOrEmpty($env:GH_TOKEN)) {
4747
}
4848
quarto install tinytex
4949

50-
# Get npm in place
50+
# Check for veraPDF (and Java) as the tool is required for PDF standard validation tests
51+
Write-Host -ForegroundColor green ">>>> Checking Java for veraPDF"
52+
try { $null = gcm java -ea stop; $java=$true } catch {
53+
Write-Host -ForegroundColor red "No java found in PATH - veraPDF requires Java to be installed."
54+
Write-Host -ForegroundColor red "Install Java and add to PATH if you need PDF standard validation tests."
55+
Write-Host -ForegroundColor red "See: https://www.java.com/en/download/"
56+
}
57+
58+
If ($java) {
59+
$javaVersion = java -version 2>&1 | Select-Object -First 1
60+
Write-Host "Java found: $javaVersion"
61+
}
62+
63+
Write-Host -ForegroundColor green ">>>> Installing veraPDF for PDF standard validation"
64+
If ($java) {
65+
quarto install verapdf
66+
} Else {
67+
Write-Host -ForegroundColor yellow "Skipping veraPDF installation (Java not found)"
68+
}
69+
70+
# Check Node.js and npm ---
5171
Write-Host -ForegroundColor green ">>>> Configuring npm for MECA testing environment"
72+
try {$null = gcm node -ea stop; $node_exists=$true } catch {
73+
Write-Host -ForegroundColor red "No node found - will skip any tests that require npm (e.g. JATS / MECA validation)"
74+
}
5275
try {$null = gcm npm -ea stop; $npm_exists=$true } catch {
53-
Write-Host -ForegroundColor red "No npm found - will skip any tests that require npm (e.g. JATS / MECA validation)"
76+
Write-Host -ForegroundColor red "No npm found - npm is required but node is present"
77+
}
78+
79+
If ($node_exists) {
80+
If ($npm_exists) {
81+
# Check Node.js version
82+
$nodeVersionFull = node -v
83+
$nodeVersion = [int]($nodeVersionFull -replace 'v(\d+)\..*','$1')
84+
Write-Host "Node.js version: $nodeVersionFull"
85+
If ($nodeVersion -lt 18) {
86+
Write-Host -ForegroundColor yellow "Warning: Node.js version $nodeVersion is older than recommended (18+)"
87+
Write-Host -ForegroundColor yellow "Some tests may fail. Consider upgrading Node.js."
88+
}
89+
Write-Host "Setting up npm testing environment"
90+
npm install -g meca --loglevel=error --no-audit
91+
}
5492
}
93+
94+
# Setup Playwright for browser testing ---
95+
Write-Host -ForegroundColor green ">>>> Configuring Playwright for integration tests"
5596
If ($npm_exists) {
56-
# TODO: Check to do equivalent of virtualenv
57-
Write-Host "Setting up npm testing environment"
58-
npm install -g meca
97+
Write-Host "Installing Playwright dependencies..."
98+
Push-Location integration/playwright
99+
npm install --loglevel=error --no-audit
100+
# Install multiplex server dependencies
101+
Write-Host "Installing multiplex server dependencies..."
102+
Push-Location multiplex-server
103+
npm install --loglevel=error --no-audit
104+
Pop-Location
105+
# On Windows, npx playwright install --with-deps works without admin rights
106+
Write-Host "Installing Playwright browsers..."
107+
npx playwright install --with-deps
108+
Pop-Location
109+
Write-Host "Playwright browsers installed."
110+
} Else {
111+
Write-Host -ForegroundColor yellow "Skipping Playwright setup (npm not found)"
59112
}
60113

61114
# Other tests dependencies
@@ -66,7 +119,21 @@ try {$null = gcm pdftotext -ea stop; $pdftotext=$true } catch {
66119
Write-Host -ForegroundColor red "No scoop found - Scoop is a package manager for Windows - see https://scoop.sh/ and it can install poppler"
67120
}
68121
If($scoop) {
69-
Write-Host -ForegroundColor green "Scoop is found so trying to install poppler for pdftotext"
122+
Write-Host -ForegroundColor green "Scoop is found so trying to install poppler for pdftotext"
70123
scoop install poppler
71124
}
125+
}
126+
127+
# Check rsvg-convert for SVG conversion ---
128+
Write-Host -ForegroundColor green ">>>> Checking rsvg-convert from librsvg"
129+
try {$null = gcm rsvg-convert -ea stop; $rsvg=$true } catch {
130+
Write-Host -ForegroundColor red "No rsvg-convert found - Some PDF tests with SVG images will be skipped."
131+
Write-Host -ForegroundColor yellow "Install librsvg to enable SVG to PDF conversion tests:"
132+
try {$null = gcm scoop -ea stop; $scoop=$true } catch {}
133+
If($scoop) {
134+
Write-Host -ForegroundColor green "Scoop is found, trying to install librsvg"
135+
scoop install librsvg
136+
} Else {
137+
Write-Host -ForegroundColor red "Consider installing scoop (https://scoop.sh/) to easily install librsvg"
138+
}
72139
}

tests/configure-test-env.sh

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,95 @@ then
5353
export GH_TOKEN=$(gh auth token)
5454
fi
5555

56-
if [ -n $(command -v quarto) ]
56+
if [ -n $(command -v quarto) ]
5757
then
5858
quarto install tinytex
5959
fi
6060

61-
# Get npm in place
61+
# Check for veraPDF (and Java) as the tool is required for PDF standard validation tests
62+
echo ">>>> Checking Java for veraPDF"
63+
java_exists=$(command -v java)
64+
if [ -z $java_exists ]
65+
then
66+
echo "No java found in PATH - veraPDF requires Java to be installed."
67+
echo "Install Java and add to PATH if you need PDF standard validation tests."
68+
echo "See: https://www.java.com/en/download/"
69+
else
70+
echo "Java found: $(java -version 2>&1 | head -n 1)"
71+
fi
72+
73+
# Install veraPDF for PDF standard validation ---
74+
echo ">>>> Installing veraPDF for PDF standard validation"
75+
if [ -n $(command -v quarto) ]
76+
then
77+
if [ -n "$java_exists" ]
78+
then
79+
quarto install verapdf
80+
else
81+
echo "Skipping veraPDF installation (Java not found)"
82+
fi
83+
else
84+
echo "Skipping veraPDF installation (quarto not found)"
85+
fi
86+
87+
# Check Node.js and npm ---
6288
echo ">>>> Configuring npm for MECA testing environment"
89+
node_exists=$(command -v node)
6390
npm_exists=$(command -v npm)
64-
if [ -z $npm_exists ]
91+
if [ -z $node_exists ]
92+
then
93+
echo "No node found - will skip any tests that require npm (e.g. JATS / MECA validation)"
94+
elif [ -z $npm_exists ]
6595
then
66-
echo "No npm found - will skip any tests that require npm (e.g. JATS / MECA validation)"
96+
echo "No npm found - npm is required but node is present"
6797
else
98+
# Check Node.js version
99+
node_version=$(node -v | sed 's/v//' | cut -d. -f1)
100+
echo "Node.js version: $(node -v)"
101+
if [ "$node_version" -lt 18 ]; then
102+
echo "Warning: Node.js version $node_version is older than recommended (18+)"
103+
echo "Some tests may fail. Consider upgrading Node.js."
104+
fi
68105
echo "Setting up npm testing environment"
69-
npm install -g meca
106+
npm install -g meca --loglevel=error --no-audit
107+
fi
108+
109+
# Setup Playwright for browser testing ---
110+
echo ">>>> Configuring Playwright for integration tests"
111+
if [ -n "$npm_exists" ]
112+
then
113+
echo "Installing Playwright dependencies..."
114+
pushd integration/playwright > /dev/null
115+
npm install --loglevel=error --no-audit
116+
# Install multiplex server dependencies
117+
echo "Installing multiplex server dependencies..."
118+
pushd multiplex-server > /dev/null
119+
npm install --loglevel=error --no-audit
120+
popd > /dev/null
121+
# Try to install browsers with --with-deps (may require sudo on Linux/macOS)
122+
echo "Installing Playwright browsers..."
123+
npx playwright install --with-deps || echo "Note: Browser installation may require sudo. Run manually: npx playwright install --with-deps"
124+
popd > /dev/null
125+
else
126+
echo "Skipping Playwright setup (npm not found)"
70127
fi
71128

72-
# Get npm in place
129+
# Check pdftotext ---
73130
echo ">>>> Do you have pdftotext installed (from poppler) ?"
74131
pdftotext_exists=$(command -v pdftotext)
75132
if [ -z $pdftotext_exists ]
76133
then
77134
echo "No pdftotext found - Some tests will require it, so you may want to install it."
135+
fi
136+
137+
# Check rsvg-convert for SVG conversion ---
138+
echo ">>>> Do you have rsvg-convert installed (from librsvg) ?"
139+
rsvg_exists=$(command -v rsvg-convert)
140+
if [ -z $rsvg_exists ]
141+
then
142+
echo "No rsvg-convert found - Some PDF tests with SVG images will be skipped."
143+
echo "Install librsvg to enable SVG to PDF conversion tests:"
144+
echo " - Ubuntu/Debian: sudo apt-get install librsvg2-bin"
145+
echo " - macOS: brew install librsvg"
146+
echo " - Windows: scoop install librsvg"
78147
fi

tests/integration/playwright/yarn.lock

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/run-fast-tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Run tests without reconfiguring the environment (faster for repeated test runs)
2+
#
3+
# Environment variables set:
4+
# QUARTO_TESTS_NO_CONFIG - Skip running configure-test-env.ps1
5+
# (don't reinstall/update R, Python, Julia dependencies)
6+
#
7+
# Note: This still activates .venv if present, so Python tests use correct dependencies.
8+
# Only use after running configure-test-env.ps1 at least once to set up environment.
9+
10+
$env:QUARTO_TESTS_NO_CONFIG="true"
11+
& .\run-tests.ps1 @args

0 commit comments

Comments
 (0)