Skip to content

Commit

Permalink
Add test verifying bulma was minified
Browse files Browse the repository at this point in the history
  • Loading branch information
mreishus committed Jan 28, 2025
1 parent 2da46a1 commit 85c6752
Show file tree
Hide file tree
Showing 2 changed files with 21,579 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/file-css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,34 @@ const fs = require( 'fs' ).promises;
describe( 'file (css): Minify CSS files', () => {
let request = supertest( `http://localhost:${ getSharedServerPort() }` );

test( 'GET `/file` -- CSS minify bootstrap.css', async () => {
test( 'GET `/file` -- CSS minify bulma.css', async () => {
const target_url = 'tests/files/bulma.css';
const originalContent = await fs.readFile( target_url, 'utf8' );

const startTime = process.hrtime();
const resp = await request
.get( `/file?path=${ target_url }` )
.expect( 200 )
.expect( 'Content-Type', /text\/css/ )
.expect( 'x-minify', 't' );
const [ seconds, nanoseconds ] = process.hrtime( startTime );
const milliseconds = seconds * 1000 + nanoseconds / 1000000;

const minifiedText = resp.text;

// Verify it was actually minified
const originalSize = originalContent.length;
const minifiedSize = minifiedText.length;
expect( minifiedSize ).toBeLessThan( originalSize * 0.91 );
console.info(
`Minimized CSS ${ target_url } to ${ ( ( minifiedSize / originalSize ) * 100 ).toFixed(
2,
) }% of original size in ${ milliseconds.toFixed( 2 ) }ms`,
);
} );

// Skipped - bootstrap.css does not minify because it has escape sequences
test.skip( 'GET `/file` -- CSS minify bootstrap.css', async () => {
const target_url = 'tests/files/bootstrap.css';
const originalContent = await fs.readFile( target_url, 'utf8' );

Expand Down
Loading

0 comments on commit 85c6752

Please sign in to comment.