Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Feat: ExpressJS to Fastify migration #878

Merged
merged 27 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
86e2889
feat: migrated express to fastify
giulianok Dec 5, 2022
2f37b20
chore: merge conflicts
giulianok Dec 6, 2022
37bd3b2
Merge branch 'main' into feature/express-fastify-migration
10xLaCroixDrinker Dec 6, 2022
32ac754
feat(fastifycdn): migrate holocron cdn to fastify
dogpatch626 Dec 7, 2022
1346c92
feat(fastifycdn): remove comment and change license year
dogpatch626 Dec 9, 2022
51ec0bf
feat(fastifycdn): fix remote module issue
dogpatch626 Jan 5, 2023
0fb7a46
feat(fastifycdn): replace got with node fetch
dogpatch626 Jan 6, 2023
74f7b0d
feat(fastifycdn): fix lint
dogpatch626 Jan 6, 2023
51aebe9
feat(fastifycdn): remove got
dogpatch626 Jan 10, 2023
ca9308f
feat(fastifycdn): throw error if in prod
dogpatch626 Jan 12, 2023
9856387
feat(fastifycdn): fix lint
dogpatch626 Jan 12, 2023
9a8c17e
Merge pull request #882 from americanexpress/feat/dev-cdn-fastify
dogpatch626 Jan 17, 2023
0a8a861
fix: matching headers with existing express output
giulianok Jan 19, 2023
0aeae57
chore: added options route when post is enabled
giulianok Jan 24, 2023
23ae146
chore: merge conflicts
giulianok Jan 24, 2023
842b650
chore: reverted options route
giulianok Jan 24, 2023
c228f78
Merge branch 'main' of https://github.com/americanexpress/one-app int…
giulianok Jan 24, 2023
0138b18
fix: integration tests
giulianok Jan 24, 2023
b3b2671
chore: reverted int test change
giulianok Jan 24, 2023
0dcc673
chore: removed unused dependencies
giulianok Jan 25, 2023
4a820b0
chore: minor eslint changes
giulianok Jan 25, 2023
f352387
fix: no-referrer header
giulianok Jan 25, 2023
54d6bca
fix: integration tests
giulianok Jan 25, 2023
56c5ca7
chore: removed middlewares and unused packages
giulianok Jan 26, 2023
3083840
chore: changes test to it
giulianok Jan 26, 2023
1552c23
chore: merge conflicts
giulianok Jan 30, 2023
a97aa5d
chore: updated package lock json
giulianok Jan 30, 2023
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
31 changes: 31 additions & 0 deletions __mocks__/node-fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2022 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express
* or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

const fetch = jest.createMockFromModule('node-fetch');
fetch.mockReturnJsonOnce = (obj) => {
if (obj instanceof Error) {
return fetch.mockImplementationOnce(() => Promise.reject(obj));
}

return fetch.mockImplementationOnce(() => Promise.resolve({ body: JSON.stringify(obj) }));
};

fetch.mockReturnFileOnce = (body) => {
if (body instanceof Error) {
return fetch.mockImplementationOnce(() => Promise.reject(body));
}

return fetch.mockImplementationOnce(() => Promise.resolve({ body, statusCode: 200 }));
};
module.exports = fetch;
9 changes: 4 additions & 5 deletions __tests__/client/initClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

import { fromJS } from 'immutable';

jest.mock('@americanexpress/one-app-router', () => {
const reactRouter = jest.requireActual('@americanexpress/one-app-router');
jest.spyOn(reactRouter, 'matchPromise');
return reactRouter;
});
jest.mock('@americanexpress/one-app-router', () => ({
...jest.requireActual('@americanexpress/one-app-router'),
matchPromise: jest.fn(),
}));

