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

fix: revamp bundler to use optimization mode #44

Merged
merged 2 commits into from
Jun 15, 2021
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
9 changes: 9 additions & 0 deletions scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ async function main() {
'node_modules/next/node_modules/jest-worker/build/workers/threadChild.js'
);

fileList.push(
...glob.sync(
'node_modules/next/dist/next-server/server/lib/squoosh/**/*.{js,wasm}',
{
cwd: workspaceRoot,
}
)
);

// Create zip file
await new Promise((resolve, reject) => {
const outputFile = fs.createWriteStream(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
119 changes: 115 additions & 4 deletions test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { URLSearchParams } from 'url';

import { s3PublicDir } from './utils/s3-public-dir';
import { getLocalIpAddressFromHost } from './utils/host-ip-address';
import { acceptAllFixtures } from './constants';
import { acceptAllFixtures, acceptWebpFixtures } from './constants';

const ONE_MINUTE_IN_MS = 60000;
const NODE_RUNTIME = 'nodejs14.x';
Expand Down Expand Up @@ -92,7 +92,12 @@ describe('[e2e]', () => {
);

const response = await lambdaSAM.sendApiGwRequest(
`${route}?${optimizerParams.toString()}`
`${route}?${optimizerParams.toString()}`,
{
headers: {
Accept: '*/*',
},
}
);
const body = await response
.text()
Expand Down Expand Up @@ -159,6 +164,100 @@ describe('[e2e]', () => {
},
ONE_MINUTE_IN_MS
);

test.each(acceptWebpFixtures)(
'External: Accept image/webp,*/*: %s',
async (filePath, fixtureResponse) => {
const publicPath = `http://${s3Endpoint}/${fixtureBucketName}/${filePath}`;
const optimizerParams = new URLSearchParams({
url: publicPath,
w: '2048',
q: '75',
});
const optimizerPrefix = `external_accept_webp_w-${optimizerParams.get(
'w'
)}_q-${optimizerParams.get('q')}_`;
const snapshotFileName = path.join(
__dirname,
'__snapshots__/e2e/',
`${optimizerPrefix}${filePath.replace('/', '_')}.${
fixtureResponse.ext
}`
);

const response = await lambdaSAM.sendApiGwRequest(
`${route}?${optimizerParams.toString()}`,
{
headers: {
Accept: 'image/webp,*/*',
},
}
);
const body = await response
.text()
.then((text) => Buffer.from(text, 'base64'));

expect(response.status).toBe(200);
expect(body).toMatchFile(snapshotFileName);
expect(response.headers.get('Content-Type')).toBe(
fixtureResponse['content-type']
);
expect(response.headers.get('Cache-Control')).toBe(cacheControlHeader);

// Header settings needed for CloudFront compression
expect(response.headers.has('Content-Length')).toBeTruthy();
expect(response.headers.has('Content-Encoding')).toBeFalsy();
},
ONE_MINUTE_IN_MS
);

test.each(acceptWebpFixtures)(
'Internal: Accept image/webp,*/*: %s',
async (filePath, fixtureResponse) => {
const publicPath = `/${fixtureBucketName}/${filePath}`;
const optimizerParams = new URLSearchParams({
url: publicPath,
w: '2048',
q: '75',
});
const optimizerPrefix = `internal_accept_webp_w-${optimizerParams.get(
'w'
)}_q-${optimizerParams.get('q')}_`;
const snapshotFileName = path.join(
__dirname,
'__snapshots__/e2e/',
`${optimizerPrefix}${filePath.replace('/', '_')}.${
fixtureResponse.ext
}`
);

const response = await lambdaSAM.sendApiGwRequest(
`${route}?${optimizerParams.toString()}`,
{
headers: {
Accept: 'image/webp,*/*',
Referer: `http://${s3Endpoint}/`,
},
}
);

const body = await response
.text()
.then((text) => Buffer.from(text, 'base64'));

expect(response.status).toBe(200);
expect(body).toMatchFile(snapshotFileName);
expect(response.headers.get('Content-Type')).toBe(
fixtureResponse['content-type']
);
expect(response.headers.get('Cache-Control')).toBe(cacheControlHeader);

// Header settings needed for CloudFront compression
expect(response.headers.has('Content-Length')).toBeTruthy();
expect(response.headers.has('Content-Encoding')).toBeFalsy();
},
ONE_MINUTE_IN_MS
);
});

describe('With S3', () => {
Expand Down Expand Up @@ -216,7 +315,13 @@ describe('[e2e]', () => {
});

const response = await lambdaSAM.sendApiGwRequest(
`${route}?${optimizerParams.toString()}`
`${route}?${optimizerParams.toString()}`,
{
headers: {
Accept: '*/*',
Referer: `http://${s3Endpoint}/`,
},
}
);

const body = await response
Expand Down Expand Up @@ -286,7 +391,13 @@ describe('[e2e]', () => {
);

const response = await lambdaSAM.sendApiGwRequest(
`${route}?${optimizerParams.toString()}`
`${route}?${optimizerParams.toString()}`,
{
headers: {
Accept: '*/*',
Referer: `http://${s3Endpoint}/`,
},
}
);
const text = await response.text();
const body = Buffer.from(text, 'base64');
Expand Down