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

Commit

Permalink
fix: fastify tests
Browse files Browse the repository at this point in the history
fix: fastify tests
  • Loading branch information
giulianok authored Dec 1, 2022
1 parent 3762216 commit 843108d
Show file tree
Hide file tree
Showing 22 changed files with 7,562 additions and 7,805 deletions.
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
60 changes: 32 additions & 28 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',
],
'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,6 +1375,7 @@ describe('Tests that require Docker setup', () => {
headers: {
origin: 'test.example.com',
},
body: {},
});

expect(response.headers.raw()).toEqual({
Expand Down Expand Up @@ -1421,6 +1428,7 @@ describe('Tests that require Docker setup', () => {
headers: {
origin: 'test.example.com',
},
body: {},
});

expect(response.headers.raw()).toEqual({
Expand All @@ -1439,9 +1447,6 @@ describe('Tests that require Docker setup', () => {
date: [
expect.any(String),
],
etag: [
expect.any(String),
],
'one-app-version': [
expect.any(String),
],
Expand All @@ -1452,7 +1457,7 @@ describe('Tests that require Docker setup', () => {
'max-age=15552000; includeSubDomains',
],
vary: [
'Accept-Encoding',
'accept-encoding',
],
'x-content-type-options': [
'nosniff',
Expand Down Expand Up @@ -1485,8 +1490,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,9 +1505,6 @@ describe('Tests that require Docker setup', () => {
date: [
expect.any(String),
],
etag: [
expect.any(String),
],
'one-app-version': [
expect.any(String),
],
Expand Down Expand Up @@ -1528,8 +1533,6 @@ describe('Tests that require Docker setup', () => {
'0',
],
});
expect(response.status).toBe(204);
expect(await response.text()).toBe('');
});

test('Request: /foo/invalid.json', async () => {
Expand All @@ -1542,6 +1545,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 +1565,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 @@ -1571,13 +1575,13 @@ describe('Tests that require Docker setup', () => {
'no-cache',
],
'referrer-policy': [
'no-referrer',
'same-origin',
],
'strict-transport-security': [
'max-age=15552000; includeSubDomains',
],
vary: [
'Accept-Encoding',
'accept-encoding',
],
'x-content-type-options': [
'nosniff',
Expand All @@ -1589,13 +1593,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',
],
});
});
Expand Down Expand Up @@ -1655,9 +1659,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 +1673,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 +1705,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 +1735,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
5 changes: 0 additions & 5 deletions __tests__/server/middleware/__snapshots__/csp.spec.js.snap

This file was deleted.

15 changes: 0 additions & 15 deletions __tests__/server/middleware/__snapshots__/sendHtml.spec.js.snap

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions __tests__/server/plugins/__snapshots__/csp.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`csp adds ip and localhost to csp in development 1`] = `"default-src 'none'; script-src 'nonce-00000000-0000-0000-0000-000000000000' 0.0.0.0:* localhost:* ws://localhost:* 'self'; connect-src 0.0.0.0:* localhost:* ws://localhost:* 'self';"`;

exports[`csp updateCSP updates cspCache with given csp 1`] = `"default-src 'self';"`;
18 changes: 9 additions & 9 deletions __tests__/server/plugins/conditionallyAllowCors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ describe('conditionallyAllowCors', () => {

const callback = jest.fn();
const fastify = {
register: jest.fn((_plugin, handler) => {
handler()(request, callback);
register: jest.fn((_plugin, { delegator }) => {
delegator(request, callback);
}),
};

await conditionallyAllowCors(fastify);

expect(fastify.register).toHaveBeenCalledTimes(1);
expect(fastify.register).toHaveBeenCalledWith(fastifyCors, expect.any(Function));
expect(fastify.register).toHaveBeenCalledWith(fastifyCors, { hook: 'preHandler', delegator: expect.any(Function) });
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(null, { origin: [/\.example.com$/] });
});
Expand All @@ -67,8 +67,8 @@ describe('conditionallyAllowCors', () => {

const callback = jest.fn();
const fastify = {
register: jest.fn((_plugin, handler) => {
handler()(request, callback);
register: jest.fn((_plugin, { delegator }) => {
delegator(request, callback);
}),
};

Expand All @@ -83,8 +83,8 @@ describe('conditionallyAllowCors', () => {

const callback = jest.fn();
const fastify = {
register: jest.fn((_plugin, handler) => {
handler()(request, callback);
register: jest.fn((_plugin, { delegator }) => {
delegator(request, callback);
}),
};

Expand All @@ -98,8 +98,8 @@ describe('conditionallyAllowCors', () => {

const callback = jest.fn();
const fastify = {
register: jest.fn((_plugin, handler) => {
handler()(request, callback);
register: jest.fn((_plugin, { delegator }) => {
delegator(request, callback);
}),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`reactHtml renderModuleScripts adds cache busting clientCacheRevision from module map to each module script src if NODE_ENV is production 1`] = `"<script src="https://example.com/cdn/test-root/2.2.2/test-root.browser.js?clientCacheRevision=123" crossorigin="anonymous" integrity="nggdfhr34"></script>"`;

exports[`reactHtml renderModuleScripts does not add cache busting clientCacheRevision from module map to each module script src if NODE_ENV is development 1`] = `"<script src="https://example.com/cdn/test-root/2.2.2/test-root.browser.js" crossorigin="anonymous" ></script>"`;

exports[`reactHtml renderModuleScripts does not add cache busting clientCacheRevision if not present 1`] = `"<script src="https://example.com/cdn/test-root/2.2.2/test-root.browser.js" crossorigin="anonymous" integrity="nggdfhr34"></script>"`;

exports[`reactHtml renderModuleScripts send a rendered page keeping correctly ordered modules 1`] = `"<script src="https://example.com/cdn/test-root/2.2.2/test-root.browser.js" crossorigin="anonymous" integrity="dhhfsdfwer"></script><script src="https://example.com/cdn/a/2.2.2/a.browser.js" crossorigin="anonymous" integrity="fhgnt543"></script><script src="https://example.com/cdn/b/2.2.2/b.browser.js" crossorigin="anonymous" integrity="yhrtrhw3"></script><script src="https://example.com/cdn/c/2.2.2/c.browser.js" crossorigin="anonymous" integrity="323egdsbf"></script>"`;

exports[`reactHtml renderModuleScripts send a rendered page with correctly ordered modules 1`] = `"<script src="https://example.com/cdn/test-root/2.2.2/test-root.browser.js" crossorigin="anonymous" integrity="dhhfsdfwer"></script><script src="https://example.com/cdn/a/2.2.2/a.browser.js" crossorigin="anonymous" integrity="fhgnt543"></script><script src="https://example.com/cdn/b/2.2.2/b.browser.js" crossorigin="anonymous" integrity="yhrtrhw3"></script><script src="https://example.com/cdn/c/2.2.2/c.browser.js" crossorigin="anonymous" integrity="323egdsbf"></script>"`;

exports[`reactHtml renderModuleScripts send a rendered page with module script tags with integrity attribute if NODE_ENV is production 1`] = `"<script src="https://example.com/cdn/test-root/2.2.2/test-root.browser.js?clientCacheRevision=123" crossorigin="anonymous" integrity="nggdfhr34"></script>"`;

exports[`reactHtml renderModuleScripts sends a rendered page with cross origin scripts 1`] = `"<script src="https://example.com/cdn/test-root/2.2.2/test-root.browser.js" crossorigin="anonymous" ></script>"`;
4 changes: 2 additions & 2 deletions __tests__/server/utils/loadModules.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getModule } from 'holocron';
import { updateModuleRegistry } from 'holocron/server';
import { CONFIGURATION_KEY } from '../../../src/server/utils/onModuleLoad';
import loadModules from '../../../src/server/utils/loadModules';
import { updateCSP } from '../../../src/server/middleware/csp';
import { updateCSP } from '../../../src/server/plugins/csp';
import { setClientModuleMapCache, getClientModuleMapCache } from '../../../src/server/utils/clientModuleMapCache';
import addBaseUrlToModuleMap from '../../../src/server/utils/addBaseUrlToModuleMap';

Expand All @@ -38,7 +38,7 @@ jest.mock('../../../src/server/utils/stateConfig', () => ({
})),
}));

jest.mock('../../../src/server/middleware/csp', () => ({
jest.mock('../../../src/server/plugins/csp', () => ({
updateCSP: jest.fn(),
}));

Expand Down
Loading

0 comments on commit 843108d

Please sign in to comment.