-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: adding further fixtures #40
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
d0ec913
c2ee621
c88a6d6
f363fb6
e8077ef
ada6bf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Generate expected outputs for new fixtures | ||
*/ | ||
|
||
import { readFile, writeFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
// Import the transform function | ||
import { buildTimeTransform } from './packages/css-if-polyfill/src/index.js'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const fixturesDir = path.join(__dirname, 'test', 'fixtures'); | ||
|
||
const newFixtures = [ | ||
'empty-token-stream', | ||
'cyclic-substitution', | ||
'complex-supports', | ||
'boolean-negation', | ||
'multiple-mixed-conditions', | ||
'nested-media-features' | ||
]; | ||
|
||
async function generateExpectedOutputs() { | ||
const results = await Promise.all( | ||
newFixtures.map(async (fixture) => { | ||
const inputPath = path.join(fixturesDir, `${fixture}.input.css`); | ||
const expectedPath = path.join( | ||
fixturesDir, | ||
`${fixture}.expected.css` | ||
); | ||
|
||
try { | ||
const input = await readFile(inputPath, 'utf8'); | ||
console.log(`Processing ${fixture}...`); | ||
console.log('Input:', input); | ||
|
||
const result = buildTimeTransform(input); | ||
console.log('Output:', result); | ||
|
||
// Extract the appropriate CSS output (nativeCSS for static transforms, runtimeCSS for dynamic) | ||
const outputCSS = result.nativeCSS || result.runtimeCSS || ''; | ||
|
||
await writeFile(expectedPath, outputCSS); | ||
console.log(`✓ Generated ${fixture}.expected.css\n`); | ||
return { fixture, success: true }; | ||
} catch (error) { | ||
console.error(`✗ Failed to process ${fixture}:`, error.message); | ||
return { fixture, success: false, error }; | ||
} | ||
}) | ||
); | ||
|
||
return results; | ||
} | ||
|
||
await generateExpectedOutputs(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
import { | ||
basicFixtureTests, | ||
loadFixture, | ||
normalizeCSS | ||
normalizeCSS, | ||
runtimeOnlyFixtureTests | ||
} from '../../../test/scripts/fixture-utils.js'; | ||
import { buildTimeTransform, init, processCSSText } from '../src/index.js'; | ||
|
||
|
@@ -30,6 +31,22 @@ | |
}); | ||
} | ||
|
||
// Runtime-only fixtures that cannot be transformed at build time | ||
for (const { fixture, description } of runtimeOnlyFixtureTests) { | ||
test(description, () => { | ||
const { input, expected } = loadFixture(fixture); | ||
const result = buildTimeTransform(input); | ||
|
||
// These fixtures should preserve the if() functions for runtime processing | ||
expect(result.hasRuntimeRules).toBe(true); | ||
expect(normalizeCSS(result.runtimeCSS)).toBe( | ||
Check failure on line 42 in packages/css-if-polyfill/test/integrated.test.js
|
||
normalizeCSS(expected) | ||
); | ||
// NativeCSS should be empty or contain only fallback values | ||
expect(result.nativeCSS).toBe(''); | ||
}); | ||
} | ||
|
||
test('handles mixed media and style conditions', () => { | ||
const { input } = loadFixture('mixed-conditions'); | ||
const result = buildTimeTransform(input); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.test { | ||
color: black; | ||
} | ||
@media (not (print)) { | ||
.test { | ||
color: blue; | ||
} | ||
} | ||
.test { | ||
display: grid; | ||
} | ||
@supports (not display: grid) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot generated this review using guidance from copilot-instructions.md. Positive FeedbackNegative Feedback |
||
.test { | ||
display: block; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.test { | ||
color: if(not media(print): blue; else: black); | ||
display: if(not supports(display: grid): block; else: grid); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.test { | ||
display: block; | ||
} | ||
@supports ((display: grid) and (gap: 1rem)) { | ||
.test { | ||
display: grid; | ||
} | ||
} | ||
.test { | ||
color: blue; | ||
} | ||
@supports (color: hsl(from red h s l)) { | ||
.test { | ||
color: hsl(from red h s l); | ||
} | ||
} | ||
@supports (color: lab(50% 20 -30)) { | ||
.test { | ||
color: lab(50% 20 -30); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.test { | ||
display: if(supports((display: grid) and (gap: 1rem)): grid; else: block); | ||
color: if(supports(color: lab(50% 20 -30)): lab(50% 20 -30); supports(color: hsl(from red h s l)): hsl(from red h s l); else: blue); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.test { | ||
--foo: default; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.test { | ||
--foo: if(style(--foo: bar): baz; else: default); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.test { | ||
background: transparent; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.test { | ||
color: if(media(print): red); | ||
background: if(supports(display: none): transparent); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.responsive { | ||
padding: 15px; | ||
} | ||
@supports (display: grid) { | ||
.responsive { | ||
padding: 25px; | ||
} | ||
} | ||
@media (width >= 768px) { | ||
.responsive { | ||
padding: 30px; | ||
} | ||
} | ||
@media (width >= 1200px) { | ||
.responsive { | ||
padding: 40px; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.responsive { | ||
padding: if( | ||
media(width >= 1200px): 40px; | ||
media(width >= 768px): 30px; | ||
supports(display: grid): 25px; | ||
style(--large-padding): 35px; | ||
else: 15px | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.test { | ||
width: 100%; | ||
} | ||
@media ((orientation: landscape) and (hover: hover)) { | ||
.test { | ||
width: 80%; | ||
} | ||
} | ||
.test { | ||
font-size: 1rem; | ||
} | ||
@media ((min-width: 768px) and (max-width: 1024px) and (prefers-reduced-motion: no-preference)) { | ||
.test { | ||
font-size: 1.2rem; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.test { | ||
width: if(media((orientation: landscape) and (hover: hover)): 80%; else: 100%); | ||
font-size: if(media((min-width: 768px) and (max-width: 1024px) and (prefers-reduced-motion: no-preference)): 1.2rem; else: 1rem); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback logic for selecting output CSS may produce inconsistent results. For runtime-only fixtures, you should explicitly choose
runtimeCSS
, and for build-time fixtures, choosenativeCSS
. The current fallback could mask issues where the wrong transformation type is being used.Copilot uses AI. Check for mistakes.