Skip to content

chore(themes): add additional tests for css variable completions#127

Open
coryrylan wants to merge 1 commit into
mainfrom
topic-cleanup-themes
Open

chore(themes): add additional tests for css variable completions#127
coryrylan wants to merge 1 commit into
mainfrom
topic-cleanup-themes

Conversation

@coryrylan

@coryrylan coryrylan commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests for CSS variable token completions, token validation, theme selector generation, and integration tests validating compiled theme CSS outputs.
  • Chores
    • Refactored theme build tooling into modular, ESM-friendly functions and added a Vitest config and package test task.
  • Bug Fixes
    • Improved token reference resolution with explicit cycle and missing-reference errors.

@coryrylan coryrylan requested a review from johnyanarella June 9, 2026 00:58
@coryrylan coryrylan self-assigned this Jun 9, 2026
@github-actions github-actions Bot added scope(themes) dependencies Pull requests that update a dependency file labels Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors the themes build scripts from side-effect modules into reusable ESM-compatible modules, extracting internal helpers into exported functions, implementing explicit cycle detection for token resolution, and adding comprehensive test coverage integrated into the build and CI pipeline.

Changes

Build Script Modularization and Testing

Layer / File(s) Summary
CSS variable completions helper functions
projects/themes/build/css-var-completions.js
Core helpers (readJSONFile, writeJSONFile, isObject, visitTokenTree, loadTokenDictionary) are exported as reusable utilities for file I/O and token tree traversal.
Token resolution and orchestration
projects/themes/build/css-var-completions.js
resolveTokenValue is refactored to recursive resolution with explicit cycle detection via referencePath parameter. Token categorization and matching helpers are exported. Consolidation and CSS variable mapping are moved from module-load time into exported createCssVarCompletions and buildCssVarCompletions functions, with module execution gated by ESM entrypoint check.
CSS variable completions test coverage
projects/themes/build/css-var-completions.test.js
Vitest suite validates completion output structure, token reference resolution across theme variants, value collapsing, and error handling for unresolved and cyclic token references.
Style dictionary validation and theme selector
projects/themes/build/style-dictionary.config.js
ESM imports added for direct-execution guard. Inline token validation is extracted into exported validateTokenValue with descriptive errors. Theme selector generation centralized in exported getThemeSelector. buildTokens exported and unconditional call replaced with conditional direct-execution check.
Style dictionary config test coverage
projects/themes/build/style-dictionary.config.test.js
Vitest suite validates validateTokenValue rejection/acceptance of raw colors and sizing values across token types and theme exceptions, and verifies getThemeSelector returns correct CSS selectors.
Generated CSS output validation
projects/themes/src/index.test.ts
Integration test validates compiled CSS output for theme variants contains expected selectors, token overrides, scale adjustments, and animation duration changes.
Vitest configuration and build pipeline wiring
projects/themes/vitest.config.ts, projects/themes/package.json
Vitest config defines test file discovery. package.json adds test script, integrates tests into CI dependencies, adds build/fonts.js as tracked input, and introduces wireit.test task with file tracking and build/vite dependencies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type(chore)

