Skip to content

Commit

Permalink
fix: builder e2e test (#5994)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name authored Jul 24, 2024
1 parent a6f5bfe commit 6b3f453
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 93 deletions.
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions tests/e2e/builder/cases/dev/history-api-fallback.test.ts

This file was deleted.

25 changes: 0 additions & 25 deletions tests/e2e/builder/cases/dev/history-api-fallback/src/App.tsx

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions tests/e2e/builder/cases/dev/history-api-fallback/tsconfig.json

This file was deleted.

7 changes: 1 addition & 6 deletions tests/e2e/builder/scripts/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fs from '@modern-js/utils/fs-extra';
import type {
UniBuilderConfig,
CreateUniBuilderOptions,
StartDevServerOptions,
} from '@modern-js/uni-builder';

type CreateBuilderOptions = Omit<
Expand Down Expand Up @@ -95,24 +94,20 @@ const updateConfigForTest = (
};

export async function dev({
serverOptions,
builderConfig = {},
entry,
...options
}: CreateBuilderOptions & {
entry: Record<string, string>;
builderConfig?: UniBuilderConfig;
serverOptions?: StartDevServerOptions['serverOptions'];
}) {
process.env.NODE_ENV = 'development';

updateConfigForTest(builderConfig, entry);

const builder = await createUniBuilder(options, builderConfig);

return builder.startDevServer({
serverOptions,
});
return builder.startDevServer();
}

export async function build({
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/dev-server/modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default applyBaseConfig({
},
},
runtime: {
router: true,
router: false,
state: false,
},
});
2 changes: 2 additions & 0 deletions tests/integration/dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"@modern-js/runtime": "workspace:*",
"react": "^18",
"react-dom": "^18",
"react-router": "^6",
"react-router-dom": "^6",
"fs-extra": "^10.1.0"
},
"devDependencies": {
Expand Down
30 changes: 27 additions & 3 deletions tests/integration/dev-server/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
export default () => {
return <div>Hello World</div>;
};
import { BrowserRouter, Link, Route, Routes, Outlet } from 'react-router-dom';

const App = () => (
<BrowserRouter>
<Routes>
<Route
path="/"
element={
<div>
home
<div>
<Link to="/a">A</Link>
</div>
<div>
<Link to="/b">B</Link>
</div>
<Outlet />
</div>
}
/>
<Route path="/a" element={<div>A</div>} />
<Route path="/b" element={<div>B</div>} />
</Routes>
</BrowserRouter>
);

export default App;
11 changes: 11 additions & 0 deletions tests/integration/dev-server/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ describe('dev', () => {
expect(headers['x-plugin']).toBe('test-plugin');
});

test('should provide history api fallback correctly', async () => {
await page.goto(`http://localhost:${appPort}`);
expect(await page.content()).toContain('<div>home<div>');

await page.goto(`http://localhost:${appPort}/a`);
expect(await page.content()).toContain('<div>A</div>');

await page.goto(`http://localhost:${appPort}/b`);
expect(await page.content()).toContain('<div>B</div>');
});

afterAll(async () => {
await killApp(app);
await page.close();
Expand Down

0 comments on commit 6b3f453

Please sign in to comment.