-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): add case for jsconfig#paths (#2032)
- Loading branch information
1 parent
189e706
commit bc92449
Showing
5 changed files
with
79 additions
and
0 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,53 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { build, gotoPage, rspackOnlyTest } from '@e2e/helper'; | ||
|
||
rspackOnlyTest( | ||
'tsconfig paths should work and override the alias config', | ||
async ({ page }) => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
runServer: true, | ||
rsbuildConfig: { | ||
source: { | ||
alias: { | ||
'@common': './src/common2', | ||
}, | ||
tsconfigPath: './jsconfig.json', | ||
}, | ||
}, | ||
}); | ||
|
||
await gotoPage(page, rsbuild); | ||
|
||
const foo = page.locator('#foo'); | ||
await expect(foo).toHaveText('tsconfig paths worked'); | ||
|
||
await rsbuild.close(); | ||
}, | ||
); | ||
|
||
rspackOnlyTest( | ||
'tsconfig paths should not work when aliasStrategy is "prefer-alias"', | ||
async ({ page }) => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
runServer: true, | ||
rsbuildConfig: { | ||
source: { | ||
alias: { | ||
'@/common': './src/common2', | ||
}, | ||
aliasStrategy: 'prefer-alias', | ||
tsconfigPath: './jsconfig.json', | ||
}, | ||
}, | ||
}); | ||
|
||
await gotoPage(page, rsbuild); | ||
|
||
const foo = page.locator('#foo'); | ||
await expect(foo).toHaveText('source.alias worked'); | ||
|
||
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 @@ | ||
{ | ||
"extends": "@rsbuild/tsconfig/base", | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"baseUrl": "./", | ||
"outDir": "./dist", | ||
"paths": { | ||
"@/common/*": ["./src/common/*"] | ||
} | ||
}, | ||
"include": ["src"] | ||
} |
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 @@ | ||
export const content = 'tsconfig paths worked'; |
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 @@ | ||
export const content = 'source.alias worked'; |
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 @@ | ||
import { content } from '@/common/test'; | ||
|
||
const testAliasEl = document.createElement('div'); | ||
testAliasEl.id = 'foo'; | ||
testAliasEl.innerHTML = content; | ||
document.body.appendChild(testAliasEl); | ||
|
||
const testEl = document.createElement('div'); | ||
testEl.id = 'test'; | ||
testEl.innerHTML = 'Hello Rsbuild!'; | ||
|
||
document.body.appendChild(testEl); |