nuxt-spec 0.4.0-alpha.2 → 0.4.0-alpha.3
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/LICENSE +21 -21
- package/README.md +13 -13
- package/app/app.vue +10 -10
- package/app/components/NuxtSpecApiTestComponent.vue +24 -24
- package/app/components/NuxtSpecTestComponent.vue +9 -9
- package/app/components/index.d.ts +7 -7
- package/app/components/index.ts +2 -2
- package/app/utils/vitest-utils.ts +5 -5
- package/config/index.d.ts +36 -36
- package/config/index.mjs +147 -147
- package/config/report/report-entry.html +6 -6
- package/config/report/report-head.html +34 -34
- package/config/report/report-screenshot.html +8 -8
- package/config/report/report-tail.html +4 -4
- package/config/templates/.github/workflows/ci-test-update.yml.template +105 -105
- package/config/templates/.github/workflows/ci-test-verify.yml.template +68 -68
- package/config/templates/.gitlab/ci/ci-test-update.yml.template +69 -69
- package/config/templates/.gitlab/ci/ci-test-verify.yml.template +41 -41
- package/config/templates/.gitlab-ci.yml.template +6 -6
- package/config/templates/pnpm-workspace.yaml.template +19 -19
- package/config/templates/vitest.config.ts.template +5 -5
- package/config/utils/merge.mjs +43 -43
- package/config/utils/options.d.mts +59 -59
- package/config/utils/options.mjs +116 -116
- package/config/utils/reporter.mjs +409 -409
- package/config/utils/warnings.mjs +38 -38
- package/modules/spec-options.ts +23 -23
- package/nuxt.config.ts +20 -20
- package/package.json +17 -23
- package/utils/e2e.ts +131 -131
- package/utils/helpers/check-params.ts +44 -44
- package/utils/helpers/location-hint.ts +30 -30
- package/utils/helpers/screenshot-utils.ts +27 -27
- package/utils/index.ts +12 -12
- package/utils/playwright.ts +28 -28
- package/utils/screenshot.ts +201 -201
- package/bin/_internal/prepublish-check.js +0 -16
- package/bin/cli.js +0 -53
- package/bin/commands/ci.js +0 -124
- package/bin/commands/setup.js +0 -367
- package/bin/commands/update.js +0 -126
- package/bin/helpers/commands.js +0 -82
- package/bin/helpers/constants.js +0 -8
- package/bin/helpers/git.js +0 -73
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
# MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-present Alois Sečkár
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Alois Sečkár
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Nuxt Spec
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
A _"testing done right"_ Nuxt base layer.
|
|
6
|
-
|
|
7
|
-
## How to use
|
|
8
|
-
|
|
9
|
-
See [ONLINE DOCS](https://nuxt-spec.netlify.app) for all the necessary information.
|
|
10
|
-
|
|
11
|
-
See [CHANGELOG](https://nuxt-spec.netlify.app/3-1-changelog.html) for the full list of changes.
|
|
12
|
-
|
|
13
|
-
See [CONTRIBUTING](https://nuxt-spec.netlify.app/4-1-contributing.html) if you want to help.
|
|
1
|
+
# Nuxt Spec
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
A _"testing done right"_ Nuxt base layer.
|
|
6
|
+
|
|
7
|
+
## How to use
|
|
8
|
+
|
|
9
|
+
See [ONLINE DOCS](https://nuxt-spec.netlify.app) for all the necessary information.
|
|
10
|
+
|
|
11
|
+
See [CHANGELOG](https://nuxt-spec.netlify.app/3-1-changelog.html) for the full list of changes.
|
|
12
|
+
|
|
13
|
+
See [CONTRIBUTING](https://nuxt-spec.netlify.app/4-1-contributing.html) if you want to help.
|
package/app/app.vue
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<NuxtWelcome />
|
|
4
|
-
<div>
|
|
5
|
-
Test-pack layer for <a href="https://nuxt.com/">Nuxt</a> applications
|
|
6
|
-
</div>
|
|
7
|
-
<NuxtSpecTestComponent id="test" text="Test Component" />
|
|
8
|
-
<NuxtSpecApiTestComponent />
|
|
9
|
-
</div>
|
|
10
|
-
</template>
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<NuxtWelcome />
|
|
4
|
+
<div>
|
|
5
|
+
Test-pack layer for <a href="https://nuxt.com/">Nuxt</a> applications
|
|
6
|
+
</div>
|
|
7
|
+
<NuxtSpecTestComponent id="test" text="Test Component" />
|
|
8
|
+
<NuxtSpecApiTestComponent />
|
|
9
|
+
</div>
|
|
10
|
+
</template>
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<h2>API Test</h2>
|
|
4
|
-
<button id="api-fetch" @click="fetchData">
|
|
5
|
-
Fetch Data
|
|
6
|
-
</button>
|
|
7
|
-
<div id="api-result">
|
|
8
|
-
{{ data }}
|
|
9
|
-
</div>
|
|
10
|
-
</div>
|
|
11
|
-
</template>
|
|
12
|
-
|
|
13
|
-
<script setup lang="ts">
|
|
14
|
-
const data = ref('')
|
|
15
|
-
const fetchData = async () => {
|
|
16
|
-
try {
|
|
17
|
-
data.value = await $fetch('https://jsonplaceholder.typicode.com/posts/1')
|
|
18
|
-
console.debug('Fetched data:', data.value)
|
|
19
|
-
} catch (error) {
|
|
20
|
-
data.value = 'Error fetching data'
|
|
21
|
-
console.error('API fetch error:', error)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<h2>API Test</h2>
|
|
4
|
+
<button id="api-fetch" @click="fetchData">
|
|
5
|
+
Fetch Data
|
|
6
|
+
</button>
|
|
7
|
+
<div id="api-result">
|
|
8
|
+
{{ data }}
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
const data = ref('')
|
|
15
|
+
const fetchData = async () => {
|
|
16
|
+
try {
|
|
17
|
+
data.value = await $fetch('https://jsonplaceholder.typicode.com/posts/1')
|
|
18
|
+
console.debug('Fetched data:', data.value)
|
|
19
|
+
} catch (error) {
|
|
20
|
+
data.value = 'Error fetching data'
|
|
21
|
+
console.error('API fetch error:', error)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div data-testid="test-component" style="margin: 1rem 0; padding: 0.5rem; border: 1px solid black;">
|
|
3
|
-
{{ text }}
|
|
4
|
-
</div>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script setup lang="ts">
|
|
8
|
-
defineProps({ text: { type: String, default: 'nuxt-spec' } })
|
|
9
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div data-testid="test-component" style="margin: 1rem 0; padding: 0.5rem; border: 1px solid black;">
|
|
3
|
+
{{ text }}
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
defineProps({ text: { type: String, default: 'nuxt-spec' } })
|
|
9
|
+
</script>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// type hint for tsconfig.nuxt-spec.json
|
|
2
|
-
declare module '*.vue' {
|
|
3
|
-
import type { DefineComponent } from 'vue'
|
|
4
|
-
|
|
5
|
-
const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>
|
|
6
|
-
export default component
|
|
7
|
-
}
|
|
1
|
+
// type hint for tsconfig.nuxt-spec.json
|
|
2
|
+
declare module '*.vue' {
|
|
3
|
+
import type { DefineComponent } from 'vue'
|
|
4
|
+
|
|
5
|
+
const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>
|
|
6
|
+
export default component
|
|
7
|
+
}
|
package/app/components/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as NuxtSpecTestComponent } from './NuxtSpecTestComponent.vue'
|
|
2
|
-
export { default as NuxtSpecApiTestComponent } from './NuxtSpecApiTestComponent.vue'
|
|
1
|
+
export { default as NuxtSpecTestComponent } from './NuxtSpecTestComponent.vue'
|
|
2
|
+
export { default as NuxtSpecApiTestComponent } from './NuxtSpecApiTestComponent.vue'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Element.checkVisibility() is not available in Vitest
|
|
2
|
-
global.Element.prototype.checkVisibility = function () {
|
|
3
|
-
// in tests we always just assume the element is visible
|
|
4
|
-
return true
|
|
5
|
-
}
|
|
1
|
+
// Element.checkVisibility() is not available in Vitest
|
|
2
|
+
global.Element.prototype.checkVisibility = function () {
|
|
3
|
+
// in tests we always just assume the element is visible
|
|
4
|
+
return true
|
|
5
|
+
}
|
package/config/index.d.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import type { UserConfig } from 'vite'
|
|
2
|
-
import type { TestUserConfig } from 'vitest/config'
|
|
3
|
-
|
|
4
|
-
export type { HtmlReportOpenMode, NuxtSpecOptions } from './utils/options.mjs'
|
|
5
|
-
|
|
6
|
-
/** Typed Vite configuration object for tests */
|
|
7
|
-
type ExtendedUserConfig = UserConfig & {
|
|
8
|
-
test?: TestUserConfig
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Allows fine-grained control over default Vitest `projects`.
|
|
13
|
-
*
|
|
14
|
-
* By default, everything is included.
|
|
15
|
-
* If set to `false`, `test.projects` key is not merged at all.
|
|
16
|
-
* If set to object, specific projects can be omitted by setting respective key to `false`.
|
|
17
|
-
*/
|
|
18
|
-
type ProjectsConfig = boolean | {
|
|
19
|
-
default?: boolean
|
|
20
|
-
unit?: boolean
|
|
21
|
-
nuxt?: boolean
|
|
22
|
-
e2e?: boolean
|
|
23
|
-
browser?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Prepare Vitest configuration object - user config merged with nuxt-spec defaults
|
|
28
|
-
* (defaults are adjusted by `spec` key from nuxt.config.ts and NUXT_SPEC_* env variables)
|
|
29
|
-
* @param userVitestConfig - custom Vitest config passed from the user
|
|
30
|
-
* @param projects - allows fine-grained control over default `test.projects` - see `ProjectsConfig` for details
|
|
31
|
-
* @returns Promise resolving to defu-merged Vitest configuration
|
|
32
|
-
*/
|
|
33
|
-
export declare function loadVitestConfig(
|
|
34
|
-
userVitestConfig: ExtendedUserConfig,
|
|
35
|
-
projects?: ProjectsConfig,
|
|
36
|
-
): Promise<ExtendedUserConfig>
|
|
1
|
+
import type { UserConfig } from 'vite'
|
|
2
|
+
import type { TestUserConfig } from 'vitest/config'
|
|
3
|
+
|
|
4
|
+
export type { HtmlReportOpenMode, NuxtSpecOptions } from './utils/options.mjs'
|
|
5
|
+
|
|
6
|
+
/** Typed Vite configuration object for tests */
|
|
7
|
+
type ExtendedUserConfig = UserConfig & {
|
|
8
|
+
test?: TestUserConfig
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Allows fine-grained control over default Vitest `projects`.
|
|
13
|
+
*
|
|
14
|
+
* By default, everything is included.
|
|
15
|
+
* If set to `false`, `test.projects` key is not merged at all.
|
|
16
|
+
* If set to object, specific projects can be omitted by setting respective key to `false`.
|
|
17
|
+
*/
|
|
18
|
+
type ProjectsConfig = boolean | {
|
|
19
|
+
default?: boolean
|
|
20
|
+
unit?: boolean
|
|
21
|
+
nuxt?: boolean
|
|
22
|
+
e2e?: boolean
|
|
23
|
+
browser?: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Prepare Vitest configuration object - user config merged with nuxt-spec defaults
|
|
28
|
+
* (defaults are adjusted by `spec` key from nuxt.config.ts and NUXT_SPEC_* env variables)
|
|
29
|
+
* @param userVitestConfig - custom Vitest config passed from the user
|
|
30
|
+
* @param projects - allows fine-grained control over default `test.projects` - see `ProjectsConfig` for details
|
|
31
|
+
* @returns Promise resolving to defu-merged Vitest configuration
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadVitestConfig(
|
|
34
|
+
userVitestConfig: ExtendedUserConfig,
|
|
35
|
+
projects?: ProjectsConfig,
|
|
36
|
+
): Promise<ExtendedUserConfig>
|
package/config/index.mjs
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
// this is the default Vitest config object
|
|
2
|
-
// based on https://nuxt.com/docs/4.x/getting-started/testing#setup
|
|
3
|
-
// `projects=false` can be used to suspend the default usage of "projects" in Vitest config
|
|
4
|
-
|
|
5
|
-
import { availableParallelism } from 'node:os'
|
|
6
|
-
import { fileURLToPath } from 'node:url'
|
|
7
|
-
import { addMessageFilters, onConsoleLog } from './utils/warnings.mjs' // filter out unnecessary logs
|
|
8
|
-
import { mergeConfig } from './utils/merge.mjs' // defu-based merge function
|
|
9
|
-
import { loadSpecOptions } from './utils/options.mjs' // `spec` key from nuxt.config.ts + NUXT_SPEC_* env variables
|
|
10
|
-
import { nuxtSpecReportPlugin } from './utils/reporter.mjs' // HTML test report
|
|
11
|
-
import { defineConfig } from 'vitest/config'
|
|
12
|
-
import { defineVitestProject } from '@nuxt/test-utils/config'
|
|
13
|
-
import { playwright } from '@vitest/browser-playwright'
|
|
14
|
-
import vue from '@vitejs/plugin-vue'
|
|
15
|
-
|
|
16
|
-
// absolute paths so it works from within the nuxt-ignis package
|
|
17
|
-
const externalPlaywrightSetup = fileURLToPath(new URL('../utils/playwright.ts', import.meta.url))
|
|
18
|
-
|
|
19
|
-
export async function loadVitestConfig(userVitestConfig, projects = true) {
|
|
20
|
-
const { externalPlaywright, htmlReport, messageFilters } = await loadSpecOptions()
|
|
21
|
-
|
|
22
|
-
// extend array of messages that will be filtered out from the output
|
|
23
|
-
// with values passed by the user (if any)
|
|
24
|
-
addMessageFilters(messageFilters)
|
|
25
|
-
|
|
26
|
-
const baseConfig = {
|
|
27
|
-
test: {
|
|
28
|
-
// filter-out unnecessary console logs coming from Vitest
|
|
29
|
-
// when the import is resolved, unnecessary stderr logs are also filtered-out
|
|
30
|
-
// as a side-effect
|
|
31
|
-
onConsoleLog,
|
|
32
|
-
// Vitest defaults to 5 which might be unnecessarily restrictive
|
|
33
|
-
// if the host machine can support more
|
|
34
|
-
maxConcurrency: availableParallelism() / 2,
|
|
35
|
-
// coverage is NOT enabled by default
|
|
36
|
-
// (use `test-c` command or `--coverage` flag)
|
|
37
|
-
// Bun runtime lacks support for the V8 provider
|
|
38
|
-
// (`bun run` without `--bun` still runs Vitest in Node, where V8 works)
|
|
39
|
-
coverage: {
|
|
40
|
-
provider: process.versions.bun ? 'istanbul' : 'v8',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// HTML test report for all projects
|
|
46
|
-
// report is generated unless explicitly disabled
|
|
47
|
-
if (htmlReport.enabled) {
|
|
48
|
-
baseConfig.plugins = [nuxtSpecReportPlugin({ open: htmlReport.open })]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// add proposed projects settings
|
|
52
|
-
// user can control the inclusion via `projects: ProjectsConfig` config object
|
|
53
|
-
// projects are included by default unless explicitly disabled
|
|
54
|
-
if (projects !== false) {
|
|
55
|
-
baseConfig.test.projects = []
|
|
56
|
-
|
|
57
|
-
// default fallback to catch tests directly in /test folder
|
|
58
|
-
if (projects.default !== false) {
|
|
59
|
-
baseConfig.test.projects.push({
|
|
60
|
-
extends: true,
|
|
61
|
-
test: {
|
|
62
|
-
name: 'default',
|
|
63
|
-
include: ['{test,tests}/**/*.{test,spec}.ts', '!test/{browser,e2e,nuxt,unit}/**'],
|
|
64
|
-
environment: 'node',
|
|
65
|
-
},
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// proposed setup for Unit tests
|
|
70
|
-
if (projects.unit !== false) {
|
|
71
|
-
baseConfig.test.projects.push({
|
|
72
|
-
extends: true,
|
|
73
|
-
test: {
|
|
74
|
-
name: 'unit',
|
|
75
|
-
include: ['test/unit/**/*.{test,spec}.ts'],
|
|
76
|
-
environment: 'node',
|
|
77
|
-
},
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// proposed setup for Nuxt component tests
|
|
82
|
-
if (projects.nuxt !== false) {
|
|
83
|
-
baseConfig.test.projects.push(
|
|
84
|
-
await defineVitestProject({
|
|
85
|
-
extends: true,
|
|
86
|
-
test: {
|
|
87
|
-
name: 'nuxt',
|
|
88
|
-
include: ['test/nuxt/**/*.{test,spec}.ts'],
|
|
89
|
-
environment: 'nuxt',
|
|
90
|
-
},
|
|
91
|
-
}),
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// proposed setup for classic E2E tests (node-based, using @nuxt/test-utils)
|
|
96
|
-
if (projects.e2e !== false) {
|
|
97
|
-
baseConfig.test.projects.push({
|
|
98
|
-
extends: true,
|
|
99
|
-
test: {
|
|
100
|
-
name: 'e2e',
|
|
101
|
-
include: ['test/e2e/**/*.{test,spec}.ts'],
|
|
102
|
-
environment: 'node',
|
|
103
|
-
// allows connecting to an external Playwright instance (if configured)
|
|
104
|
-
setupFiles: externalPlaywright ? [externalPlaywrightSetup] : [],
|
|
105
|
-
// setup file will just read the value via `inject()`
|
|
106
|
-
provide: externalPlaywright ? { nuxtSpecExternalPlaywright: externalPlaywright } : {},
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// proposed setup for browser component tests (with Playwright runner)
|
|
112
|
-
if (projects.browser !== false) {
|
|
113
|
-
// allows connecting to an external Playwright instance (if configured)
|
|
114
|
-
const playwrightConfig = {}
|
|
115
|
-
if (externalPlaywright) {
|
|
116
|
-
console.log(`[Nuxt Spec] Using external Playwright instance for browser tests at: ${externalPlaywright}`)
|
|
117
|
-
playwrightConfig.connectOptions = {
|
|
118
|
-
wsEndpoint: externalPlaywright,
|
|
119
|
-
// this allows reaching caller's localhost from within the external Playwright
|
|
120
|
-
exposeNetwork: '<loopback>',
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
baseConfig.test.projects.push({
|
|
124
|
-
extends: true,
|
|
125
|
-
// vue plugin is required for proper imports resolution
|
|
126
|
-
plugins: [vue()],
|
|
127
|
-
test: {
|
|
128
|
-
name: 'browser',
|
|
129
|
-
include: ['test/browser/**/*.{test,spec}.ts'],
|
|
130
|
-
environment: 'node',
|
|
131
|
-
// only chromium browser by default - add others manually if needed
|
|
132
|
-
browser: {
|
|
133
|
-
provider: playwright(playwrightConfig),
|
|
134
|
-
enabled: true,
|
|
135
|
-
headless: true,
|
|
136
|
-
instances: [{
|
|
137
|
-
browser: 'chromium',
|
|
138
|
-
viewport: { width: 1280, height: 720 },
|
|
139
|
-
}],
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return mergeConfig(userVitestConfig, defineConfig(baseConfig))
|
|
147
|
-
}
|
|
1
|
+
// this is the default Vitest config object
|
|
2
|
+
// based on https://nuxt.com/docs/4.x/getting-started/testing#setup
|
|
3
|
+
// `projects=false` can be used to suspend the default usage of "projects" in Vitest config
|
|
4
|
+
|
|
5
|
+
import { availableParallelism } from 'node:os'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { addMessageFilters, onConsoleLog } from './utils/warnings.mjs' // filter out unnecessary logs
|
|
8
|
+
import { mergeConfig } from './utils/merge.mjs' // defu-based merge function
|
|
9
|
+
import { loadSpecOptions } from './utils/options.mjs' // `spec` key from nuxt.config.ts + NUXT_SPEC_* env variables
|
|
10
|
+
import { nuxtSpecReportPlugin } from './utils/reporter.mjs' // HTML test report
|
|
11
|
+
import { defineConfig } from 'vitest/config'
|
|
12
|
+
import { defineVitestProject } from '@nuxt/test-utils/config'
|
|
13
|
+
import { playwright } from '@vitest/browser-playwright'
|
|
14
|
+
import vue from '@vitejs/plugin-vue'
|
|
15
|
+
|
|
16
|
+
// absolute paths so it works from within the nuxt-ignis package
|
|
17
|
+
const externalPlaywrightSetup = fileURLToPath(new URL('../utils/playwright.ts', import.meta.url))
|
|
18
|
+
|
|
19
|
+
export async function loadVitestConfig(userVitestConfig, projects = true) {
|
|
20
|
+
const { externalPlaywright, htmlReport, messageFilters } = await loadSpecOptions()
|
|
21
|
+
|
|
22
|
+
// extend array of messages that will be filtered out from the output
|
|
23
|
+
// with values passed by the user (if any)
|
|
24
|
+
addMessageFilters(messageFilters)
|
|
25
|
+
|
|
26
|
+
const baseConfig = {
|
|
27
|
+
test: {
|
|
28
|
+
// filter-out unnecessary console logs coming from Vitest
|
|
29
|
+
// when the import is resolved, unnecessary stderr logs are also filtered-out
|
|
30
|
+
// as a side-effect
|
|
31
|
+
onConsoleLog,
|
|
32
|
+
// Vitest defaults to 5 which might be unnecessarily restrictive
|
|
33
|
+
// if the host machine can support more
|
|
34
|
+
maxConcurrency: availableParallelism() / 2,
|
|
35
|
+
// coverage is NOT enabled by default
|
|
36
|
+
// (use `test-c` command or `--coverage` flag)
|
|
37
|
+
// Bun runtime lacks support for the V8 provider
|
|
38
|
+
// (`bun run` without `--bun` still runs Vitest in Node, where V8 works)
|
|
39
|
+
coverage: {
|
|
40
|
+
provider: process.versions.bun ? 'istanbul' : 'v8',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// HTML test report for all projects
|
|
46
|
+
// report is generated unless explicitly disabled
|
|
47
|
+
if (htmlReport.enabled) {
|
|
48
|
+
baseConfig.plugins = [nuxtSpecReportPlugin({ open: htmlReport.open })]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// add proposed projects settings
|
|
52
|
+
// user can control the inclusion via `projects: ProjectsConfig` config object
|
|
53
|
+
// projects are included by default unless explicitly disabled
|
|
54
|
+
if (projects !== false) {
|
|
55
|
+
baseConfig.test.projects = []
|
|
56
|
+
|
|
57
|
+
// default fallback to catch tests directly in /test folder
|
|
58
|
+
if (projects.default !== false) {
|
|
59
|
+
baseConfig.test.projects.push({
|
|
60
|
+
extends: true,
|
|
61
|
+
test: {
|
|
62
|
+
name: 'default',
|
|
63
|
+
include: ['{test,tests}/**/*.{test,spec}.ts', '!test/{browser,e2e,nuxt,unit}/**'],
|
|
64
|
+
environment: 'node',
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// proposed setup for Unit tests
|
|
70
|
+
if (projects.unit !== false) {
|
|
71
|
+
baseConfig.test.projects.push({
|
|
72
|
+
extends: true,
|
|
73
|
+
test: {
|
|
74
|
+
name: 'unit',
|
|
75
|
+
include: ['test/unit/**/*.{test,spec}.ts'],
|
|
76
|
+
environment: 'node',
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// proposed setup for Nuxt component tests
|
|
82
|
+
if (projects.nuxt !== false) {
|
|
83
|
+
baseConfig.test.projects.push(
|
|
84
|
+
await defineVitestProject({
|
|
85
|
+
extends: true,
|
|
86
|
+
test: {
|
|
87
|
+
name: 'nuxt',
|
|
88
|
+
include: ['test/nuxt/**/*.{test,spec}.ts'],
|
|
89
|
+
environment: 'nuxt',
|
|
90
|
+
},
|
|
91
|
+
}),
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// proposed setup for classic E2E tests (node-based, using @nuxt/test-utils)
|
|
96
|
+
if (projects.e2e !== false) {
|
|
97
|
+
baseConfig.test.projects.push({
|
|
98
|
+
extends: true,
|
|
99
|
+
test: {
|
|
100
|
+
name: 'e2e',
|
|
101
|
+
include: ['test/e2e/**/*.{test,spec}.ts'],
|
|
102
|
+
environment: 'node',
|
|
103
|
+
// allows connecting to an external Playwright instance (if configured)
|
|
104
|
+
setupFiles: externalPlaywright ? [externalPlaywrightSetup] : [],
|
|
105
|
+
// setup file will just read the value via `inject()`
|
|
106
|
+
provide: externalPlaywright ? { nuxtSpecExternalPlaywright: externalPlaywright } : {},
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// proposed setup for browser component tests (with Playwright runner)
|
|
112
|
+
if (projects.browser !== false) {
|
|
113
|
+
// allows connecting to an external Playwright instance (if configured)
|
|
114
|
+
const playwrightConfig = {}
|
|
115
|
+
if (externalPlaywright) {
|
|
116
|
+
console.log(`[Nuxt Spec] Using external Playwright instance for browser tests at: ${externalPlaywright}`)
|
|
117
|
+
playwrightConfig.connectOptions = {
|
|
118
|
+
wsEndpoint: externalPlaywright,
|
|
119
|
+
// this allows reaching caller's localhost from within the external Playwright
|
|
120
|
+
exposeNetwork: '<loopback>',
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
baseConfig.test.projects.push({
|
|
124
|
+
extends: true,
|
|
125
|
+
// vue plugin is required for proper imports resolution
|
|
126
|
+
plugins: [vue()],
|
|
127
|
+
test: {
|
|
128
|
+
name: 'browser',
|
|
129
|
+
include: ['test/browser/**/*.{test,spec}.ts'],
|
|
130
|
+
environment: 'node',
|
|
131
|
+
// only chromium browser by default - add others manually if needed
|
|
132
|
+
browser: {
|
|
133
|
+
provider: playwright(playwrightConfig),
|
|
134
|
+
enabled: true,
|
|
135
|
+
headless: true,
|
|
136
|
+
instances: [{
|
|
137
|
+
browser: 'chromium',
|
|
138
|
+
viewport: { width: 1280, height: 720 },
|
|
139
|
+
}],
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return mergeConfig(userVitestConfig, defineConfig(baseConfig))
|
|
147
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<div class="failure">
|
|
2
|
-
<h2>{{TITLE}}</h2>
|
|
3
|
-
<p class="location">{{LOCATION}}</p>
|
|
4
|
-
{{ERRORS}}
|
|
5
|
-
{{SCREENSHOTS}}
|
|
6
|
-
</div>
|
|
1
|
+
<div class="failure">
|
|
2
|
+
<h2>{{TITLE}}</h2>
|
|
3
|
+
<p class="location">{{LOCATION}}</p>
|
|
4
|
+
{{ERRORS}}
|
|
5
|
+
{{SCREENSHOTS}}
|
|
6
|
+
</div>
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>Nuxt Spec Test Report - {{TIMESTAMP}}</title>
|
|
6
|
-
<style>
|
|
7
|
-
body { font-family: system-ui, sans-serif; margin: 2rem; background: #f5f5f5; color: #222; }
|
|
8
|
-
h1 { font-size: 1.4rem; }
|
|
9
|
-
.summary { font-weight: 700; font-size: 18px; }
|
|
10
|
-
.summary.passed { color: #0b0; }
|
|
11
|
-
.summary.failed { color: #b00; }
|
|
12
|
-
.failure { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 1rem; margin: 1rem 0; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
|
|
13
|
-
.failure h2 { font-size: 1rem; margin: 0 0 .25rem; }
|
|
14
|
-
.failure .location { color: #666; font-size: .8rem; margin: 0 0 .75rem; }
|
|
15
|
-
.failure pre { white-space: pre-wrap; word-break: break-word; font-size: .8rem; margin: 0 0 .75rem; padding: .5rem; background: #fafafa; border: 1px solid #eee; border-radius: 4px; }
|
|
16
|
-
.failure pre.message { color: #b00; }
|
|
17
|
-
.failure details summary { cursor: pointer; font-size: .8rem; margin-bottom: .25rem; }
|
|
18
|
-
.screenshot { margin-top: .75rem; }
|
|
19
|
-
.screenshot h3 { font-size: .9rem; margin: 0 0 .25rem; }
|
|
20
|
-
.screenshot .message { color: #b00; font-size: .85rem; margin: 0 0 .75rem; }
|
|
21
|
-
.pair { display: flex; gap: 1rem; flex-wrap: wrap; }
|
|
22
|
-
.pair figure { margin: 0; flex: 1 1 0; min-width: 240px; }
|
|
23
|
-
.pair figcaption { font-size: .8rem; margin-bottom: .25rem; font-weight: bold; }
|
|
24
|
-
.pair figure:first-child figcaption { color: #0b0; }
|
|
25
|
-
.pair figure:last-child figcaption { color: #b00; }
|
|
26
|
-
.pair img { max-width: 100%; background: #fff; }
|
|
27
|
-
.pair figure:first-child img { border: 2px solid #0b0; }
|
|
28
|
-
.pair figure:last-child img { border: 2px solid #b00; }
|
|
29
|
-
</style>
|
|
30
|
-
</head>
|
|
31
|
-
<body>
|
|
32
|
-
<h1>Nuxt Spec Test Report - {{TIMESTAMP}}</h1>
|
|
33
|
-
<p class="summary {{STATUS}}">{{SUMMARY}}</p>
|
|
34
|
-
<!-- BEGIN failure entries -->
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>Nuxt Spec Test Report - {{TIMESTAMP}}</title>
|
|
6
|
+
<style>
|
|
7
|
+
body { font-family: system-ui, sans-serif; margin: 2rem; background: #f5f5f5; color: #222; }
|
|
8
|
+
h1 { font-size: 1.4rem; }
|
|
9
|
+
.summary { font-weight: 700; font-size: 18px; }
|
|
10
|
+
.summary.passed { color: #0b0; }
|
|
11
|
+
.summary.failed { color: #b00; }
|
|
12
|
+
.failure { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 1rem; margin: 1rem 0; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
|
|
13
|
+
.failure h2 { font-size: 1rem; margin: 0 0 .25rem; }
|
|
14
|
+
.failure .location { color: #666; font-size: .8rem; margin: 0 0 .75rem; }
|
|
15
|
+
.failure pre { white-space: pre-wrap; word-break: break-word; font-size: .8rem; margin: 0 0 .75rem; padding: .5rem; background: #fafafa; border: 1px solid #eee; border-radius: 4px; }
|
|
16
|
+
.failure pre.message { color: #b00; }
|
|
17
|
+
.failure details summary { cursor: pointer; font-size: .8rem; margin-bottom: .25rem; }
|
|
18
|
+
.screenshot { margin-top: .75rem; }
|
|
19
|
+
.screenshot h3 { font-size: .9rem; margin: 0 0 .25rem; }
|
|
20
|
+
.screenshot .message { color: #b00; font-size: .85rem; margin: 0 0 .75rem; }
|
|
21
|
+
.pair { display: flex; gap: 1rem; flex-wrap: wrap; }
|
|
22
|
+
.pair figure { margin: 0; flex: 1 1 0; min-width: 240px; }
|
|
23
|
+
.pair figcaption { font-size: .8rem; margin-bottom: .25rem; font-weight: bold; }
|
|
24
|
+
.pair figure:first-child figcaption { color: #0b0; }
|
|
25
|
+
.pair figure:last-child figcaption { color: #b00; }
|
|
26
|
+
.pair img { max-width: 100%; background: #fff; }
|
|
27
|
+
.pair figure:first-child img { border: 2px solid #0b0; }
|
|
28
|
+
.pair figure:last-child img { border: 2px solid #b00; }
|
|
29
|
+
</style>
|
|
30
|
+
</head>
|
|
31
|
+
<body>
|
|
32
|
+
<h1>Nuxt Spec Test Report - {{TIMESTAMP}}</h1>
|
|
33
|
+
<p class="summary {{STATUS}}">{{SUMMARY}}</p>
|
|
34
|
+
<!-- BEGIN failure entries -->
|