Skip to content

Commit 79beb74

Browse files
committed
Fix of a test and problems it detected
1 parent 74dbf78 commit 79beb74

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

__tests__/server/renderer.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const TEST_HTTP_REQUEST = {
3636
const TEST_WEBPACK_CONFIG = {
3737
context: TEST_CONTEXT,
3838
output: {
39+
path: '/test/path',
3940
publicPath: '/test/public/path/',
4041
},
4142
};
@@ -76,6 +77,19 @@ async function coreTest(webpackConfig, options) {
7677
try {
7778
let render = '';
7879
await renderer(_.clone(TEST_HTTP_REQUEST), {
80+
locals: {
81+
webpackStats: {
82+
toJson: () => ({
83+
assetsByChunkName: {
84+
'test-chunk-a': 'test-chunk-a-1511941200000.css',
85+
'test-chunk-b': [
86+
'test-chunk-b-1511941200000.js',
87+
'test-chunk-b-1511941200000.css',
88+
],
89+
},
90+
}),
91+
},
92+
},
7993
send: (x) => { render += x; },
8094
status: (x) => { render += `HTTP STATUS: ${x}\n`; },
8195
});

src/server/renderer.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,21 @@ export default function factory(webpackConfig, options) {
163163
const { webpackStats } = res.locals;
164164
if (webpackStats) {
165165
({ assetsByChunkName } = webpackStats.toJson());
166-
} else ({ assetsByChunkName } = WEBPACK_STATS);
166+
} else if (WEBPACK_STATS) ({ assetsByChunkName } = WEBPACK_STATS);
167+
else assetsByChunkName = {};
167168

168169
const timestamp = moment(buildInfo.timestamp).valueOf();
169170

170171
if (context.status) res.status(context.status);
171172
const styles = [];
172173
context.chunks.forEach((chunk) => {
173174
let assets = assetsByChunkName[chunk];
175+
if (!assets) return;
174176
if (!_.isArray(assets)) assets = [assets];
175177
assets = assets.filter(asset => asset.endsWith('.css'));
176178
assets.forEach((asset) => {
177179
styles.push((
178-
`<link href="${publicPath}${asset}" id="tru-style" rel="stylesheet" />`
180+
`<link data-chunk="${chunk}" id="tru-style" href="${publicPath}${asset}" rel="stylesheet" />`
179181
));
180182
});
181183
});

0 commit comments

Comments
 (0)