Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions e2e/cases/manifest/basic/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expect, getFileContent, test } from '@e2e/helper';

test('should generate manifest file in output', async ({ build }) => {
const rsbuild = await build({
config: {
output: {
manifest: true,
filenameHash: false,
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
},
});

const files = rsbuild.getDistFiles();

const manifestContent = getFileContent(files, 'manifest.json');

expect(manifestContent).toBeDefined();

const manifest = JSON.parse(manifestContent);

// index.js, index.html
expect(Object.keys(manifest.allFiles).length).toBe(2);

expect(manifest.entries.index).toMatchObject({
initial: {
js: ['/static/js/index.js'],
},
html: ['/index.html'],
});
});

test('should always write manifest to disk when in dev', async ({ dev }) => {
const rsbuild = await dev({
config: {
output: {
distPath: 'dist-dev',
manifest: true,
filenameHash: false,
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
},
});

const files = rsbuild.getDistFiles();

const manifestContent = getFileContent(files, 'manifest.json');

expect(manifestContent).toBeDefined();
});
16 changes: 16 additions & 0 deletions e2e/cases/manifest/custom-path/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { expect, test } from '@e2e/helper';

test('should generate manifest file at specified path', async ({ build }) => {
await build();

const manifest = join(import.meta.dirname, 'dist', 'custom/my-manifest.json');
const manifestContent = readFileSync(manifest, 'utf-8');
expect(manifestContent).toBeDefined();

const parsed = JSON.parse(manifestContent);

// index.js, index.html
expect(Object.keys(parsed.allFiles).length).toBe(2);
});
13 changes: 13 additions & 0 deletions e2e/cases/manifest/custom-path/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
output: {
manifest: './custom/my-manifest.json',
filenameHash: false,
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('should allow to access manifest data in environment context after build',
},
});

// main.js, index.html
// index.js, index.html
expect(Object.keys(webManifest.allFiles).length).toBe(2);
expect(webManifest.entries.index).toMatchObject({
initial: {
Expand All @@ -52,7 +52,7 @@ test('should allow to access manifest data in environment context after build',
html: ['/index.html'],
});

// main.js
// index.js
expect(Object.keys(nodeManifest.allFiles).length).toBe(1);
expect(nodeManifest.entries.index).toMatchObject({
initial: {
Expand Down Expand Up @@ -103,7 +103,7 @@ test('should allow to access manifest data in environment context after dev buil
},
});

// main.js, main.js.map, index.html
// index.js, index.js.map, index.html
expect(Object.keys(webManifest.allFiles).length).toBe(3);
expect(webManifest.entries.index).toMatchObject({
initial: {
Expand All @@ -112,7 +112,7 @@ test('should allow to access manifest data in environment context after dev buil
html: ['/index.html'],
});

// main.js, main.js.map
// index.js, index.js.map
expect(Object.keys(nodeManifest.allFiles).length).toBe(2);
expect(nodeManifest.entries.index).toMatchObject({
initial: {
Expand Down Expand Up @@ -161,7 +161,7 @@ test('should allow to access manifest data in environment API', async ({
// should visit base url correctly
await page.goto(`http://localhost:${rsbuild.port}`);

// main.js, main.js.map, index.html
// index.js, index.js.map, index.html
expect(Object.keys(webManifest.allFiles).length).toBe(3);
expect(webManifest.entries.index).toMatchObject({
initial: {
Expand All @@ -170,7 +170,7 @@ test('should allow to access manifest data in environment API', async ({
html: ['/index.html'],
});

// main.js, main.js.map
// index.js, index.js.map
expect(Object.keys(nodeManifest.allFiles).length).toBe(2);
expect(nodeManifest.entries.index).toMatchObject({
initial: {
Expand Down
69 changes: 69 additions & 0 deletions e2e/cases/manifest/filter/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { expect, getFileContent, rspackTest, test } from '@e2e/helper';

test('should allow to filter files in manifest', async ({ build }) => {
const rsbuild = await build({
config: {
output: {
manifest: {
filter: (file) => file.name.endsWith('.js'),
},
filenameHash: false,
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
},
});

const files = rsbuild.getDistFiles();

const manifestContent = getFileContent(files, 'manifest.json');
const manifest = JSON.parse(manifestContent);

// index.js
expect(Object.keys(manifest.allFiles).length).toBe(1);

expect(manifest.entries.index).toMatchObject({
initial: {
js: ['/static/js/index.js'],
},
});
});

rspackTest(
'should allow to include license files in manifest',
async ({ build }) => {
const rsbuild = await build({
config: {
output: {
manifest: {
filter: () => true,
},
filenameHash: false,
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
},
});

const files = rsbuild.getDistFiles();

const manifestContent = getFileContent(files, 'manifest.json');
const manifest = JSON.parse(manifestContent);

expect(Object.keys(manifest.allFiles).length).toBe(3);

expect(manifest.entries.index).toMatchObject({
initial: {
js: ['/static/js/index.js'],
},
html: ['/index.html'],
assets: ['/static/js/index.js.LICENSE.txt'],
});
},
);
3 changes: 3 additions & 0 deletions e2e/cases/manifest/filter/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

console.log('hello!', React);
3 changes: 3 additions & 0 deletions e2e/cases/manifest/integrity/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

console.log('hello!', React);
18 changes: 18 additions & 0 deletions e2e/cases/manifest/node/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect, getFileContent, test } from '@e2e/helper';

test('should generate manifest file when target is node', async ({ build }) => {
const rsbuild = await build();
const files = rsbuild.getDistFiles();
const manifestContent = getFileContent(files, 'manifest.json');

expect(manifestContent).toBeDefined();

const manifest = JSON.parse(manifestContent);
expect(Object.keys(manifest.allFiles).length).toBe(1);

expect(manifest.entries.index).toMatchObject({
initial: {
js: ['/index.js'],
},
});
});
9 changes: 9 additions & 0 deletions e2e/cases/manifest/node/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
output: {
target: 'node',
manifest: true,
filenameHash: false,
},
});
3 changes: 3 additions & 0 deletions e2e/cases/manifest/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

console.log('hello!', React);
Loading
Loading