-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
server.base
configuration (#3542)
Co-authored-by: neverland <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
- Loading branch information
1 parent
dbad5d5
commit c681381
Showing
39 changed files
with
626 additions
and
29 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,133 @@ | ||
import { build, dev, proxyConsole } from '@e2e/helper'; | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test('server.base when dev', async ({ page }) => { | ||
const { logs, restore } = proxyConsole('log'); | ||
|
||
const rsbuild = await dev({ | ||
cwd: __dirname, | ||
page, | ||
rsbuildConfig: { | ||
html: { | ||
template: './src/index.html', | ||
}, | ||
server: { | ||
printUrls: true, | ||
base: '/base', | ||
}, | ||
}, | ||
}); | ||
|
||
// should redirect root visit to based url | ||
await expect(page.locator('#test')).toHaveText('Hello Rsbuild!'); | ||
|
||
expect(page.url().includes('/base/')).toBeTruthy(); | ||
|
||
// should define `process.env.BASE_URL` correctly | ||
await expect(page.locator('#public-base-path')).toHaveText('/base'); | ||
|
||
// should print url with base path | ||
const baseUrlLog = logs.find( | ||
(log) => | ||
log.includes('Local:') && log.includes(`localhost:${rsbuild.port}/base`), | ||
); | ||
|
||
expect(baseUrlLog).toBeTruthy(); | ||
|
||
// should visit base url correctly | ||
await page.goto(`http://localhost:${rsbuild.port}/base`); | ||
|
||
await expect(page.locator('#test')).toHaveText('Hello Rsbuild!'); | ||
|
||
// should 404 when visit resource without base prefix | ||
const indexRes = await page.goto(`http://localhost:${rsbuild.port}/a`); | ||
expect(indexRes?.status()).toBe(404); | ||
expect(await page.content()).toContain( | ||
'The server is configured with a base URL of /base', | ||
); | ||
|
||
// should visit public dir correctly with base prefix | ||
await page.goto(`http://localhost:${rsbuild.port}/base/aaa.txt`); | ||
|
||
expect(await page.content()).toContain('aaaa'); | ||
|
||
restore(); | ||
await rsbuild.close(); | ||
}); | ||
|
||
test('server.base when build & preview', async ({ page }) => { | ||
const { logs, restore } = proxyConsole('log'); | ||
|
||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
page, | ||
runServer: true, | ||
rsbuildConfig: { | ||
html: { | ||
template: './src/index.html', | ||
}, | ||
server: { | ||
printUrls: true, | ||
base: '/base', | ||
}, | ||
}, | ||
}); | ||
|
||
// should redirect root visit to based url | ||
await expect(page.locator('#test')).toHaveText('Hello Rsbuild!'); | ||
|
||
expect(page.url().includes('/base/')).toBeTruthy(); | ||
|
||
// should define `process.env.BASE_URL` correctly | ||
await expect(page.locator('#public-base-path')).toHaveText('/base'); | ||
|
||
// should print url with base path | ||
const baseUrlLog = logs.find( | ||
(log) => | ||
log.includes('Local:') && log.includes(`localhost:${rsbuild.port}/base`), | ||
); | ||
|
||
expect(baseUrlLog).toBeTruthy(); | ||
|
||
// should visit base url correctly | ||
await page.goto(`http://localhost:${rsbuild.port}/base`); | ||
|
||
await expect(page.locator('#test')).toHaveText('Hello Rsbuild!'); | ||
|
||
// should 404 when visit resource without base prefix | ||
const indexRes = await page.goto(`http://localhost:${rsbuild.port}/a`); | ||
expect(indexRes?.status()).toBe(404); | ||
expect(await page.content()).toContain( | ||
'The server is configured with a base URL of /base', | ||
); | ||
|
||
// should visit public dir correctly with base prefix | ||
await page.goto(`http://localhost:${rsbuild.port}/base/aaa.txt`); | ||
|
||
expect(await page.content()).toContain('aaaa'); | ||
|
||
restore(); | ||
await rsbuild.close(); | ||
}); | ||
|
||
test('should serve resource correctly when assetPrefix is a subPath of server.base', async ({ | ||
page, | ||
}) => { | ||
const rsbuild = await dev({ | ||
cwd: __dirname, | ||
page, | ||
rsbuildConfig: { | ||
dev: { | ||
assetPrefix: '/base/aaa', | ||
}, | ||
server: { | ||
base: '/base', | ||
}, | ||
}, | ||
}); | ||
|
||
const locator = page.locator('#test'); | ||
await expect(locator).toHaveText('Hello Rsbuild!'); | ||
|
||
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 @@ | ||
aaaa |
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,13 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head></head> | ||
|
||
<body> | ||
<div id="public-base-path"> | ||
<%= process.env.BASE_URL %> | ||
</div> | ||
<div id="root"></div> | ||
</body> | ||
|
||
</html> |
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,5 @@ | ||
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
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
Oops, something went wrong.