Skip to content

Commit

Permalink
test: add generate assertion and enable browser
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Dec 18, 2023
1 parent fba662c commit 9451393
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
7 changes: 3 additions & 4 deletions examples/app-jest/test/browser.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ await setup({
describe('browser', () => {
it('runs a test', async () => {
const page = await createPage('/')
const text = await page.getByRole('heading',{ name: 'Welcome to Nuxt!' }).innerText()
expect(text).toContain(
'Welcome to Nuxt!'
)
const text = await page.getByRole('heading', { name: 'Welcome to Nuxt!' }).innerText()
expect(text).toContain('Welcome to Nuxt!')
await page.close()
})
})
1 change: 1 addition & 0 deletions examples/app-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"@nuxt/test-utils": "latest",
"globby": "^14.0.0",
"happy-dom": "^12.10.3",
"typescript": "^5.2.2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ await setup({
browser: true,
})

describe('browser', async () => {
describe('browser', () => {
it('runs a test', async () => {
const page = await createPage('/')
expect(page.getByRole('heading').innerText()).toContain('Welcome to Nuxt!')
const page = await createPage('/')
const text = await page.getByRole('heading', { name: 'Welcome to Nuxt!' }).innerText()
expect(text).toContain('Welcome to Nuxt!')
await page.close()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ await setup({
dev: true,
})

describe('server (dev)', async () => {
describe('server (dev)', () => {
it('runs a test', async () => {
const html = await $fetch('/')
expect(html.slice(0, 15)).toMatchInlineSnapshot(`
Expand Down
25 changes: 25 additions & 0 deletions examples/app-vitest/test/generate.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { fileURLToPath } from 'node:url'
import { resolve } from 'pathe'
import { globby } from 'globby'
import { setup, useTestContext } from '@nuxt/test-utils/e2e'
import { describe, expect, it } from 'vitest'

await setup({
rootDir: fileURLToPath(new URL('../', import.meta.url)),
nuxtConfig: {
nitro: {
prerender: {
routes: ['/test']
}
}
}
})

describe('generate test', () => {
it('can assert files are prerendered', async () => {
const ctx = useTestContext()
const outputDir = resolve(ctx.nuxt!.options.nitro.output?.dir || '', 'public')
const files = await globby(outputDir)
expect(files).toContain(resolve(outputDir, 'test/index.html'))
})
})
2 changes: 1 addition & 1 deletion examples/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "nuxt dev",
"dev:prepare": "nuxt prepare",
"generate": "nuxt generate",
"test": "vitest",
"test": "vitest run",
"preview": "nuxt preview"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9451393

Please sign in to comment.