Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add case for jsconfig#paths #2032

Merged
merged 1 commit into from
Apr 8, 2024
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
53 changes: 53 additions & 0 deletions e2e/cases/source/jsconfig-paths/index.test.ts
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();
},
);
12 changes: 12 additions & 0 deletions e2e/cases/source/jsconfig-paths/jsconfig.json
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"]
}
1 change: 1 addition & 0 deletions e2e/cases/source/jsconfig-paths/src/common/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const content = 'tsconfig paths worked';
1 change: 1 addition & 0 deletions e2e/cases/source/jsconfig-paths/src/common2/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const content = 'source.alias worked';
12 changes: 12 additions & 0 deletions e2e/cases/source/jsconfig-paths/src/index.js
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);