jest.mock('../../src/client/prerender', () => {
const prerender = jest.requireActual('../../src/client/prerender');
Expand Down
2 changes: 2 additions & 0 deletions __tests__/integration/__snapshots__/one-app.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ exports[`Tests that require Docker setup one-app successfully started metrics ha
"nodejs_active_handles_total",
"nodejs_active_requests",
"nodejs_active_requests_total",
"nodejs_active_resources",
"nodejs_active_resources_total",
"nodejs_eventloop_lag_max_seconds",
"nodejs_eventloop_lag_mean_seconds",
"nodejs_eventloop_lag_min_seconds",
Expand Down
74 changes: 40 additions & 34 deletions __tests__/integration/one-app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ describe('Tests that require Docker setup', () => {
headers: {
origin: 'test.example.com',
},
body: JSON.stringify({}),
});
const rawHeaders = response.headers.raw();
expect(response.status).toBe(200);
expect(rawHeaders).not.toHaveProperty('access-control-allow-origin');
expect(rawHeaders).not.toHaveProperty('access-control-expose-headers');
expect(rawHeaders).not.toHaveProperty('access-control-allow-credentials');
});
Expand Down Expand Up @@ -210,9 +210,9 @@ describe('Tests that require Docker setup', () => {
headers: {
origin: 'test.example.com',
},
body: {
body: JSON.stringify({
message: 'Hello!',
},
}),
}
);
const rawHeaders = response.headers.raw();
Expand Down Expand Up @@ -1335,9 +1335,6 @@ describe('Tests that require Docker setup', () => {
date: [
expect.any(String),
],
etag: [
expect.any(String),
],
'one-app-version': [
expect.any(String),
],
Expand All @@ -1348,14 +1345,23 @@ describe('Tests that require Docker setup', () => {
'max-age=15552000; includeSubDomains',
],
vary: [
'Accept-Encoding',
'Accept-Encoding, accept-encoding',
],
'x-content-type-options': [
'nosniff',
],
'x-dns-prefetch-control': [
'off',
],
'x-download-options': [
'noopen',
],
'x-frame-options': [
'DENY',
],
'x-permitted-cross-domain-policies': [
'none',
],
'x-xss-protection': [
'1; mode=block',
],
Expand All @@ -1369,9 +1375,11 @@ describe('Tests that require Docker setup', () => {
headers: {
origin: 'test.example.com',
},
body: {},
});

expect(response.headers.raw()).toEqual({
vary: ['Accept-Encoding'],
connection: [
'close',
],
Expand All @@ -1385,7 +1393,7 @@ describe('Tests that require Docker setup', () => {
expect.any(String),
],
'referrer-policy': [
'no-referrer',
'same-origin',
],
'strict-transport-security': [
'max-age=15552000; includeSubDomains',
Expand All @@ -1400,13 +1408,13 @@ describe('Tests that require Docker setup', () => {
'noopen',
],
'x-frame-options': [
'SAMEORIGIN',
'DENY',
],
'x-permitted-cross-domain-policies': [
'none',
],
'x-xss-protection': [
'0',
'1; mode=block',
],
});
expect(response.status).toBe(204);
Expand All @@ -1421,6 +1429,7 @@ describe('Tests that require Docker setup', () => {
headers: {
origin: 'test.example.com',
},
body: {},
});

expect(response.headers.raw()).toEqual({
Expand All @@ -1439,20 +1448,17 @@ describe('Tests that require Docker setup', () => {
date: [
expect.any(String),
],
etag: [
expect.any(String),
],
'one-app-version': [
expect.any(String),
],
'referrer-policy': [
'no-referrer',
'same-origin',
],
'strict-transport-security': [
'max-age=15552000; includeSubDomains',
],
vary: [
'Accept-Encoding',
'Accept-Encoding, accept-encoding',
],
'x-content-type-options': [
'nosniff',
Expand All @@ -1464,13 +1470,13 @@ describe('Tests that require Docker setup', () => {
'noopen',
],
'x-frame-options': [
'SAMEORIGIN',
'DENY',
],
'x-permitted-cross-domain-policies': [
'none',
],
'x-xss-protection': [
'0',
'1; mode=block',
],
});
expect(response.status).toBe(415);
Expand All @@ -1485,8 +1491,11 @@ describe('Tests that require Docker setup', () => {
origin: 'test.example.com',
'content-type': 'application/json',
},
body: JSON.stringify({}),
});

// expect(response.status).toBe(204);
expect(await response.text()).toBe('');
expect(response.headers.raw()).toEqual({
connection: [
'close',
Expand All @@ -1497,18 +1506,16 @@ describe('Tests that require Docker setup', () => {
date: [
expect.any(String),
],
etag: [
expect.any(String),
],
'one-app-version': [
expect.any(String),
],
'referrer-policy': [
'no-referrer',
'same-origin',
],
'strict-transport-security': [
'max-age=15552000; includeSubDomains',
],
vary: ['Accept-Encoding'],
'x-content-type-options': [
'nosniff',
],
Expand All @@ -1519,17 +1526,15 @@ describe('Tests that require Docker setup', () => {
'noopen',
],
'x-frame-options': [
'SAMEORIGIN',
'DENY',
],
'x-permitted-cross-domain-policies': [
'none',
],
'x-xss-protection': [
'0',
'1; mode=block',
],
});
expect(response.status).toBe(204);
expect(await response.text()).toBe('');
});

test('Request: /foo/invalid.json', async () => {
Expand All @@ -1542,6 +1547,7 @@ describe('Tests that require Docker setup', () => {
});

expect(response.status).toBe(404);
expect(await response.text()).toBe('Not found');
expect(response.headers.raw()).toEqual({
'cache-control': [
'no-store',
Expand All @@ -1561,8 +1567,8 @@ describe('Tests that require Docker setup', () => {
date: [
expect.any(String),
],
etag: [
expect.any(String),
'expect-ct': [
'max-age=0',
],
'one-app-version': [
expect.any(String),
Expand All @@ -1577,7 +1583,7 @@ describe('Tests that require Docker setup', () => {
'max-age=15552000; includeSubDomains',
],
vary: [
'Accept-Encoding',
'Accept-Encoding, accept-encoding',
],
'x-content-type-options': [
'nosniff',
Expand Down Expand Up @@ -1655,9 +1661,9 @@ describe('Tests that can run against either local Docker setup or remote One App
headers: {
origin: 'test.example.com',
},
body: {
body: JSON.stringify({
message: 'Hello!',
},
}),
}
);
expect(response.status).toBe(200);
Expand All @@ -1669,11 +1675,10 @@ describe('Tests that can run against either local Docker setup or remote One App
const response = await fetch(`${appInstanceUrls.fetchUrl}/success`, {
...defaultFetchOpts,
method: 'POST',
body: {},
});
const pageHtml = await response.text();
expect(pageHtml.includes('Hello! One App is successfully rendering its Modules!')).toBe(
true
);
expect(pageHtml).toContain('Hello! One App is successfully rendering its Modules!');
});

test('app passes vitruvius data to modules', async () => {
Expand Down Expand Up @@ -1702,7 +1707,7 @@ describe('Tests that can run against either local Docker setup or remote One App
method: 'GET',
originalUrl: '/vitruvius',
params: {
0: '/vitruvius',
'*': 'vitruvius',
},
protocol: expect.stringMatching(/^https?$/),
query: {},
Expand Down Expand Up @@ -1732,6 +1737,7 @@ describe('Tests that can run against either local Docker setup or remote One App
sendingData: 'in POSTs',
});
});

test('app passes urlencoded POST data to modules via vitruvius', async () => {
const response = await fetch(`${appInstanceUrls.fetchUrl}/vitruvius`, {
...defaultFetchOpts,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/server/config/env/runTime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ describe('runTime', () => {
const referrerPolicyOverride = getEnvVarConfig('ONE_REFERRER_POLICY_OVERRIDE');

it('default value', () => {
expect(referrerPolicyOverride.defaultValue()).toEqual('same-origin');
expect(referrerPolicyOverride.defaultValue()).toEqual('');
});

it('validates approved policy', () => {
Expand Down
Loading