Suggested reviewers

  • johnyanarella
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title claims the PR adds tests, but the actual changes include substantial refactoring of build modules with module-level structural changes and new exports. Update the title to reflect the primary change: refactoring css-var-completions.js and style-dictionary.config.js into reusable, ESM-compatible modules with added tests.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch topic-cleanup-themes

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Cory Rylan <crylan@nvidia.com>
@coryrylan coryrylan force-pushed the topic-cleanup-themes branch from 57bb039 to 20eb61b Compare June 9, 2026 01:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@projects/themes/build/css-var-completions.js`:
- Around line 167-187: The code constructs file paths using template literals
with sourcePath and buildPath (used in buildCssVarCompletions,
loadTokenDictionary calls and fs.mkdirSync/writeJSONFile) while sourcePath is
defined with a trailing slash, producing double slashes; change all path
constructions to use path.join (e.g., replace `${sourcePath}/index.json` etc.)
or normalize by removing trailing slashes from sourcePath and buildPath and
updating calls to loadTokenDictionary, fs.existsSync/fs.mkdirSync, and
writeJSONFile to use the normalized paths so you never emit '//'. Ensure you
import/require path if switching to path.join.

In `@projects/themes/package.json`:
- Line 49: The project currently lists the devDependency
"`@vitest/coverage-istanbul`" but the Vitest invocation in
projects/themes/package.json doesn't pass --coverage, so coverage
provider/config in projects/themes/vitest.config.ts (which merges
libraryNodeTestConfig) never runs; either add --coverage to the Vitest CLI used
in the package.json script that runs Vitest so the existing coverage
configuration in vitest.config.ts is applied, or if you don't intend to run
coverage from this package remove the "`@vitest/coverage-istanbul`" entry; locate
the Vitest-running script in projects/themes/package.json and update it (or
remove the dependency) accordingly, keeping vitest.config.ts and
libraryNodeTestConfig intact.

In `@projects/themes/src/index.test.ts`:
- Around line 7-9: The helper function readThemeCss lacks an explicit return
type; update its signature to declare the return type (e.g. async function
readThemeCss(theme: string): Promise<string>) so TypeScript knows it returns a
promise of a string, leaving the body using readFile as-is; ensure the
Promise<string> annotation matches the value returned by readFile in this
function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: acdeee5b-75cf-4f09-a9b1-f4fd6bf770ac

📥 Commits

Reviewing files that changed from the base of the PR and between 57bb039 and 20eb61b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • projects/themes/build/css-var-completions.js
  • projects/themes/build/css-var-completions.test.js
  • projects/themes/build/style-dictionary.config.js
  • projects/themes/build/style-dictionary.config.test.js
  • projects/themes/package.json
  • projects/themes/src/index.test.ts
  • projects/themes/vitest.config.ts

Comment on lines +167 to 187
export function buildCssVarCompletions() {
const baseTokenDictionary = loadTokenDictionary(`${sourcePath}/index.json`);
const compactThemeTokenDictionary = loadTokenDictionary(`${sourcePath}/compact.json`);
const darkThemeTokenDictionary = loadTokenDictionary(`${sourcePath}/dark.json`);
const highContrastThemeTokenDictionary = loadTokenDictionary(`${sourcePath}/high-contrast.json`);
const reducedMotionThemeTokenDictionary = loadTokenDictionary(`${sourcePath}/reduced-motion.json`);

const cssVarCompletions = createCssVarCompletions({
baseTokenDictionary,
compactThemeTokenDictionary,
darkThemeTokenDictionary,
highContrastThemeTokenDictionary,
reducedMotionThemeTokenDictionary
});

if (!fs.existsSync(`${buildPath}`)) {
fs.mkdirSync(`${buildPath}`);
}

writeJSONFile('./dist/data.css-vars.json', cssVarCompletions);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | 💤 Low value

Inconsistent path construction with sourcePath.

sourcePath is defined as 'src/' (line 7) with a trailing slash. Using template literals like `${sourcePath}/index.json` produces 'src//index.json'. While Node.js tolerates double slashes, this is inconsistent. Consider removing the trailing slash from sourcePath and buildPath, or use path.join() for all path construction.

Suggested path consistency fix
-const buildPath = 'dist/';
-const sourcePath = 'src/';
+const buildPath = 'dist';
+const sourcePath = 'src';

Then update usages accordingly, or use path.join(sourcePath, 'index.json') etc.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@projects/themes/build/css-var-completions.js` around lines 167 - 187, The
code constructs file paths using template literals with sourcePath and buildPath
(used in buildCssVarCompletions, loadTokenDictionary calls and
fs.mkdirSync/writeJSONFile) while sourcePath is defined with a trailing slash,
producing double slashes; change all path constructions to use path.join (e.g.,
replace `${sourcePath}/index.json` etc.) or normalize by removing trailing
slashes from sourcePath and buildPath and updating calls to loadTokenDictionary,
fs.existsSync/fs.mkdirSync, and writeJSONFile to use the normalized paths so you
never emit '//'. Ensure you import/require path if switching to path.join.

],
"devDependencies": {
"@internals/vite": "workspace:*",
"@vitest/coverage-istanbul": "catalog:",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check for coverage configuration in vitest configs and shared test setup

# Check for coverage configuration in local and shared configs
rg -n "coverage" vitest.config.ts
rg -n "coverage" projects/internals/vite/src/configs/test.node.js

Repository: NVIDIA/elements

Length of output: 514


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Find actual vitest config files
fd -t f -i 'vitest.config.ts' . || true
fd -t f -i '*vitest*.ts' projects . || true

# 2) Search for `@vitest/coverage-istanbul` usage
rg -n "`@vitest/coverage-istanbul`" . || true

# 3) Search for coverage config in likely Vitest config files
rg -n "coverage\s*:" projects/internals/vite/src/configs -S || true
rg -n "reportsDirectory|reporter|lcov|html|json-summary" projects/internals/vite/src/configs -S || true

# 4) Show how coverage is wired in shared configs (the file from initial run)
ls -la projects/internals/vite/src/configs || true
sed -n '1,120p' projects/internals/vite/src/configs/test.node.js || true

Repository: NVIDIA/elements

Length of output: 17052


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect themes vitest config
echo "=== projects/themes/vitest.config.ts ==="
sed -n '1,200p' projects/themes/vitest.config.ts || true

# Check for usage of shared libraryNodeTestConfig in themes config
echo "=== rg libraryNodeTestConfig usage (themes) ==="
rg -n "libraryNodeTestConfig" projects/themes || true

# Inspect themes package scripts for coverage usage
echo "=== projects/themes/package.json (scripts + vitest/coverage) ==="
rg -n "\"scripts\"" -n projects/themes/package.json || true
sed -n '1,220p' projects/themes/package.json || true

# Also search if themes config passes --coverage
echo "=== rg \"--coverage\" in themes ==="
rg -n "--coverage" projects/themes || true

Repository: NVIDIA/elements

Length of output: 6430


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find places that pass coverage to vitest (limit scope to repo)
rg -n "vitest(\s+run)?[^\n]*--coverage" . || true
rg -n "(^|\s)--coverage(\s|$)" projects -S || true

# Also check wireit internals/vite:ci for themes
rg -n "internals/vite:ci" -S projects/themes/package.json projects -g'*.json' || true

# Search for "coverage" in wireit scripts around vitest
rg -n "wireit" projects/internals/vite -S || true
rg -n "coverage" projects/internals/vite -S || true

Repository: NVIDIA/elements

Length of output: 7482


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,140p' projects/internals/vite/package.json || true
rg -n "\"ci\"" projects/internals/vite/package.json -n || true
# Show wireit section for ci task(s)
rg -n "wireit" -n projects/internals/vite/package.json || true

# Search for vitest command templates inside internals/vite
rg -n "vitest run" projects/internals/vite -S || true
rg -n "--coverage" projects/internals/vite -S || true

# If there is a wireit config file or scripts, find them
fd -t f projects/internals/vite -i 'wireit*' || true
fd -t f projects/internals/vite -i '*config*' || true

Repository: NVIDIA/elements

Length of output: 2626


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== rg coverage in projects/themes/package.json ==="
rg -n "coverage" projects/themes/package.json || true

echo "=== list themes vitest.* configs ==="
ls -ლა projects/themes/vitest* 2>/dev/null || true
fd -t f -i "vitest*.ts" projects/themes || true

echo "=== rg --coverage in projects/themes ==="
rg -n "--coverage" projects/themes || true

echo "=== rg coverage in projects/themes/vitest*.ts ==="
rg -n "coverage" projects/themes/vitest*.ts || true

Repository: NVIDIA/elements

Length of output: 882


Coverage tooling is already configured via the shared Vitest config

  • projects/themes/vitest.config.ts merges libraryNodeTestConfig from projects/internals/vite/src/configs/test.node.js, which already defines coverage (provider istanbul, reports/thresholds, etc.), so @vitest/coverage-istanbul is intentional for coverage runs.
  • projects/themes/package.json runs vitest run --config=vitest.config.ts (and lighthouse/visual) without --coverage, so coverage reports/threshold enforcement will only happen when Vitest is invoked with --coverage in CI or a follow-up task.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@projects/themes/package.json` at line 49, The project currently lists the
devDependency "`@vitest/coverage-istanbul`" but the Vitest invocation in
projects/themes/package.json doesn't pass --coverage, so coverage
provider/config in projects/themes/vitest.config.ts (which merges
libraryNodeTestConfig) never runs; either add --coverage to the Vitest CLI used
in the package.json script that runs Vitest so the existing coverage
configuration in vitest.config.ts is applied, or if you don't intend to run
coverage from this package remove the "`@vitest/coverage-istanbul`" entry; locate
the Vitest-running script in projects/themes/package.json and update it (or
remove the dependency) accordingly, keeping vitest.config.ts and
libraryNodeTestConfig intact.

Comment on lines +7 to +9
async function readThemeCss(theme: string) {
return readFile(new URL(`../dist/${theme}.css`, import.meta.url), 'utf8');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add explicit return type annotation.

The readThemeCss helper function should explicitly declare its return type for better type safety and code clarity. As per coding guidelines, TypeScript code should follow type safety best practices.

📝 Suggested improvement
-async function readThemeCss(theme: string) {
+async function readThemeCss(theme: string): Promise<string> {
   return readFile(new URL(`../dist/${theme}.css`, import.meta.url), 'utf8');
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@projects/themes/src/index.test.ts` around lines 7 - 9, The helper function
readThemeCss lacks an explicit return type; update its signature to declare the
return type (e.g. async function readThemeCss(theme: string): Promise<string>)
so TypeScript knows it returns a promise of a string, leaving the body using
readFile as-is; ensure the Promise<string> annotation matches the value returned
by readFile in this function.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file scope(ci) scope(themes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant