Skip to content

Commit ec33331

Browse files
authored
test(e2e): update plugin hooks test case (#2100)
1 parent 018422f commit ec33331

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

e2e/cases/plugin-api/plugin-hooks/index.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import path from 'node:path';
22
import { test, expect } from '@playwright/test';
3+
import { gotoPage } from '@e2e/helper';
34
import { type RsbuildPlugin, createRsbuild } from '@rsbuild/core';
4-
import { fse } from '@rsbuild/shared';
5+
import { fse, setNodeEnv } from '@rsbuild/shared';
56

67
const distFile = path.join(__dirname, 'node_modules/hooksTempFile');
78

@@ -22,6 +23,10 @@ const plugin: RsbuildPlugin = {
2223
api.modifyWebpackChain(() => write('ModifyBundlerConfig'));
2324
api.modifyRsbuildConfig(() => write('ModifyRsbuildConfig'));
2425
api.modifyBundlerChain(() => write('ModifyBundlerChain'));
26+
api.modifyHTMLTags((tags) => {
27+
write('ModifyHTMLTags');
28+
return tags;
29+
});
2530
api.onBeforeStartDevServer(() => write('BeforeStartDevServer'));
2631
api.onAfterStartDevServer(() => write('AfterStartDevServer'));
2732
api.onBeforeCreateCompiler(() => write('BeforeCreateCompiler'));
@@ -31,6 +36,7 @@ const plugin: RsbuildPlugin = {
3136
api.onBeforeStartProdServer(() => write('BeforeStartProdServer'));
3237
api.onCloseDevServer(() => write('OnCloseDevServer'));
3338
api.onAfterStartProdServer(() => write('AfterStartProdServer'));
39+
api.onDevCompileDone(() => write('OnDevCompileDone'));
3440
},
3541
};
3642

@@ -53,11 +59,15 @@ test('should run plugin hooks correctly when running build', async () => {
5359
'BeforeCreateCompiler',
5460
'AfterCreateCompiler',
5561
'BeforeBuild',
62+
'ModifyHTMLTags',
5663
'AfterBuild',
5764
]);
5865
});
5966

60-
test('should run plugin hooks correctly when running startDevServer', async () => {
67+
test('should run plugin hooks correctly when running startDevServer', async ({
68+
page,
69+
}) => {
70+
setNodeEnv('development');
6171
fse.removeSync(distFile);
6272

6373
const rsbuild = await createRsbuild({
@@ -69,6 +79,8 @@ test('should run plugin hooks correctly when running startDevServer', async () =
6979

7080
const result = await rsbuild.startDevServer();
7181

82+
await gotoPage(page, result);
83+
7284
await result.server.close();
7385

7486
expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual([
@@ -79,8 +91,12 @@ test('should run plugin hooks correctly when running startDevServer', async () =
7991
'BeforeCreateCompiler',
8092
'AfterCreateCompiler',
8193
'AfterStartDevServer',
94+
'ModifyHTMLTags',
95+
'OnDevCompileDone',
8296
'OnCloseDevServer',
8397
]);
98+
99+
setNodeEnv('test');
84100
});
85101

86102
test('should run plugin hooks correctly when running preview', async () => {

0 commit comments

Comments
 (0)