Skip to content

PROD-4372 #60

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

Open
wants to merge 12 commits into
base: master_based_on_v0.7.8
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
__coverage__
dist
node_modules
44 changes: 37 additions & 7 deletions __tests__/server/__snapshots__/renderer.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

exports[`Base rendering of HTML template 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>


<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"

id=\\"tru-style\\"
rel=\\"stylesheet\\"
/>
Expand All @@ -27,11 +30,13 @@ exports[`Base rendering of HTML template 1`] = `
</script>
<script
src=\\"/test/public/path/polyfills-1511941200000.js\\"

type=\\"application/javascript\\"
></script>

<script
src=\\"/test/public/path/main-1511941200000.js\\"

type=\\"application/javascript\\"
></script>
</body>
Expand All @@ -40,12 +45,15 @@ exports[`Base rendering of HTML template 1`] = `

exports[`Config overriding for injection 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>


<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"

id=\\"tru-style\\"
rel=\\"stylesheet\\"
/>
Expand All @@ -65,11 +73,13 @@ exports[`Config overriding for injection 1`] = `
</script>
<script
src=\\"/test/public/path/polyfills-1511941200000.js\\"

type=\\"application/javascript\\"
></script>

<script
src=\\"/test/public/path/main-1511941200000.js\\"

type=\\"application/javascript\\"
></script>
</body>
Expand All @@ -78,12 +88,15 @@ exports[`Config overriding for injection 1`] = `

exports[`Hemlet integration works 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>
<title data-react-helmet=\\"true\\">Test Page Title</title>
<meta data-react-helmet=\\"true\\" property=\\"description\\" content=\\"Test Page Description\\"/>
<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"

id=\\"tru-style\\"
rel=\\"stylesheet\\"
/>
Expand All @@ -103,11 +116,13 @@ exports[`Hemlet integration works 1`] = `
</script>
<script
src=\\"/test/public/path/polyfills-1511941200000.js\\"

type=\\"application/javascript\\"
></script>

<script
src=\\"/test/public/path/main-1511941200000.js\\"

type=\\"application/javascript\\"
></script>
</body>
Expand All @@ -116,12 +131,15 @@ exports[`Hemlet integration works 1`] = `

exports[`Injection of additional JS scripts 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>


<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"

id=\\"tru-style\\"
rel=\\"stylesheet\\"
/>
Expand All @@ -141,11 +159,13 @@ exports[`Injection of additional JS scripts 1`] = `
</script>
<script
src=\\"/test/public/path/polyfills-1511941200000.js\\"

type=\\"application/javascript\\"
></script>
<script>Dummy JS Sript</script><script>Another Dummy JS Script</script>
<script
src=\\"/test/public/path/main-1511941200000.js\\"

type=\\"application/javascript\\"
></script>
</body>
Expand All @@ -154,16 +174,19 @@ exports[`Injection of additional JS scripts 1`] = `

exports[`Server-side rendering (SSR); injection of CSS chunks & Redux state 1`] = `
"<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>
<title data-react-helmet=\\"true\\"></title>

<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"

id=\\"tru-style\\"
rel=\\"stylesheet\\"
/>
<link data-chunk=\\"test-chunk-a\\" id=\\"tru-style\\" href=\\"/test/public/path/test-chunk-a-1511941200000.css\\" rel=\\"stylesheet\\" /><link data-chunk=\\"test-chunk-b\\" id=\\"tru-style\\" href=\\"/test/public/path/test-chunk-b-1511941200000.css\\" rel=\\"stylesheet\\" />
<link data-chunk=\\"test-chunk-a\\" id=\\"tru-style\\" href=\\"/test/public/path/test-chunk-a-1511941200000.css\\" rel=\\"stylesheet\\" /><link data-chunk=\\"test-chunk-b\\" id=\\"tru-style\\" href=\\"/test/public/path/test-chunk-b-1511941200000.css\\" rel=\\"stylesheet\\" />
<link rel=\\"shortcut icon\\" href=\\"/favicon.ico\\" />
<meta charset=\\"utf-8\\" />
<meta
Expand All @@ -179,11 +202,13 @@ exports[`Server-side rendering (SSR); injection of CSS chunks & Redux state 1`]
</script>
<script
src=\\"/test/public/path/polyfills-1511941200000.js\\"

type=\\"application/javascript\\"
></script>

<script
src=\\"/test/public/path/main-1511941200000.js\\"

type=\\"application/javascript\\"
></script>
</body>
Expand All @@ -193,12 +218,15 @@ exports[`Server-side rendering (SSR); injection of CSS chunks & Redux state 1`]
exports[`Setting of response HTTP status the server-side rendering 1`] = `
"HTTP STATUS: 404
<!DOCTYPE html>
<html>
<html lang=\\"en\\">
<head>
<title data-react-helmet=\\"true\\"></title>

<meta name=\\"theme-color\\" content=\\"#FFFFFF\\"/>
<link rel=\\"manifest\\" href=\\"/test/public/path/manifest.json\\">
<link
href=\\"/test/public/path/main-1511941200000.css\\"

id=\\"tru-style\\"
rel=\\"stylesheet\\"
/>
Expand All @@ -218,11 +246,13 @@ exports[`Setting of response HTTP status the server-side rendering 1`] = `
</script>
<script
src=\\"/test/public/path/polyfills-1511941200000.js\\"

type=\\"application/javascript\\"
></script>

<script
src=\\"/test/public/path/main-1511941200000.js\\"

type=\\"application/javascript\\"
></script>
</body>
Expand Down
49 changes: 49 additions & 0 deletions __tests__/shared/components/Modal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Modal, { BaseModal } from 'components/Modal';
import React from 'react';
import ReactDom from 'react-dom';
import {
findInDomByClass,
renderDom,
simulate,
snapshot,
} from 'utils/jest';

beforeAll(() => {
/* Modal uses ReactJS portals to ensure proper rendering. react-test-renderer,
* used by utils/jest under the hood, does not support it properly, thus this
* simple mock for the createPortal(..) function. */
ReactDom.createPortal = jest.fn(element => (
<div className="MOCK_PORTAL">
{element}
</div>
));
});

test('Snapshot match', () => {
snapshot(<Modal>CONTENT</Modal>);
});

test('onCancel', () => {
const onCancel = jest.fn();
const dom = renderDom((
<BaseModal
onCancel={onCancel}
theme={{ overlay: 'overlay' }}
/>
));
const overlay = findInDomByClass(dom, 'overlay');
simulate.click(overlay);
expect(onCancel).toHaveBeenCalled();
});

test('onWheel', () => {
const dom = renderDom((
<BaseModal
theme={{ container: 'container' }}
/>
));
const container = findInDomByClass(dom, 'container');
const stopPropagation = jest.fn();
simulate.wheel(container, { stopPropagation });
expect(stopPropagation).toHaveBeenCalled();
});
19 changes: 19 additions & 0 deletions __tests__/shared/components/__snapshots__/Modal.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Snapshot match 1`] = `
<div
className="MOCK_PORTAL"
>
<div
className="style__container___1SoeQ"
onWheel={[Function]}
>
CONTENT
</div>
<button
className="style__overlay___X12tn"
onClick={[Function]}
type="button"
/>
</div>
`;
7 changes: 7 additions & 0 deletions config/webpack/app-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ module.exports = function configFactory(ops) {

/* Build timestamp. */
timestamp: now.utc().toISOString(),

...(o.crossOriginLoading ? {
crossOriginLoading: o.crossOriginLoading,
} : {}),
};
fs.writeFileSync(buildInfoUrl, JSON.stringify(buildInfo));
}
Expand Down Expand Up @@ -103,6 +107,9 @@ module.exports = function configFactory(ops) {
filename: `[name]-${now.valueOf()}.js`,
path: path.resolve(__dirname, o.context, 'build'),
publicPath: `${o.publicPath}/`,
...(o.crossOriginLoading ? {
crossOriginLoading: o.crossOriginLoading,
} : {}),
},
plugins: [
new MiniCssExtractPlugin({
Expand Down
32 changes: 32 additions & 0 deletions dist/dev/client/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

var _nodeForge = require('node-forge');

var _nodeForge2 = _interopRequireDefault(_nodeForge);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

window.TRU_BUILD_INFO = BUILD_INFO; /**
* Initialization of client-side environment.
*/

/* global BUILD_INFO, document, window */

window.TRU_FRONT_END = true;

/* Removes data injection script out of the document. */
var block = document.querySelector('script[id="inj"]');
document.getElementsByTagName('body')[0].removeChild(block);

/* Decodes data injected at the server side. */
var key = window.TRU_BUILD_INFO.key;

var data = _nodeForge2.default.util.decode64(window.INJ);
var decipher = _nodeForge2.default.cipher.createDecipher('AES-CBC', key);
decipher.start({ iv: data.slice(0, 32) });
decipher.update(_nodeForge2.default.util.createBuffer(data.slice(32)));
decipher.finish();
data = JSON.parse(_nodeForge2.default.util.decodeUtf8(decipher.output.data));

window.CONFIG = data.CONFIG;
window.ISTATE = data.ISTATE;
Loading