Skip to content

Commit 8951ecc

Browse files
committed
feat: added lit support to browser creator
1 parent 1474620 commit 8951ecc

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

packages/vitest/src/create/browser/creator.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function getFramework(): prompt.Choice[] {
8484
value: 'react',
8585
description: '"The library for web and native user interfaces"',
8686
},
87+
{
88+
title: 'lit',
89+
value: 'lit',
90+
description: '"A simple library for building fast, lightweight web components."',
91+
},
8792
{
8893
title: 'preact',
8994
value: 'preact',
@@ -112,6 +117,8 @@ function getFrameworkTestPackage(framework: string) {
112117
return 'vitest-browser-svelte'
113118
case 'react':
114119
return 'vitest-browser-react'
120+
case 'lit':
121+
return 'vitest-browser-lit'
115122
case 'preact':
116123
return '@testing-library/preact'
117124
case 'solid':
@@ -205,6 +212,9 @@ function getPossibleFramework(dependencies: Record<string, string>) {
205212
if (dependencies.svelte || dependencies['@sveltejs/kit']) {
206213
return 'svelte'
207214
}
215+
if (dependencies.lit || dependencies['lit-html']) {
216+
return 'lit'
217+
}
208218
if (dependencies.preact) {
209219
return 'preact'
210220
}

packages/vitest/src/create/browser/examples.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,62 @@ test('renders name', async () => {
135135
`,
136136
}
137137

138+
const litExample = {
139+
name: 'HelloWorld.js',
140+
js: `
141+
import { html, LitElement } from 'lit'
142+
143+
export class HelloWorld extends LitElement {
144+
static properties = {
145+
name: { type: String },
146+
}
147+
148+
constructor() {
149+
super()
150+
this.name = 'World'
151+
}
152+
153+
render() {
154+
return html\`<h1>Hello \${this.name}!</h1>\`
155+
}
156+
}
157+
158+
customElements.define('hello-world', HelloWorld)
159+
`,
160+
ts: `
161+
import { html, LitElement } from 'lit'
162+
import { customElement, property } from 'lit/decorators.js'
163+
164+
@customElement('hello-world')
165+
export class HelloWorld extends LitElement {
166+
@property({ type: String })
167+
name = 'World'
168+
169+
render() {
170+
return html\`<h1>Hello \${this.name}!</h1>\`
171+
}
172+
}
173+
174+
declare global {
175+
interface HTMLElementTagNameMap {
176+
'hello-world': HelloWorld
177+
}
178+
}
179+
`,
180+
test: `
181+
import { expect, test } from 'vitest'
182+
import { render } from 'vitest-browser-lit'
183+
import { html } from 'lit'
184+
import './HelloWorld.js'
185+
186+
test('renders name', async () => {
187+
const screen = render(html\`<hello-world name="Vitest"></hello-world>\`)
188+
const element = screen.getByText('Hello Vitest!')
189+
expect(element).toBeInTheDocument()
190+
})
191+
`,
192+
}
193+
138194
const vanillaExample = {
139195
name: 'HelloWorld.js',
140196
js: `
@@ -191,6 +247,8 @@ function getExampleTest(framework: string) {
191247
return vueExample
192248
case 'svelte':
193249
return svelteExample
250+
case 'lit':
251+
return litExample
194252
case 'marko':
195253
return markoExample
196254
default:

0 commit comments

Comments
 (0)