Skip to content
Merged
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
34 changes: 30 additions & 4 deletions packages/vitest/src/create/browser/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ function getFramework(): prompt.Choice[] {
value: 'marko',
description: '"A declarative, HTML-based language that makes building web apps fun"',
},
{
title: 'qwik',
value: 'qwik',
description: '"Instantly interactive web apps at scale"',
},
]
}

Expand All @@ -125,6 +130,8 @@ function getFrameworkTestPackage(framework: string) {
return '@solidjs/testing-library'
case 'marko':
return '@marko/testing-library'
case 'qwik':
return 'vitest-browser-qwik'
}
throw new Error(`Unsupported framework: ${framework}`)
}
Expand All @@ -143,6 +150,8 @@ function getFrameworkPluginPackage(framework: string) {
return 'vite-plugin-solid'
case 'marko':
return '@marko/vite'
case 'qwik':
return '@builder.io/qwik/optimizer'
}
return null
}
Expand Down Expand Up @@ -224,6 +233,9 @@ function getPossibleFramework(dependencies: Record<string, string>) {
if (dependencies.marko) {
return 'marko'
}
if (dependencies['@builder.io/qwik'] || dependencies['@qwik.dev/core']) {
return 'qwik'
}
return 'vanilla'
}

Expand Down Expand Up @@ -257,22 +269,36 @@ function fail() {
process.exitCode = 1
}

function getFrameworkImportInfo(framework: string) {
switch (framework) {
case 'svelte':
return { importName: 'svelte', isNamedExport: true }
case 'qwik':
return { importName: 'qwikVite', isNamedExport: true }
default:
return { importName: framework, isNamedExport: false }
}
}

async function generateFrameworkConfigFile(options: {
configPath: string
framework: string
frameworkPlugin: string | null
provider: string
browsers: string[]
}) {
const frameworkImport = options.framework === 'svelte'
? `import { svelte } from '${options.frameworkPlugin}'`
: `import ${options.framework} from '${options.frameworkPlugin}'`
const { importName, isNamedExport } = getFrameworkImportInfo(options.framework)

const frameworkImport = isNamedExport
? `import { ${importName} } from '${options.frameworkPlugin}'`
: `import ${importName} from '${options.frameworkPlugin}'`

const configContent = [
`import { defineConfig } from 'vitest/config'`,
options.frameworkPlugin ? frameworkImport : null,
``,
'export default defineConfig({',
options.frameworkPlugin ? ` plugins: [${options.framework}()],` : null,
options.frameworkPlugin ? ` plugins: [${importName}()],` : null,
` test: {`,
` browser: {`,
` enabled: true,`,
Expand Down
38 changes: 38 additions & 0 deletions packages/vitest/src/create/browser/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,42 @@ test('renders name', async () => {
`,
}

const qwikExample = {
name: 'HelloWorld.jsx',
js: `
import { component$ } from '@builder.io/qwik'
export default component$(({ name }) => {
return (
<div>
<h1>Hello {name}!</h1>
</div>
)
})
`,
ts: `
import { component$ } from '@builder.io/qwik'
export default component$(({ name }: { name: string }) => {
return (
<div>
<h1>Hello {name}!</h1>
</div>
)
})
`,
test: `
import { expect, test } from 'vitest'
import { render } from 'vitest-browser-qwik'
import HelloWorld from './HelloWorld.tsx'
test('renders name', async () => {
const { getByText } = render(<HelloWorld name="Vitest" />)
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
})
`,
}

const vanillaExample = {
name: 'HelloWorld.js',
js: `
Expand Down Expand Up @@ -251,6 +287,8 @@ function getExampleTest(framework: string) {
return litExample
case 'marko':
return markoExample
case 'qwik':
return qwikExample
default:
return vanillaExample
}
Expand Down
Loading