|
| 1 | +import { build, dev } from '@e2e/helper'; |
| 2 | +import { expect, test } from '@playwright/test'; |
| 3 | +import type { RsbuildPluginAPI } from '@rsbuild/core'; |
| 4 | + |
| 5 | +const fixtures = __dirname; |
| 6 | + |
| 7 | +test('should allow to access manifest data in environment context after prod build', async () => { |
| 8 | + let webManifest: Record<string, any> = {}; |
| 9 | + let nodeManifest: Record<string, any> = {}; |
| 10 | + |
| 11 | + await build({ |
| 12 | + cwd: fixtures, |
| 13 | + rsbuildConfig: { |
| 14 | + output: { |
| 15 | + manifest: true, |
| 16 | + filenameHash: false, |
| 17 | + }, |
| 18 | + environments: { |
| 19 | + web: {}, |
| 20 | + node: { |
| 21 | + output: { |
| 22 | + target: 'node', |
| 23 | + }, |
| 24 | + }, |
| 25 | + }, |
| 26 | + plugins: [ |
| 27 | + { |
| 28 | + name: 'test', |
| 29 | + setup(api: RsbuildPluginAPI) { |
| 30 | + api.onAfterBuild(({ environments }) => { |
| 31 | + if (environments.web.manifest) { |
| 32 | + webManifest = environments.web.manifest; |
| 33 | + } |
| 34 | + if (environments.node.manifest) { |
| 35 | + nodeManifest = environments.node.manifest; |
| 36 | + } |
| 37 | + }); |
| 38 | + }, |
| 39 | + }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + }); |
| 43 | + |
| 44 | + // main.js, index.html |
| 45 | + expect(Object.keys(webManifest.allFiles).length).toBe(2); |
| 46 | + expect(webManifest.entries.index).toMatchObject({ |
| 47 | + initial: { |
| 48 | + js: ['/static/js/index.js'], |
| 49 | + }, |
| 50 | + html: ['/index.html'], |
| 51 | + }); |
| 52 | + |
| 53 | + // main.js |
| 54 | + expect(Object.keys(nodeManifest.allFiles).length).toBe(1); |
| 55 | + expect(nodeManifest.entries.index).toMatchObject({ |
| 56 | + initial: { |
| 57 | + js: ['/index.js'], |
| 58 | + }, |
| 59 | + }); |
| 60 | +}); |
| 61 | + |
| 62 | +test('should allow to access manifest data in environment context after dev build', async ({ |
| 63 | + page, |
| 64 | +}) => { |
| 65 | + let webManifest: Record<string, any> = {}; |
| 66 | + let nodeManifest: Record<string, any> = {}; |
| 67 | + |
| 68 | + const rsbuild = await dev({ |
| 69 | + cwd: fixtures, |
| 70 | + page, |
| 71 | + rsbuildConfig: { |
| 72 | + output: { |
| 73 | + manifest: true, |
| 74 | + filenameHash: false, |
| 75 | + }, |
| 76 | + environments: { |
| 77 | + web: {}, |
| 78 | + node: { |
| 79 | + output: { |
| 80 | + target: 'node', |
| 81 | + }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + plugins: [ |
| 85 | + { |
| 86 | + name: 'test', |
| 87 | + setup(api: RsbuildPluginAPI) { |
| 88 | + api.onDevCompileDone(({ environments }) => { |
| 89 | + if (environments.web.manifest) { |
| 90 | + webManifest = environments.web.manifest; |
| 91 | + } |
| 92 | + if (environments.node.manifest) { |
| 93 | + nodeManifest = environments.node.manifest; |
| 94 | + } |
| 95 | + }); |
| 96 | + }, |
| 97 | + }, |
| 98 | + ], |
| 99 | + }, |
| 100 | + }); |
| 101 | + |
| 102 | + // main.js, main.js.map, index.html |
| 103 | + expect(Object.keys(webManifest.allFiles).length).toBe(3); |
| 104 | + expect(webManifest.entries.index).toMatchObject({ |
| 105 | + initial: { |
| 106 | + js: ['/static/js/index.js'], |
| 107 | + }, |
| 108 | + html: ['/index.html'], |
| 109 | + }); |
| 110 | + |
| 111 | + // main.js, main.js.map |
| 112 | + expect(Object.keys(nodeManifest.allFiles).length).toBe(2); |
| 113 | + expect(nodeManifest.entries.index).toMatchObject({ |
| 114 | + initial: { |
| 115 | + js: ['/index.js'], |
| 116 | + }, |
| 117 | + }); |
| 118 | + |
| 119 | + await rsbuild.close(); |
| 120 | +}); |
0 commit comments