Skip to content

Commit

Permalink
test: add TF: Fetch twice external image to git the filesystem cache
Browse files Browse the repository at this point in the history
  • Loading branch information
b6pzeusbc54tvhw5jgpyw8pwz2x6gs committed Mar 11, 2021
1 parent 92205f9 commit ae21226
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('[e2e]', () => {
fixtureBucketName = upload.bucketName;
});

describe('Without S3', () => {
describe.skip('Without S3', () => {
let lambdaSAM: LambdaSAM;

beforeAll(async () => {
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('[e2e]', () => {
);
});

describe('With S3', () => {
describe.skip('With S3', () => {
let lambdaSAM: LambdaSAM;

beforeAll(async () => {
Expand Down Expand Up @@ -225,5 +225,70 @@ describe('[e2e]', () => {
});
});

describe('From filesystem cache', () => {
let lambdaSAM: LambdaSAM;
beforeAll(async () => {
// Generate SAM for the worker lambda
lambdaSAM = await generateSAM({
lambdas: {
imageOptimizer: {
filename: 'dist.zip',
handler: 'handler.handler',
runtime: NODE_RUNTIME,
memorySize: 1024,
route,
method: 'get',
environment: {
TF_NEXTIMAGE_DOMAINS: JSON.stringify([hostIpAddress]),
},
},
},
cwd: pathToWorker,
onData: (data) => console.log(data.toString()),
onError: (data) => console.log(data.toString()),
});

await lambdaSAM.start();
});

afterAll(async () => {
await lambdaSAM.stop();
});
test("Fetch twice external image to git the filesystem cache", async () => {
const [filePath, fixtureResponse] = acceptAllFixtures[0]
const publicPath = `http://${s3Endpoint}/${fixtureBucketName}/${filePath}`;
const [w,q] = ['2048','75']
const optimizerParams = new URLSearchParams({ url: publicPath, w, q })
const optimizerPrefix = `external_accept_all_w-${w}_q-${q}_`;
const snapshotFileName = path.join(
__dirname,
'__snapshots__/e2e/',
`${optimizerPrefix}${filePath.replace('/', '_')}.${fixtureResponse.ext}`
);

const fetchExternalImage = async () => {
const response = await lambdaSAM.sendApiGwRequest(
`${route}?${optimizerParams.toString()}`
);
const text = await response.text();
const body = 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();
}

await fetchExternalImage()
await fetchExternalImage()
})
})

test.todo('Run test against domain that is not on the list');
});

0 comments on commit ae21226

Please sign in to comment.