|
| 1 | +import { candidate, css, fetchStyles, json, retryAssertion, test, ts } from '../utils' |
| 2 | + |
| 3 | +test( |
| 4 | + 'dev mode', |
| 5 | + { |
| 6 | + fs: { |
| 7 | + 'package.json': json` |
| 8 | + { |
| 9 | + "type": "module", |
| 10 | + "dependencies": { |
| 11 | + "@builder.io/qwik": "^1", |
| 12 | + "@builder.io/qwik-city": "^1", |
| 13 | + "vite": "^5", |
| 14 | + "@tailwindcss/vite": "workspace:^", |
| 15 | + "tailwindcss": "workspace:^" |
| 16 | + } |
| 17 | + } |
| 18 | + `, |
| 19 | + 'vite.config.ts': ts` |
| 20 | + import { defineConfig } from 'vite' |
| 21 | + import { qwikVite } from '@builder.io/qwik/optimizer' |
| 22 | + import { qwikCity } from '@builder.io/qwik-city/vite' |
| 23 | + import tailwindcss from '@tailwindcss/vite' |
| 24 | +
|
| 25 | + export default defineConfig(() => { |
| 26 | + return { |
| 27 | + plugins: [tailwindcss(), qwikCity(), qwikVite()], |
| 28 | + } |
| 29 | + }) |
| 30 | + `, |
| 31 | + 'src/root.tsx': ts` |
| 32 | + import { component$ } from '@builder.io/qwik' |
| 33 | + import { QwikCityProvider, RouterOutlet } from '@builder.io/qwik-city' |
| 34 | +
|
| 35 | + import './global.css' |
| 36 | +
|
| 37 | + export default component$(() => { |
| 38 | + return ( |
| 39 | + <QwikCityProvider> |
| 40 | + <head></head> |
| 41 | + <body> |
| 42 | + <RouterOutlet /> |
| 43 | + </body> |
| 44 | + </QwikCityProvider> |
| 45 | + ) |
| 46 | + }) |
| 47 | + `, |
| 48 | + 'src/global.css': css`@import 'tailwindcss/utilities.css';`, |
| 49 | + 'src/entry.ssr.tsx': ts` |
| 50 | + import { renderToStream, type RenderToStreamOptions } from '@builder.io/qwik/server' |
| 51 | + import Root from './root' |
| 52 | +
|
| 53 | + export default function (opts: RenderToStreamOptions) { |
| 54 | + return renderToStream(<Root />, opts) |
| 55 | + } |
| 56 | + `, |
| 57 | + 'src/routes/index.tsx': ts` |
| 58 | + import { component$ } from '@builder.io/qwik' |
| 59 | +
|
| 60 | + export default component$(() => { |
| 61 | + return <h1 class="underline">Hello World!</h1> |
| 62 | + }) |
| 63 | + `, |
| 64 | + }, |
| 65 | + }, |
| 66 | + async ({ fs, spawn, expect }) => { |
| 67 | + let process = await spawn('pnpm vite --mode ssr') |
| 68 | + await process.onStdout((m) => m.includes('ready in')) |
| 69 | + |
| 70 | + let url = '' |
| 71 | + await process.onStdout((m) => { |
| 72 | + console.log(m) |
| 73 | + let match = /Local:\s*(http.*)\//.exec(m) |
| 74 | + if (match) url = match[1] |
| 75 | + return Boolean(url) |
| 76 | + }) |
| 77 | + |
| 78 | + await retryAssertion(async () => { |
| 79 | + let css = await fetchStyles(url) |
| 80 | + expect(css).toContain(candidate`underline`) |
| 81 | + }) |
| 82 | + |
| 83 | + await retryAssertion(async () => { |
| 84 | + await fs.write( |
| 85 | + 'src/routes/index.tsx', |
| 86 | + ts` |
| 87 | + import { component$ } from '@builder.io/qwik' |
| 88 | +
|
| 89 | + export default component$(() => { |
| 90 | + return <h1 class="underline flex">Hello World!</h1> |
| 91 | + }) |
| 92 | + `, |
| 93 | + ) |
| 94 | + |
| 95 | + let css = await fetchStyles(url) |
| 96 | + expect(css).toContain(candidate`underline`) |
| 97 | + expect(css).toContain(candidate`flex`) |
| 98 | + }) |
| 99 | + }, |
| 100 | +) |
0 commit comments