Skip to content

Commit

Permalink
test(e2e): add case for jsconfig#paths (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Apr 8, 2024
1 parent 189e706 commit bc92449
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
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);

0 comments on commit bc92449

Please sign in to comment.