chore: add a new test case for test#2400
Conversation
🦋 Changeset detectedLatest commit: acb2a75 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughA Changesets markdown file was added with minimal content, and two unit tests were introduced to validate that inline style transformation correctly preserves CSS custom property expressions (with and without fallback values) in the color property. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/web-platform/web-core/src/style_transformer/inline_style.rs (2)
192-203: Consider adding edge case coverage for CSS variables.The existing color transformation tests (lines 143-160) include variations for whitespace and
!importantmodifiers. Consider adding similar coverage for CSS variables to ensure robust handling:
- Whitespace:
" color : var(--color) ;"- Important modifier:
"color: var(--color) !important;"- Complex fallback:
"color: var(--color, var(--fallback, blue));"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/web-platform/web-core/src/style_transformer/inline_style.rs` around lines 192 - 203, Add unit tests for CSS variable edge cases to the inline_style.rs test suite to mirror existing color tests: create tests that call transform_inline_style_string(source, &TransformerConfig::default()) with inputs covering (1) whitespace variations like " color : var(--color) ;", (2) important modifier "color: var(--color) !important;", and (3) nested fallbacks "color: var(--color, var(--fallback, blue));" and assert the result contains the normalized output (e.g., "color:var(--color)", "color:var(--color)!important", and "color:var(--color,var(--fallback,blue))" respectively) so transform_inline_style_string and TransformerConfig are exercised for these cases.
192-203: Strengthen test assertions to match existing patterns.The new tests use
assert!(result.contains(...)), which only verifies substring presence rather than the complete transformation output. This is weaker than the existing test pattern in this file (e.g., lines 136-139, 147-148) that useassert_eq!to verify exact results.Color transformations add additional CSS properties like
--lynx-text-bg-color,-webkit-background-clip, andbackground-clip. Thecontainsassertion won't catch if these are missing or incorrect when CSS variables are used.🔍 Proposed fix: Use exact output assertions
First, verify the actual transformation output by running these tests with debug printing, then replace with exact assertions:
#[test] fn transform_color_with_css_var() { let source = "color: var(--color)"; let result = transform_inline_style_string(source, &TransformerConfig::default()); - assert!(result.contains("color:var(--color)")); + assert_eq!( + result, + "--lynx-text-bg-color:initial;-webkit-background-clip:initial;background-clip:initial;color:var(--color);" + ); } #[test] fn transform_color_with_css_var_and_fallback() { let source = "color: var(--color, blue)"; let result = transform_inline_style_string(source, &TransformerConfig::default()); - assert!(result.contains("color:var(--color, blue)")); + assert_eq!( + result, + "--lynx-text-bg-color:initial;-webkit-background-clip:initial;background-clip:initial;color:var(--color, blue);" + ); }Note: Adjust the expected output based on actual transformation behavior if different.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/web-platform/web-core/src/style_transformer/inline_style.rs` around lines 192 - 203, Replace the weak substring assertions in tests transform_color_with_css_var and transform_color_with_css_var_and_fallback with exact equality checks: call transform_inline_style_string(source, &TransformerConfig::default()) and assert_eq! the result to the full expected transformed output (including added properties such as --lynx-text-bg-color, -webkit-background-clip, background-clip, and any normalized spacing/punctuation) so the tests validate the complete transformation; update the expected strings to match the actual output produced by transform_inline_style_string and TransformerConfig::default() before committing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/web-platform/web-core/src/style_transformer/inline_style.rs`:
- Around line 192-203: Add unit tests for CSS variable edge cases to the
inline_style.rs test suite to mirror existing color tests: create tests that
call transform_inline_style_string(source, &TransformerConfig::default()) with
inputs covering (1) whitespace variations like " color : var(--color) ;", (2)
important modifier "color: var(--color) !important;", and (3) nested fallbacks
"color: var(--color, var(--fallback, blue));" and assert the result contains the
normalized output (e.g., "color:var(--color)", "color:var(--color)!important",
and "color:var(--color,var(--fallback,blue))" respectively) so
transform_inline_style_string and TransformerConfig are exercised for these
cases.
- Around line 192-203: Replace the weak substring assertions in tests
transform_color_with_css_var and transform_color_with_css_var_and_fallback with
exact equality checks: call transform_inline_style_string(source,
&TransformerConfig::default()) and assert_eq! the result to the full expected
transformed output (including added properties such as --lynx-text-bg-color,
-webkit-background-clip, background-clip, and any normalized
spacing/punctuation) so the tests validate the complete transformation; update
the expected strings to match the actual output produced by
transform_inline_style_string and TransformerConfig::default() before
committing.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 22c5e67e-6103-4d0c-88e0-857dda11430c
📒 Files selected for processing (2)
.changeset/huge-breads-jam.mdpackages/web-platform/web-core/src/style_transformer/inline_style.rs
Merging this PR will improve performance by 26.99%
Performance Changes
Comparing Footnotes
|
Web Explorer#8536 Bundle Size — 728.6KiB (0%).acb2a75(current) vs 78493b4 main#8520(baseline) Bundle metrics
Bundle size by type
|
| Current #8536 |
Baseline #8520 |
|
|---|---|---|
384.4KiB |
384.4KiB |
|
342.04KiB |
342.04KiB |
|
2.16KiB |
2.16KiB |
Bundle analysis report Branch PupilTong:p/hw/chore-add-test-ca... Project dashboard
Generated by RelativeCI Documentation Report issue
React MTF Example#92 Bundle Size — 207.47KiB (0%).acb2a75(current) vs 78493b4 main#76(baseline) Bundle metrics
|
| Current #92 |
Baseline #76 |
|
|---|---|---|
0B |
0B |
|
0B |
0B |
|
0% |
0% |
|
0 |
0 |
|
3 |
3 |
|
174 |
174 |
|
68 |
68 |
|
46.09% |
46.09% |
|
2 |
2 |
|
0 |
0 |
Bundle size by type no changes
| Current #92 |
Baseline #76 |
|
|---|---|---|
111.23KiB |
111.23KiB |
|
96.24KiB |
96.24KiB |
Bundle analysis report Branch PupilTong:p/hw/chore-add-test-ca... Project dashboard
Generated by RelativeCI Documentation Report issue
React Example#6958 Bundle Size — 237.89KiB (0%).acb2a75(current) vs 78493b4 main#6942(baseline) Bundle metrics
|
| Current #6958 |
Baseline #6942 |
|
|---|---|---|
0B |
0B |
|
0B |
0B |
|
0% |
0% |
|
0 |
0 |
|
4 |
4 |
|
180 |
180 |
|
71 |
71 |
|
46.4% |
46.4% |
|
2 |
2 |
|
0 |
0 |
Bundle size by type no changes
| Current #6958 |
Baseline #6942 |
|
|---|---|---|
145.76KiB |
145.76KiB |
|
92.13KiB |
92.13KiB |
Bundle analysis report Branch PupilTong:p/hw/chore-add-test-ca... Project dashboard
Generated by RelativeCI Documentation Report issue
Summary by CodeRabbit
Checklist