Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 73750a9

Browse files
committed
Merge branch 'master' of github.com:opencomponents/oc-template-react into react
2 parents 3c87687 + 0e3a409 commit 73750a9

File tree

10 files changed

+86
-49
lines changed

10 files changed

+86
-49
lines changed

acceptance-setup/__tests__/__snapshots__/acceptance.js.snap

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

acceptance-setup/__tests__/acceptance.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ afterAll(done => {
7777
test("Registry should correctly serve rendered and unrendered components", done => {
7878
const rendered = r(registryUrl + `react-app/?name=SuperMario`)
7979
.then(function(body) {
80-
const bodyVersionless = body.replace(semverRegex, "6.6.6");
80+
const bodyVersionless = body
81+
.replace(semverRegex, "6.6.6")
82+
.replace(/data-hash=\\\".*?\\\"/, "")
83+
.replace(
84+
/\[\\\"oc\\\",.*?\\\"reactComponents\\\",.*?\\\".*?\\\"\]/,
85+
'["oc", "reactComponents", "dummyContent"]'
86+
);
8187
expect(bodyVersionless).toMatchSnapshot();
8288
})
8389
.catch(err => expect(err).toBeNull());
@@ -89,7 +95,9 @@ test("Registry should correctly serve rendered and unrendered components", done
8995
}
9096
})
9197
.then(function(body) {
92-
const bodyVersionless = body.replace(semverRegex, "6.6.6");
98+
const bodyVersionless = body
99+
.replace(semverRegex, "6.6.6")
100+
.replace(/\"key\"\:\".*?\"/g, "");
93101
expect(bodyVersionless).toMatchSnapshot();
94102
})
95103
.catch(err => expect(err).toBeNull());
@@ -102,7 +110,13 @@ test("Registry should correctly serve rendered and unrendered components", done
102110
test("server-side-side rendering", done => {
103111
JSDOM.fromURL(serverUrl + `?name=SuperMario`, {})
104112
.then(dom => {
105-
const domVersionless = dom.serialize().replace(semverRegex, "6.6.6");
113+
const domVersionless = dom
114+
.serialize()
115+
.replace(semverRegex, "6.6.6")
116+
.replace(
117+
/\[\"oc\",.*?\"reactComponents\",.*?\".*?\"\]/,
118+
'["oc", "reactComponents", "dummyContent"]'
119+
);
106120
expect(domVersionless).toMatchSnapshot();
107121
done();
108122
})

acceptance-setup/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = (port, cb) => {
4545
<title>A page</title>
4646
</head>
4747
<body>
48-
${renderedComponents[1]}
48+
${renderedComponents[1].replace(/data-hash=\".*?\"/, "")}
4949
${renderedComponents[0]}
5050
</body>
5151
</html>

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"devDependencies": {
33
"codecov": "3.0.2",
44
"husky": "^0.14.3",
5-
"jest": "23.0.0",
5+
"jest": "23.1.0",
66
"lerna": "^2.4.0",
7-
"lint-staged": "7.1.2",
8-
"oc": "0.44.7",
7+
"lint-staged": "7.1.3",
8+
"oc": "0.44.9",
99
"prettier-eslint-cli": "^4.2.0"
1010
},
1111
"scripts": {

packages/oc-template-react-compiler/__tests__/__snapshots__/compile.js.snap

Lines changed: 32 additions & 32 deletions
Large diffs are not rendered by default.

packages/oc-template-react-compiler/__tests__/__snapshots__/compileServer.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`Should correctly compile the server 1`] = `
44
Object {
5-
"hashKey": "a75995ea264d18328ead9fa7570d5500850393cc",
5+
"hashKey": "dummyData",
66
"src": "server.js",
77
"type": "node.js",
88
}

packages/oc-template-react-compiler/__tests__/__snapshots__/compileView.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
exports[`valid component 1`] = `
44
Object {
55
"bundle": Object {
6-
"hashKey": "c246e2c2247889e20b39dbdf1f1bce65b2aebf24",
6+
"hashKey": "dummyData",
77
},
88
"template": Object {
9-
"hashKey": "e97759d7e09bdc330b6cea4c708417e00d1dbb12",
9+
"hashKey": "dummyData",
1010
"src": "template.js",
1111
"type": "oc-template-react",
1212
},
1313
}
1414
`;
1515

16-
exports[`valid component 2`] = `"var oc=oc||{};oc.components=oc.components||{};oc.components['e97759d7e09bdc330b6cea4c708417e00d1dbb12']=function(model){ var modelHTML = model.__html ? model.__html : ''; var staticPath = model.reactComponent.props._staticPath; var props = JSON.stringify(model.reactComponent.props); return '<div id=\\"oc-reactRoot-react-component\\" class=\\"oc-reactRoot-react-component\\">' + modelHTML + '</div>' + '' + '<script>' + 'window.oc = window.oc || {};' + 'oc.cmd = oc.cmd || [];' + 'oc.cmd.push(function(oc){' + '' + 'oc.requireSeries([{\\"global\\":\\"PropTypes\\",\\"url\\":\\"https://unpkg.com/[email protected]/prop-types.min.js\\",\\"name\\":\\"prop-types\\"},{\\"global\\":\\"React\\",\\"url\\":\\"https://unpkg.com/[email protected]/umd/react.production.min.js\\",\\"name\\":\\"react\\"},{\\"global\\":\\"ReactDOM\\",\\"url\\":\\"https://unpkg.com/[email protected]/umd/react-dom.production.min.js\\",\\"name\\":\\"react-dom\\"}], function(){' + 'oc.require(' + '[\\"oc\\", \\"reactComponents\\", \\"c246e2c2247889e20b39dbdf1f1bce65b2aebf24\\"],' + '\\"' + staticPath + 'react-component.js\\",' + 'function(ReactComponent){' + 'var targetNode = document.getElementById(\\"oc-reactRoot-react-component\\");' + 'targetNode.setAttribute(\\"id\\",\\"\\");' + 'ReactDOM.render(React.createElement(ReactComponent,' + props + '),targetNode);' + '}' + ');' + '});' + '});' + '</script>' }"`;
16+
exports[`valid component 2`] = `"var oc=oc||{};oc.components=oc.components||{};oc.components['dummyData']=function(model){ var modelHTML = model.__html ? model.__html : ''; var staticPath = model.reactComponent.props._staticPath; var props = JSON.stringify(model.reactComponent.props); return '<div id=\\"oc-reactRoot-react-component\\" class=\\"oc-reactRoot-react-component\\">' + modelHTML + '</div>' + '' + '<script>' + 'window.oc = window.oc || {};' + 'oc.cmd = oc.cmd || [];' + 'oc.cmd.push(function(oc){' + '' + 'oc.requireSeries([{\\"global\\":\\"PropTypes\\",\\"url\\":\\"https://unpkg.com/[email protected]/prop-types.min.js\\",\\"name\\":\\"prop-types\\"},{\\"global\\":\\"React\\",\\"url\\":\\"https://unpkg.com/[email protected]/umd/react.production.min.js\\",\\"name\\":\\"react\\"},{\\"global\\":\\"ReactDOM\\",\\"url\\":\\"https://unpkg.com/[email protected]/umd/react-dom.production.min.js\\",\\"name\\":\\"react-dom\\"}], function(){' + 'oc.require(' + '[\\"oc\\", \\"reactComponents\\", \\"dummyContent\\"],' + '\\"' + staticPath + 'react-component.js\\",' + 'function(ReactComponent){' + 'var targetNode = document.getElementById(\\"oc-reactRoot-react-component\\");' + 'targetNode.setAttribute(\\"id\\",\\"\\");' + 'ReactDOM.render(React.createElement(ReactComponent,' + props + '),targetNode);' + '}' + ');' + '});' + '});' + '</script>' }"`;

packages/oc-template-react-compiler/__tests__/compile.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,21 @@ const execute = (options, cb) => {
8383
result.oc.date = "";
8484
result.oc.files.template.version = "";
8585
nodeDir.paths(options.publishPath, (err2, res2) => {
86-
const files = _.chain(res2.files)
86+
const files = _
87+
.chain(res2.files)
8788
.map(filePath => {
8889
const source = fs.readFileSync(filePath, "UTF8");
8990
return {
9091
source: !filePath.match(/\.png$/)
91-
? source.replace(/"date":\d+/, "")
92+
? source
93+
.replace(/"date":\d+/, "")
94+
.replace(/\"hashKey\"\:\".*?\"\,/g, "")
95+
.replace(/omponents\['.*?'\]/g, "omponents['dummyContent']")
96+
.replace(/key\:\'.*?\'/g, "")
97+
.replace(
98+
/\[\"oc\",.*?\"reactComponents\",.*?\".*?\"\]/g,
99+
'["oc", "reactComponents", "dummyContent"]'
100+
)
92101
: "img-binary",
93102
path: path.relative(__dirname, filePath)
94103
};
@@ -105,6 +114,10 @@ _.each(components, scenarios => {
105114
test(testName, done => {
106115
execute(scenario, (err, { result, files }) => {
107116
expect(err).toBeNull();
117+
if (result.oc.files.dataProvider) {
118+
result.oc.files.dataProvider.hashKey = "dummyData";
119+
}
120+
result.oc.files.template.hashKey = "dummyData";
108121
expect(result).toMatchSnapshot();
109122
expect(files).toMatchSnapshot();
110123
done();

packages/oc-template-react-compiler/__tests__/compileServer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ test("Should correctly compile the server", done => {
2323
}),
2424
(err, compiledServerInfo) => {
2525
expect(err).toBeNull();
26+
compiledServerInfo.hashKey = "dummyData";
2627
expect(compiledServerInfo).toMatchSnapshot();
2728
expect(
2829
fs.readFileSync(path.join(publishPath, publishFileName), "UTF8")

packages/oc-template-react-compiler/__tests__/compileView.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ test("valid component", done => {
1818
};
1919

2020
compileView(options, (err, compiledViewInfo) => {
21+
compiledViewInfo.bundle.hashKey = "dummyData";
22+
const viewHashKey = compiledViewInfo.template.hashKey;
23+
compiledViewInfo.template.hashKey = "dummyData";
2124
expect(compiledViewInfo).toMatchSnapshot();
2225
expect(
23-
fs.readFileSync(path.join(publishPath, publishFileName), "UTF8")
26+
fs
27+
.readFileSync(path.join(publishPath, publishFileName), "UTF8")
28+
.replace(viewHashKey, "dummyData")
29+
.replace(
30+
/\[\"oc\",.*?\"reactComponents\",.*?\".*?\"\]/g,
31+
'["oc", "reactComponents", "dummyContent"]'
32+
)
2433
).toMatchSnapshot();
2534
fs.removeSync(publishPath);
2635
done();

0 commit comments

Comments
 (0)