-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix router info error when use custom file system routes entry (#…
- Loading branch information
Showing
10 changed files
with
207 additions
and
23 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,7 @@ | ||
--- | ||
'@modern-js/runtime': patch | ||
--- | ||
|
||
fix: fix router info error when use custom file system routes entry | ||
|
||
fix: 修复当使用自定义约定式路由入口时生成 router 信息问题 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
tests/integration/custom-file-system-entry/modern.config.ts
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,20 @@ | ||
import { appTools, defineConfig } from '@modern-js/app-tools'; | ||
|
||
const bundler = process.env.BUNDLER; | ||
|
||
export default defineConfig({ | ||
source: { | ||
entries: { | ||
custom: 'src/custom', | ||
}, | ||
disableDefaultEntries: true, | ||
}, | ||
runtime: { | ||
router: true, | ||
}, | ||
plugins: [ | ||
appTools({ | ||
bundler: bundler === 'rspack' ? 'experimental-rspack' : 'webpack', | ||
}), | ||
], | ||
}); |
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,32 @@ | ||
{ | ||
"private": true, | ||
"name": "custom-file-system-entry", | ||
"version": "2.9.0", | ||
"scripts": { | ||
"dev": "modern dev", | ||
"build": "modern build", | ||
"serve": "modern serve", | ||
"new": "modern new", | ||
"lint": "modern lint" | ||
}, | ||
"engines": { | ||
"node": ">=14.17.6" | ||
}, | ||
"eslintIgnore": [ | ||
"node_modules/", | ||
"dist/" | ||
], | ||
"dependencies": { | ||
"@modern-js/runtime": "workspace:*", | ||
"react": "^18", | ||
"react-dom": "^18" | ||
}, | ||
"devDependencies": { | ||
"@modern-js/app-tools": "workspace:*", | ||
"@types/node": "^14", | ||
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"typescript": "^5", | ||
"@types/jest": "^29" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/integration/custom-file-system-entry/src/custom/layout.tsx
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,10 @@ | ||
import { Outlet } from '@modern-js/runtime/router'; | ||
|
||
export default function Layout() { | ||
return ( | ||
<div> | ||
root layout | ||
<Outlet /> | ||
</div> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/integration/custom-file-system-entry/src/custom/page.tsx
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 App = () => { | ||
return <div className="index">custom entry</div>; | ||
}; | ||
|
||
export default App; |
51 changes: 51 additions & 0 deletions
51
tests/integration/custom-file-system-entry/tests/index.test.ts
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,51 @@ | ||
import path from 'path'; | ||
import puppeteer, { Browser } from 'puppeteer'; | ||
|
||
import type { Page } from 'puppeteer'; | ||
import { | ||
launchApp, | ||
killApp, | ||
getPort, | ||
launchOptions, | ||
} from '../../../utils/modernTestUtils'; | ||
|
||
const appDir = path.resolve(__dirname, '../'); | ||
|
||
describe('dev', () => { | ||
let app: unknown; | ||
let appPort: number; | ||
let page: Page; | ||
let browser: Browser; | ||
const errors: string[] = []; | ||
beforeAll(async () => { | ||
appPort = await getPort(); | ||
app = await launchApp(appDir, appPort, {}, {}); | ||
browser = await puppeteer.launch(launchOptions as any); | ||
page = await browser.newPage(); | ||
await page.setRequestInterception(true); | ||
page.on('request', interceptedRequest => { | ||
interceptedRequest.continue(); | ||
}); | ||
page.on('pageerror', error => { | ||
console.log(error.message); | ||
errors.push(error.message); | ||
}); | ||
}); | ||
|
||
test('should render correctly', async () => { | ||
await page.goto(`http://localhost:${appPort}/custom`, { | ||
waitUntil: ['networkidle0'], | ||
}); | ||
const element = await page.$('.index'); | ||
const targetText = await page.evaluate( | ||
el => el?.firstChild?.textContent, | ||
element, | ||
); | ||
expect(targetText?.includes('custom entry')); | ||
}); | ||
afterAll(async () => { | ||
await killApp(app); | ||
await page.close(); | ||
await browser.close(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
tests/integration/custom-file-system-entry/tests/tsconfig.json
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": "@modern-js/tsconfig/base", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"jsx": "preserve", | ||
"baseUrl": "./", | ||
"emitDeclarationOnly": true, | ||
"isolatedModules": true, | ||
"paths": {}, | ||
"types": ["node", "jest"] | ||
} | ||
} |
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 @@ | ||
{ | ||
"extends": "@modern-js/tsconfig/base", | ||
"compilerOptions": { | ||
"declaration": false, | ||
"jsx": "preserve", | ||
"baseUrl": "./", | ||
"paths": { | ||
"@/*": ["./src/*"], | ||
"@shared/*": ["./shared/*"] | ||
} | ||
}, | ||
"include": ["src", "shared", "config"] | ||
} |