Skip to content
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

CSS Minification: Add test covering nesting :where(& > .bar) #52

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/file-css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,31 @@ describe( 'file (css): Minify CSS files', () => {
) }% of original size`,
);
} );

test( 'GET `/file` -- CSS minify supports nesting :where(& > .bar)', async () => {
// This is from https://github.com/evanw/esbuild/issues/4005
const target_url = 'tests/files/nesting-test.css';
const originalContent = await fs.readFile( target_url, 'utf8' );

const resp = await request
.get( `/file?path=${ target_url }` )
.expect( 200 )
.expect( 'Content-Type', /text\/css/ )
.expect( 'x-minify', 't' );

const minifiedText = resp.text;
// Verify it was actually minified
const originalSize = originalContent.length;
const minifiedSize = minifiedText.length;
expect( minifiedSize ).toBeLessThan( originalSize * 0.85 );

// Verify the "purple" rule was not removed
expect( minifiedText ).toContain( 'purple' );

console.info(
`Minimized CSS ${ target_url } to ${ ( ( minifiedSize / originalSize ) * 100 ).toFixed(
2,
) }% of original size`,
);
} );
} );
10 changes: 10 additions & 0 deletions tests/files/nesting-test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* From https://github.com/evanw/esbuild/issues/4005 */
.foo {
color: red;
}

.foo {
:where(& > .bar) {
color: purple;
}
}
Loading