nuxt-spec 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/spec-setup.js +2 -2
- package/{app/utils/vitest-config.ts → config/index.mjs} +10 -0
- package/config/vitest.config.ts.template +5 -0
- package/package.json +13 -1
- package/.gitattributes +0 -2
- package/.vscode/settings.json +0 -9
- package/CHANGELOG.md +0 -27
- package/eslint.config.mjs +0 -37
- package/test/e2e/nuxt-e2e.test.ts +0 -21
- package/test/nuxt/nuxt-unit.test.ts +0 -28
- package/test/unit/vitest.test.ts +0 -5
- package/tsconfig.json +0 -7
- package/vitest.config.ts +0 -8
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Aside from being "forked" and used as you seem fit, `nuxt-spec` is also availabl
|
|
|
14
14
|
|
|
15
15
|
1) Add following dependency into your `package.json`:
|
|
16
16
|
```
|
|
17
|
-
"nuxt-spec": "0.1.
|
|
17
|
+
"nuxt-spec": "0.1.4"
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
2) Add following section into your `nuxt.config.ts`:
|
|
@@ -79,12 +79,12 @@ See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/main/CHANGELOG.
|
|
|
79
79
|
|
|
80
80
|
## Configuration
|
|
81
81
|
|
|
82
|
-
By default, `nuxt-spec` uses Vitest configuration defined in [`/
|
|
82
|
+
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/main/config/index.mjs). The configuration is based on [Nuxt team recommendations](https://nuxt.com/docs/4.x/getting-started/testing) and our best judgement.
|
|
83
83
|
|
|
84
|
-
To add/override your custom config, you can create a file named `vitest.config.ts` in the root of your project with the following content:
|
|
84
|
+
To add/override your custom config, you can create (or scaffold via CLI tool) a file named `vitest.config.ts` in the root of your project with the following content:
|
|
85
85
|
|
|
86
86
|
```ts
|
|
87
|
-
import { loadVitestConfig } from '
|
|
87
|
+
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
88
88
|
|
|
89
89
|
export default loadVitestConfig({
|
|
90
90
|
// your custom config here
|
package/bin/spec-setup.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// CLI tool to scaffold default `vitest.config.ts` file
|
|
4
4
|
// and to add test-related commands in `package.json`
|
|
@@ -9,7 +9,7 @@ import { updatePackageJsonScripts } from './utils/modify-scripts.js'
|
|
|
9
9
|
|
|
10
10
|
async function main() {
|
|
11
11
|
// 1) create vitest.config.ts
|
|
12
|
-
await createFileFromTemplate('../vitest.config.ts', 'vitest.config.ts')
|
|
12
|
+
await createFileFromTemplate('../config/vitest.config.ts.template', 'vitest.config.ts')
|
|
13
13
|
|
|
14
14
|
// 2) modify scripts in package.json
|
|
15
15
|
await updatePackageJsonScripts({
|
|
@@ -11,6 +11,15 @@ export async function loadVitestConfig(userVitestConfig) {
|
|
|
11
11
|
return defu(userVitestConfig, defineConfig({
|
|
12
12
|
test: {
|
|
13
13
|
projects: [
|
|
14
|
+
// default fallback to catch tests in /test folder
|
|
15
|
+
{
|
|
16
|
+
test: {
|
|
17
|
+
name: 'node',
|
|
18
|
+
include: ['test/*.{test,spec}.ts'],
|
|
19
|
+
environment: 'node',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
// proposed setup for unit and e2e tests
|
|
14
23
|
{
|
|
15
24
|
test: {
|
|
16
25
|
name: 'node',
|
|
@@ -18,6 +27,7 @@ export async function loadVitestConfig(userVitestConfig) {
|
|
|
18
27
|
environment: 'node',
|
|
19
28
|
},
|
|
20
29
|
},
|
|
30
|
+
// proposed setup for Nuxt
|
|
21
31
|
await defineVitestProject({
|
|
22
32
|
test: {
|
|
23
33
|
name: 'nuxt',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-spec",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Test-pack layer for Nuxt Applications",
|
|
5
5
|
"repository": "github:AloisSeckar/nuxt-spec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,6 +9,18 @@
|
|
|
9
9
|
"bin": {
|
|
10
10
|
"spec-setup": "./bin/spec-setup.js"
|
|
11
11
|
},
|
|
12
|
+
"exports": {
|
|
13
|
+
"./config": {
|
|
14
|
+
"import": "./config/index.mjs",
|
|
15
|
+
"default": "./config/index.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"app",
|
|
20
|
+
"bin",
|
|
21
|
+
"config",
|
|
22
|
+
"public"
|
|
23
|
+
],
|
|
12
24
|
"dependencies": {
|
|
13
25
|
"@nuxt/test-utils": "3.19.2",
|
|
14
26
|
"@vue/test-utils": "2.4.6",
|
package/.gitattributes
DELETED
package/.vscode/settings.json
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
Overview of the newest features in Nuxt Spec.
|
|
4
|
-
|
|
5
|
-
## 0.1.2
|
|
6
|
-
|
|
7
|
-
**2025-08-09**
|
|
8
|
-
|
|
9
|
-
- fix: target path for scaffolded `vitest.config.ts` (#3)
|
|
10
|
-
|
|
11
|
-
## 0.1.1
|
|
12
|
-
|
|
13
|
-
**2025-08-09**
|
|
14
|
-
|
|
15
|
-
- feat: CLI tool for scaffolding `vitest.config.ts` and test-related scripts in `package.json`
|
|
16
|
-
- docs: added `CHANGELOG.md` and fixed link to `playwright-core`
|
|
17
|
-
|
|
18
|
-
## 0.1.0
|
|
19
|
-
|
|
20
|
-
**2025-08-08**
|
|
21
|
-
|
|
22
|
-
- initial release [v0.1.0](https://github.com/AloisSeckar/nuxt-spec/releases/tag/v0.1.0)
|
|
23
|
-
- key features:
|
|
24
|
-
- Nuxt base layer for testing
|
|
25
|
-
- Nuxt v4 and Vitest v4 compatibility
|
|
26
|
-
- Integrated `vitest`, `@vitest/browser`, `happy-dom`, `playwright-core`, `@vue/test-utils`, `@nuxt/test-utils`
|
|
27
|
-
- Support for custom configuration via `loadVitestConfig` function in `vitest.config.ts`
|
package/eslint.config.mjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import withNuxt from './.nuxt/eslint.config.mjs'
|
|
2
|
-
|
|
3
|
-
// config is being passed as an array of separate objects
|
|
4
|
-
// as suggested here: https://github.com/nuxt/eslint/discussions/413
|
|
5
|
-
|
|
6
|
-
export default withNuxt([
|
|
7
|
-
|
|
8
|
-
// `rules` section can follow, where you can change default eslint behaviour if needed
|
|
9
|
-
// you can adjust or even turn off some rules if you cannot or don't want to satisfy them
|
|
10
|
-
{
|
|
11
|
-
rules: {
|
|
12
|
-
// the default for this rule is "1", but I find it too restrictive
|
|
13
|
-
// https://eslint.vuejs.org/rules/max-attributes-per-line.html
|
|
14
|
-
'vue/max-attributes-per-line': ['error', {
|
|
15
|
-
singleline: {
|
|
16
|
-
max: 4,
|
|
17
|
-
},
|
|
18
|
-
multiline: {
|
|
19
|
-
max: 3,
|
|
20
|
-
},
|
|
21
|
-
}],
|
|
22
|
-
// the default rule forces newline after "else"
|
|
23
|
-
// I prefer using "} else {" on single row
|
|
24
|
-
'vue/html-closing-bracket-newline': [
|
|
25
|
-
'error',
|
|
26
|
-
{
|
|
27
|
-
multiline: 'never',
|
|
28
|
-
selfClosingTag: {
|
|
29
|
-
multiline: 'never',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
'@stylistic/brace-style': 'off',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
])
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { setup, $fetch, createPage, url } from '@nuxt/test-utils/e2e'
|
|
2
|
-
import { describe, expect, test } from 'vitest'
|
|
3
|
-
|
|
4
|
-
describe('NuxtTestComponent E2E test', async () => {
|
|
5
|
-
// setup app.vue in headless browser
|
|
6
|
-
await setup()
|
|
7
|
-
|
|
8
|
-
test('component renders in browser', async () => {
|
|
9
|
-
// fetch for the rendered value
|
|
10
|
-
const html = await $fetch('/')
|
|
11
|
-
expect(html).toContain('Test Component')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('with playwright', async () => {
|
|
15
|
-
// render page in headless browser
|
|
16
|
-
const page = await createPage()
|
|
17
|
-
await page.goto(url('/'), { waitUntil: 'hydration' })
|
|
18
|
-
const hasText = await page.getByText('Test Component').isVisible()
|
|
19
|
-
expect(hasText).toBeTruthy()
|
|
20
|
-
})
|
|
21
|
-
})
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'vitest'
|
|
2
|
-
import { mount } from '@vue/test-utils'
|
|
3
|
-
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
4
|
-
import NuxtTestComponent from '../../app/components/NuxtTestComponent.vue'
|
|
5
|
-
|
|
6
|
-
const text = 'custom-text'
|
|
7
|
-
|
|
8
|
-
describe('NuxtTestComponent', () => {
|
|
9
|
-
test('component mounts and renders text properly', () => {
|
|
10
|
-
const wrapper = mount(NuxtTestComponent, {
|
|
11
|
-
propsData: {
|
|
12
|
-
text,
|
|
13
|
-
},
|
|
14
|
-
})
|
|
15
|
-
expect(wrapper.text()).toContain(text)
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe('NuxtTestComponentSuspended', () => {
|
|
20
|
-
test('component mounts using mountSuspended and renders text properly', async () => {
|
|
21
|
-
const component = await mountSuspended(NuxtTestComponent, {
|
|
22
|
-
props: {
|
|
23
|
-
text,
|
|
24
|
-
},
|
|
25
|
-
})
|
|
26
|
-
expect(component.html()).toContain(text)
|
|
27
|
-
})
|
|
28
|
-
})
|
package/test/unit/vitest.test.ts
DELETED
package/tsconfig.json
DELETED
package/vitest.config.ts
DELETED