Skip to content

Commit

Permalink
Set up test framework & add basic test (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
vernaillen authored Apr 7, 2024
1 parent 4e3815d commit a62bf39
Show file tree
Hide file tree
Showing 9 changed files with 868 additions and 266 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ playground/schema.graphql
playground/queries/
examples/yoastseo/test-src/queries/
examples/yoastseo/test-src/schema.graphql
tests/fixtures/basic/queries/
tests/fixtures/basic/schema.graphql
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"@nuxt/fonts": "^0.6.1",
"@nuxt/ui-pro": "^1.1.0",
"nuxt": "^3.11.2",
"nuxt-og-image": "3.0.0-rc.50"
"nuxt-og-image": "3.0.0-rc.51"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/eslint-config": "^0.3.1",
"@nuxthq/studio": "^1.0.13",
"eslint": "^8.57.0",
"vue-tsc": "^2.0.10"
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,18 @@
"@graphql-codegen/client-preset": "^4.2.5",
"@graphql-codegen/typescript-operations": "^4.2.0",
"@nuxt/devtools": "^1.1.5",
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/eslint-config": "^0.3.1",
"@nuxt/module-builder": "^0.5.5",
"@nuxt/schema": "^3.11.2",
"@nuxt/test-utils": "^3.12.0",
"@rollup/rollup-linux-arm64-gnu": "^4.14.0",
"@rollup/rollup-linux-arm64-musl": "^4.14.0",
"@types/node": "20.12.4",
"@types/node": "20.12.5",
"@vitest/coverage-v8": "^1.4.0",
"@vue/test-utils": "^2.4.5",
"changelogen": "^0.5.5",
"eslint": "^8.57.0",
"happy-dom": "^14.5.1",
"nuxt": "^3.11.2",
"playwright-core": "^1.43.0",
"typescript": "^5.4.4",
"untyped": "1.4.2",
"vitest": "^1.4.0",
Expand Down
1,055 changes: 810 additions & 245 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions tests/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { $fetch, setup, startServer } from '@nuxt/test-utils/e2e'

describe('ssr', async () => {
await setup({
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
})

it('renders the index page', async () => {
// Get response to a server-rendered page with `$fetch`.
const html = await $fetch('/')
expect(html).toContain('<div>basic <span>original value</span></div>')
})

it('changes runtime config and restarts', async () => {
await startServer({ env: { NUXT_PUBLIC_MY_VALUE: 'overwritten by test!' } })

const html = await $fetch('/')
expect(html).toContain('<div>basic <span>overwritten by test!</span></div>')

await startServer()
const htmlRestored = await $fetch('/')
expect(htmlRestored).toContain('<div>basic <span>original value</span></div>')
})
})
12 changes: 12 additions & 0 deletions tests/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import WPNuxtModule from '../../../src/module'

export default defineNuxtConfig({
runtimeConfig: {
public: {
myValue: 'original value',
},
},
modules: [
WPNuxtModule
]
})
5 changes: 5 additions & 0 deletions tests/fixtures/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"private": true,
"name": "basic",
"type": "module"
}
9 changes: 9 additions & 0 deletions tests/fixtures/basic/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import { useRuntimeConfig } from 'nuxt/app';
const config = useRuntimeConfig();
</script>

<template>
<div>basic <span>{{ config.public.myValue }}</span></div>
</template>
15 changes: 0 additions & 15 deletions vitest.config.mjs

This file was deleted.

0 comments on commit a62bf39

Please sign in to comment.