Skip to content
Open
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
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ node_modules
dist
types
.idea
.DS_Store
.DS_Store

# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
3 changes: 0 additions & 3 deletions example/src/pages/home2/App.vue

This file was deleted.

4 changes: 0 additions & 4 deletions example/src/pages/home2/index.js

This file was deleted.

77 changes: 18 additions & 59 deletions example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import color from 'picocolors';
import { createMpaPlugin, createPages } from '../src/index';

const base = '/'; // You can change whatever you want
Expand Down Expand Up @@ -36,18 +37,18 @@ const pages = createPages([
},
{
name: 'home',
filename: 'fruits/home.html',
filename: 'index.html',
entry: '/src/pages/home/index.js',
data: {
title: 'This is Home page',
},
},
{
name: 'home2',
filename: 'fruits/home2.html',
entry: '/src/pages/home2/index.js',
name: 'some-test-url',
filename: 'index.html',
entry: '/src/pages/home/index.js',
data: {
title: 'This is Home2 page',
title: 'This is Home page',
},
},
]);
Expand All @@ -60,61 +61,7 @@ export default defineConfig({
vueJsx(),
createMpaPlugin({
template: 'src/template.html',
/**
* You can write directly or use `createPages` function independently outside and then pass it to this field.
* Both of the above can enjoy type hints.
*/
pages,
/**
* The following `scanOptions` configs can replace the `pages` above, but except data injection.
*/
scanOptions: {
scanDirs: 'src/pages',
entryFile: 'index.js',
filename: (name) => `fruits/${name}.html`,
template: '../../template.html',
},
/**
* Use html minimization feature at build time.
*/
htmlMinify: true,
/**
* Customize the history fallback rewrite rules for `dev server`.
* If you config your pages as above, this rewrite rules will be automatically generated.
* Otherwise you should manually write it, which will overwrite the default.
*/
// rewrites: [
// {
// from: new RegExp(
// normalizePath(`/${base}/(apple|banana|strawberries|home2|home)`),
// ),
// to: (ctx) => normalizePath(`/${base}/fruits/${ctx.match[1]}.html`),
// },
// ],
/**
* Customize the history fallback rewrite rules for `preview server`.
* This option is almost the same with `rewrites`.
*/
previewRewrites: [
// If there's no index.html, you need to manually set rules for history fallback like:
{ from: /.*/, to: '/home.html' },
],
/**
* Sometimes you might want to reload `pages` config or restart ViteDevServer when
* there are some files added, removed, changed and so on. You can set `watchOptions` to
* customize your own logic.
*
* The `include` and `exclude` based on `Rollup.createFilter`
* @see https://vitejs.dev/guide/api-plugin.html#filtering-include-exclude-pattern
*/
watchOptions: {
events: ['add', 'unlink', 'change'],
include: ['**/pages/**', '**/infos/**'],
handler: (ctx) => {
console.log(ctx.type, ctx.file);
// ctx.reloadPages();
},
},
transformHtml(html, ctx) {
return {
html,
Expand All @@ -128,6 +75,18 @@ export default defineConfig({
};
},
}),
// Used to log incoming requests for debugging.
{
name: 'requestLogger',
configurePreviewServer(server) {
server.middlewares.use((req, res, next) => {
console.log(
`[${color.blue('request')}]: ${color.green(req.method)} ${req.url} ${color.yellow(`(Accept: ${req.headers.accept})`)}`,
);
next();
});
},
},
],
build: { sourcemap: true },
server: { port: 5173, open: true },
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"build": "tsup",
"watch": "tsup --watch",
"lint": "eslint . --fix --ext .js,.ts",
"test": "playwright test",
"changeset": "changeset",
"versions": "changeset version"
},
Expand All @@ -63,7 +64,9 @@
"@changesets/cli": "^2.27.7",
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.3",
"@playwright/test": "^1.56.1",
"@types/ejs": "^3.1.5",
"@types/node": "^24.9.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vue/eslint-config-typescript": "^12.0.0",
Expand Down
39 changes: 39 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { defineConfig, devices } from '@playwright/test';

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
retries: 0,
reporter: 'html',

use: {
baseURL: 'http://localhost:5173',
},

projects: [
{
name: 'default',
use: { ...devices['Desktop Chrome'] },
},
],

webServer: {
command: 'cd ./example && pnpm build && pnpm preview',

// This works fine, as there's a base route defined in example/vite.config.ts
// url: 'http://localhost:5173/',

// This is what causes the infinite hang on Playwright. On a browser,
// accessing this URL causes a reroute to `/`, which returns a response.
// When Playwright attempts to hit this URL with an `Accept: */*` header,
// no rewrite takes place and the server never connects.
url: 'http://localhost:5173/some-test-url',
Comment on lines +30 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what causes the break, hitting the root URL directly seems to be fine.


// This is only here for debugging purposes.
stdout: 'pipe',
},
});
Loading