-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: migrate and re-enable test suite (#177)
- Loading branch information
Showing
12 changed files
with
401 additions
and
1,293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
typescript.includeWorkspace=true | ||
imports.autoImport=false | ||
sourcemap=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { fileURLToPath } from 'url' | ||
import { setup, $fetch } from '@nuxt/test-utils' | ||
import { describe, it, expect } from 'vitest' | ||
|
||
const fixture = fileURLToPath(new URL('../../playground', import.meta.url)) | ||
|
||
describe('ssr: false, dev mode', async () => { | ||
await setup({ | ||
server: true, | ||
dev: true, | ||
fixture, | ||
nuxtConfig: { ssr: false } | ||
}) | ||
it('renders', async () => { | ||
const html = await $fetch('/') | ||
expect(html).toContain("getItem('nuxt-color-mode')") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { join, resolve } from 'path' | ||
import { fileURLToPath } from 'url' | ||
import { readFile } from 'fs/promises' | ||
import { setup, useTestContext } from '@nuxt/test-utils' | ||
import { describe, it, expect } from 'vitest' | ||
|
||
const fixture = fileURLToPath(new URL('../../playground', import.meta.url)) | ||
|
||
describe('ssr: false, target: static, generated files', async () => { | ||
await setup({ | ||
fixture, | ||
server: false, | ||
nuxtConfig: { | ||
_generate: true, | ||
ssr: false | ||
} | ||
}) | ||
|
||
it('generated file', async () => { | ||
const ctx = useTestContext() | ||
const generateDir = resolve(ctx.nuxt!.options.nitro.output?.dir || '', 'public') | ||
const files = ['index.html', '200.html'] | ||
for (const file of files) { | ||
const contents = await readFile(join(generateDir, file), 'utf-8') | ||
expect(contents).toContain("getItem('nuxt-color-mode')") | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fileURLToPath } from 'url' | ||
import { setup, $fetch } from '@nuxt/test-utils' | ||
import { describe, it, expect } from 'vitest' | ||
|
||
const fixture = fileURLToPath(new URL('../../playground', import.meta.url)) | ||
|
||
describe('ssr: false, target: server, prod mode', async () => { | ||
await setup({ | ||
server: true, | ||
build: true, | ||
fixture, | ||
nuxtConfig: { ssr: false } | ||
}) | ||
|
||
it('render', async () => { | ||
const html = await $fetch('/') | ||
expect(html).toContain("getItem('nuxt-color-mode')") | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { fileURLToPath } from 'url' | ||
import { setup, $fetch } from '@nuxt/test-utils' | ||
import { describe, it, expect } from 'vitest' | ||
|
||
const fixture = fileURLToPath(new URL('../../playground', import.meta.url)) | ||
|
||
describe('ssr: true, dev mode', async () => { | ||
await setup({ | ||
server: true, | ||
dev: true, | ||
fixture | ||
}) | ||
|
||
it('render', async () => { | ||
const html = await $fetch('/') | ||
expect(html).toContain("getItem('nuxt-color-mode')") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { join, resolve } from 'path' | ||
import { fileURLToPath } from 'url' | ||
import { readFile } from 'fs/promises' | ||
import { setup, useTestContext } from '@nuxt/test-utils' | ||
import { describe, it, expect } from 'vitest' | ||
|
||
const fixture = fileURLToPath(new URL('../../playground', import.meta.url)) | ||
|
||
describe('ssr: true, target: static, generated files', async () => { | ||
await setup({ | ||
server: false, | ||
fixture, | ||
nuxtConfig: { | ||
_generate: true | ||
} | ||
}) | ||
|
||
it('generated file', async () => { | ||
const ctx = useTestContext() | ||
const generateDir = resolve(ctx.nuxt!.options.nitro.output?.dir || '', 'public') | ||
const files = ['index.html', '200.html'] | ||
for (const file of files) { | ||
const contents = await readFile(join(generateDir, file), 'utf-8') | ||
expect(contents).toMatch("getItem('nuxt-color-mode')") | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { fileURLToPath } from 'url' | ||
import { setup, $fetch } from '@nuxt/test-utils' | ||
import { describe, it, expect } from 'vitest' | ||
|
||
const fixture = fileURLToPath(new URL('../../playground', import.meta.url)) | ||
|
||
describe('ssr: true, target: server, prod mode', async () => { | ||
await setup({ | ||
server: true, | ||
build: true, | ||
fixture, | ||
nuxtConfig: { ssr: true } | ||
}) | ||
|
||
it('render', async () => { | ||
const html = await $fetch('/') | ||
expect(html).toContain("getItem('nuxt-color-mode')") | ||
}) | ||
}) | ||
|
||
// describe.skip('ssr: true, csp hash on script', async () => { | ||
// await setup({ | ||
// server: true, | ||
// fixture, | ||
// nuxtConfig: { | ||
// // render: { | ||
// // csp: true | ||
// // } | ||
// } | ||
// }) | ||
|
||
// it('csp hash on script', async () => { | ||
// const { headers } = await fetch('/') | ||
// expect(headers.get('content-security-policy')).toContain('sha256-') | ||
// }) | ||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
test: { | ||
coverage: { | ||
reporter: ['text'], | ||
include: ['src'] | ||
} | ||
} | ||
}) |
Oops, something went wrong.