kit
kit copied to clipboard
Built-in test support per route
Describe the problem
Kit is great and the new routing changes have opened up a world of possibilities. Running tests is still a bit of a hassle. I would love to be able to run tests whenever I change a file inside of a route.
Describe the proposed solution
This is what I have in mind. Add a new file called +tests.ts or +spec.ts that contains something like the following:
import { test, expect } from '@playwright/test';
import { expect as viteExpect, test as viteTest } from 'vitest'
export const playwright = [
test('login', async ({ page }) => {
await page.goto(...)
...
await expect(page).toHaveUrl(...)
}),
test('register', async ({ page }) => {
await page.goto(...)
...
await expect(page).toHaveUrl(...)
}),
]
export const vitest = [
viteTest('Math.sqrt()', () => {
viteExpect(Math.sqrt(4)).toBe(2)
}),
viteTest('Some other test', () => {
...
}),
]
Every time a relevant file in the route changes, these tests should re-run. I don't know if it makes sense to do both unit and E2E tests in the same file like the proposed example here though. Maybe it just makes sense to have the playwright ones since this is also what's in the CLI.
Alternatives considered
Set it all up manually and run the tests manually. Not as fun! 😆
Importance
would make my life easier
Additional Information
No response