-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support registering async plugin in config (#1657)
- Loading branch information
1 parent
7dc1735
commit c0dee79
Showing
8 changed files
with
116 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { expect } from '@playwright/test'; | ||
import { build, gotoPage, rspackOnlyTest } from '@e2e/helper'; | ||
import type { RsbuildPlugin } from '@rsbuild/core'; | ||
|
||
const asyncPlugin = async (): Promise<RsbuildPlugin> => { | ||
await new Promise((resolve) => { | ||
setTimeout(resolve); | ||
}); | ||
|
||
return { | ||
name: 'async-plugin', | ||
setup(api) { | ||
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => { | ||
return mergeRsbuildConfig(config, { | ||
source: { | ||
define: { | ||
ENABLE_TEST: JSON.stringify(true), | ||
}, | ||
}, | ||
}); | ||
}); | ||
}, | ||
}; | ||
}; | ||
|
||
rspackOnlyTest( | ||
'should allow to register async plugin in plugins field', | ||
async ({ page }) => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
runServer: true, | ||
plugins: [asyncPlugin()], | ||
}); | ||
|
||
await gotoPage(page, rsbuild); | ||
|
||
const testEl = page.locator('#test-el'); | ||
await expect(testEl).toHaveText('aaaaa'); | ||
|
||
await rsbuild.close(); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
if (ENABLE_TEST === true) { | ||
const test = document.createElement('div'); | ||
test.id = 'test-el'; | ||
test.innerHTML = 'aaaaa'; | ||
document.body.appendChild(test); | ||
} | ||
|
||
const testEl = document.createElement('div'); | ||
testEl.id = 'test'; | ||
testEl.innerHTML = 'Hello Rsbuild!'; | ||
|
||
document.body.appendChild(testEl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters