-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev-server): supports Bun (#119)
* feat(dev-server): supports Bun * fix the test commanda * fixed ci config * add changeset
- Loading branch information
Showing
10 changed files
with
199 additions
and
7 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,5 @@ | ||
--- | ||
'@hono/vite-dev-server': minor | ||
--- | ||
|
||
feat: supports Bun |
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
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,70 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
test('Should return 200 response', async ({ page }) => { | ||
const response = await page.goto('/') | ||
expect(response?.status()).toBe(200) | ||
|
||
const headers = response?.headers() ?? {} | ||
expect(headers['x-via']).toBe('vite') | ||
|
||
const content = await page.textContent('h1') | ||
expect(content).toBe('Hello Vite!') | ||
}) | ||
|
||
test('Should contain an injected script tag', async ({ page }) => { | ||
await page.goto('/') | ||
|
||
const lastScriptTag = await page.$('script:last-of-type') | ||
expect(lastScriptTag).not.toBeNull() | ||
|
||
const content = await lastScriptTag?.textContent() | ||
expect(content).toBe('import("/@vite/client")') | ||
}) | ||
|
||
test('Should exclude the file specified in the config file', async ({ page }) => { | ||
let response = await page.goto('/file.ts') | ||
expect(response?.status()).toBe(404) | ||
|
||
response = await page.goto('/ends-in-ts') | ||
expect(response?.status()).toBe(200) | ||
|
||
response = await page.goto('/app/foo') | ||
expect(response?.status()).toBe(404) | ||
|
||
response = await page.goto('/favicon.ico') | ||
expect(response?.status()).toBe(404) | ||
|
||
response = await page.goto('/static/foo.png') | ||
expect(response?.status()).toBe(404) | ||
}) | ||
|
||
test('Should return 200 response - /stream', async ({ page }) => { | ||
const response = await page.goto('/stream') | ||
expect(response?.status()).toBe(200) | ||
|
||
const headers = response?.headers() ?? {} | ||
expect(headers['x-via']).toBe('vite') | ||
|
||
const content = await page.textContent('h1') | ||
expect(content).toBe('Hello Vite!') | ||
}) | ||
|
||
test('Should serve static files in `public/static`', async ({ page }) => { | ||
const response = await page.goto('/static/hello.json') | ||
expect(response?.status()).toBe(200) | ||
|
||
const data = await response?.json() | ||
expect(data['message']).toBe('Hello') | ||
}) | ||
|
||
test('Should return a vite error page - /invalid-response', async ({ page }) => { | ||
const response = await page.goto('/invalid-response') | ||
expect(response?.status()).toBe(500) | ||
expect(await response?.text()).toContain('ErrorOverlay') | ||
}) | ||
|
||
test('Should set `workerd` as a runtime key', async ({ page }) => { | ||
const res = await page.goto('/runtime') | ||
expect(res?.ok()).toBe(true) | ||
expect(await res?.text()).toBe('bun') | ||
}) |
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,62 @@ | ||
import { Hono } from 'hono' | ||
import { getRuntimeKey } from 'hono/adapter' | ||
|
||
const app = new Hono() | ||
|
||
app.get('/', (c) => { | ||
c.header('x-via', 'vite') | ||
return c.html('<h1>Hello Vite!</h1>') | ||
}) | ||
|
||
app.get('/file.ts', (c) => { | ||
return c.text('console.log("exclude me!")') | ||
}) | ||
|
||
app.get('/app/foo', (c) => { | ||
return c.html('<h1>exclude me!</h1>') | ||
}) | ||
|
||
app.get('/ends-in-ts', (c) => { | ||
return c.text('this should not be excluded') | ||
}) | ||
|
||
app.get('/favicon.ico', (c) => { | ||
return c.text('a good favicon') | ||
}) | ||
|
||
app.get('/static/foo.png', (c) => { | ||
return c.text('a good image') | ||
}) | ||
|
||
app.get('/stream', () => { | ||
const html = new TextEncoder().encode('<h1>Hello Vite!</h1>') | ||
const stream = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(html) | ||
controller.close() | ||
}, | ||
}) | ||
return new Response(stream, { | ||
headers: { 'Content-Type': 'text/html', 'x-via': 'vite' }, | ||
}) | ||
}) | ||
|
||
// @ts-expect-error the response is string | ||
app.get('/invalid-response', () => { | ||
return '<h1>Hello!</h1>' | ||
}) | ||
|
||
app.get('/invalid-error-response', (c) => { | ||
try { | ||
// @ts-expect-error the variable does not exist, intentionally | ||
doesNotExist = true | ||
|
||
return c.html('<h1>Hello Vite!</h1>') | ||
} catch (err) { | ||
return err | ||
} | ||
}) | ||
|
||
app.get('/runtime', (c) => c.text(getRuntimeKey())) | ||
|
||
export default app |
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,24 @@ | ||
import { defineConfig, devices } from '@playwright/test' | ||
|
||
export default defineConfig({ | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 0, | ||
workers: process.env.CI ? 1 : undefined, | ||
use: { | ||
baseURL: 'http://localhost:6173', | ||
}, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
timeout: 5000, | ||
retries: 2, | ||
}, | ||
], | ||
webServer: { | ||
command: 'bun --bun vite --port 6173 -c ./vite.config.ts', | ||
port: 6173, | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}) |
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,3 @@ | ||
{ | ||
"message": "Hello" | ||
} |
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 @@ | ||
import { defineConfig } from 'vite' | ||
import devServer, { defaultOptions } from '../src' | ||
|
||
export default defineConfig(async () => { | ||
return { | ||
plugins: [ | ||
devServer({ | ||
entry: './mock/app.ts', | ||
exclude: [...defaultOptions.exclude, '/app/**'], | ||
}), | ||
], | ||
} | ||
}) |
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
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
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