Skip to content

Commit 785798e

Browse files
committed
test: Add tests for updated push-manifest building
1 parent 190e291 commit 785798e

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

packages/cli/tests/build.test.js

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { join } = require('path');
2-
const { access, readdir, readFile } = require('fs').promises;
2+
const { access, readdir, readFile, writeFile } = require('fs').promises;
33
const looksLike = require('html-looks-like');
44
const { create, build } = require('./lib/cli');
55
const { snapshot } = require('./lib/utils');
@@ -245,13 +245,55 @@ describe('preact build', () => {
245245
mockExit.mockRestore();
246246
});
247247

248-
it('should produce correct push-manifest', async () => {
249-
let dir = await create('default');
248+
describe('Push manifest plugin', () => {
249+
it('should produce correct default `push-manifest.json`', async () => {
250+
let dir = await create('default');
250251

251-
await build(dir);
252-
const manifest = await readFile(`${dir}/build/push-manifest.json`, 'utf8');
253-
expect(manifest).toEqual(
254-
expect.stringMatching(getRegExpFromMarkup(images.pushManifest))
255-
);
252+
await build(dir);
253+
const manifest = await readFile(
254+
`${dir}/build/push-manifest.json`,
255+
'utf8'
256+
);
257+
expect(manifest).toEqual(
258+
expect.stringMatching(getRegExpFromMarkup(images.pushManifest))
259+
);
260+
});
261+
262+
it('should produce correct `push-manifest.json` when expected values are missing', async () => {
263+
// In this subject, there is no source CSS which means no CSS asset is output.
264+
// In the past, this would result in `"undefined": { type: "style" ... }` being added to the manifest.
265+
let dir = await subject('custom-webpack');
266+
await build(dir);
267+
const manifest = await readFile(
268+
`${dir}/build/push-manifest.json`,
269+
'utf8'
270+
);
271+
expect(manifest).not.toMatch(/"undefined"/);
272+
});
273+
274+
// Issue #1675
275+
it('should produce correct `push-manifest.json` when user configures output filenames', async () => {
276+
let dir = await subject('custom-webpack');
277+
278+
const config = await readFile(`${dir}/preact.config.js`, 'utf8');
279+
await writeFile(
280+
`${dir}/preact.config.js`,
281+
config.replace(
282+
"config.output.filename = '[name].js'",
283+
"config.output.filename = 'scripts/[name].js'"
284+
)
285+
);
286+
287+
await build(dir, { prerender: false });
288+
const manifest = await readFile(
289+
`${dir}/build/push-manifest.json`,
290+
'utf8'
291+
);
292+
expect(manifest).toEqual(
293+
expect.stringMatching(
294+
getRegExpFromMarkup(images.pushManifestAlteredFilenames)
295+
)
296+
);
297+
});
256298
});
257299
});

packages/cli/tests/images/build.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exports.default = Object.assign({}, common, {
1515
'ssr-build/ssr-bundle.aaacf.css.map': 2070,
1616
'ssr-build/ssr-bundle.js': 11937,
1717
'ssr-build/ssr-bundle.js.map': 32557,
18+
'ssr-build/asset-manifest.json': 178,
1819
'bundle.2da73.css': 901,
1920
'bundle.44866.js': 21429,
2021
'bundle.44866.js.map': 111801,
@@ -23,6 +24,7 @@ exports.default = Object.assign({}, common, {
2324
'manifest.json': 455,
2425
'preact_prerender_data.json': 11,
2526
'push-manifest.json': 450,
27+
'asset-manifest.json': 1074,
2628
'route-home.chunk.bcb8a.css': 58,
2729
'route-home.chunk.3cec8.js': 327,
2830
'route-home.chunk.3cec8.js.map': 483,
@@ -42,6 +44,7 @@ exports['default-esm'] = Object.assign({}, exports.default, {
4244
'route-profile.chunk.*.esm.js.map': 15392,
4345
'index.html': 2193,
4446
'push-manifest.json': 466,
47+
'asset-manifest.json': 1106,
4548
});
4649

4750
exports.sass = `
@@ -253,3 +256,14 @@ exports.pushManifest = `
253256
}
254257
}
255258
`;
259+
260+
exports.pushManifestAlteredFilenames = `
261+
{
262+
"/":{
263+
"scripts/bundle.js":{
264+
"type":"script",
265+
"weight":1
266+
}
267+
}
268+
}
269+
`;

0 commit comments

Comments
 (0)