|
1 | 1 | const { join } = require('path'); |
2 | | -const { access, readdir, readFile } = require('fs').promises; |
| 2 | +const { access, readdir, readFile, writeFile } = require('fs').promises; |
3 | 3 | const looksLike = require('html-looks-like'); |
4 | 4 | const { create, build } = require('./lib/cli'); |
5 | 5 | const { snapshot } = require('./lib/utils'); |
@@ -245,13 +245,55 @@ describe('preact build', () => { |
245 | 245 | mockExit.mockRestore(); |
246 | 246 | }); |
247 | 247 |
|
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'); |
250 | 251 |
|
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 | + }); |
256 | 298 | }); |
257 | 299 | }); |
0 commit comments