Skip to content

Commit

Permalink
CSS Minification: Add test covering nesting :where(& > .bar) (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
mreishus authored Jan 30, 2025
1 parent 7019ab6 commit c75e0e2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
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;
}
}

0 comments on commit c75e0e2

Please sign in to comment.