nuxt-spec 0.2.4-alpha.4 → 0.2.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 +5 -5
- package/bin/setup.js +9 -9
- package/package.json +1 -1
- package/utils/screenshot/report-utils.ts +11 -0
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ If you don't want to use the CLI tool, or you want to understand its flow better
|
|
|
38
38
|
**1)** - Add following dependency into your `package.json`:
|
|
39
39
|
|
|
40
40
|
```json
|
|
41
|
-
"nuxt-spec": "0.2.4
|
|
41
|
+
"nuxt-spec": "0.2.4"
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
It is advised to remove explicit `nuxt`, `vue` and `vue-router` dependencies, if present. The `nuxt-spec` layer brings them and there might be version clashes if defined in both places.
|
|
@@ -98,7 +98,7 @@ test/
|
|
|
98
98
|
└── vitest-unit.test.ts
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
You can use sample files from the [project repository](https://github.com/AloisSeckar/nuxt-spec/tree/v0.2.4
|
|
101
|
+
You can use sample files from the [project repository](https://github.com/AloisSeckar/nuxt-spec/tree/v0.2.4/test).
|
|
102
102
|
|
|
103
103
|
### Install and execute
|
|
104
104
|
|
|
@@ -263,11 +263,11 @@ Planned future development:
|
|
|
263
263
|
- reason about (not) using Vitest browser mode (or make it optional)
|
|
264
264
|
- solution for visual regression testing - (currently there is experimental custom solution)
|
|
265
265
|
|
|
266
|
-
See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/v0.2.4
|
|
266
|
+
See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/v0.2.4/CHANGELOG.md) for the latest updates and features.
|
|
267
267
|
|
|
268
268
|
## Configuration
|
|
269
269
|
|
|
270
|
-
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/v0.2.4
|
|
270
|
+
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/v0.2.4/config/index.mjs). The configuration is based on [Nuxt team recommendations](https://nuxt.com/docs/4.x/getting-started/testing) and our best judgement.
|
|
271
271
|
|
|
272
272
|
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:
|
|
273
273
|
|
|
@@ -380,7 +380,7 @@ const html: string = await getAPIResultHtml('/', '#api-fetch', '/your-api', '#ap
|
|
|
380
380
|
const html: string = await getAPIResultHtml(page, '#api-fetch', '/your-api', '#api-result')
|
|
381
381
|
```
|
|
382
382
|
|
|
383
|
-
For detailed description, see [utils.d.ts](https://github.com/AloisSeckar/nuxt-spec/blob/v0.2.4
|
|
383
|
+
For detailed description, see [utils.d.ts](https://github.com/AloisSeckar/nuxt-spec/blob/v0.2.4/utils/index.d.ts).
|
|
384
384
|
|
|
385
385
|
The `compareScreenshot` function usage results into HTML report file being automatically created. The file is generated within the specified `__current__` directory as `report_YYYYMMDDHHMMSS.html`. It contains all failed screenshots comparison. When test suite is over, file is attempted to be opened in system default browser (unless Node operates in `CI` mode).
|
|
386
386
|
|
package/bin/setup.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function specSetup(autoRun = false) {
|
|
|
40
40
|
// add nuxt-spec
|
|
41
41
|
try {
|
|
42
42
|
await updateJsonFile('package.json', 'dependencies', {
|
|
43
|
-
'nuxt-spec': '0.2.4
|
|
43
|
+
'nuxt-spec': '0.2.4',
|
|
44
44
|
}, isAutoRun, 'This will add \'nuxt-spec\' dependency to your \'package.json\'. Continue?')
|
|
45
45
|
} catch (error) {
|
|
46
46
|
console.error('Error adding \'nuxt-spec\' dependency:\n', error.message)
|
|
@@ -110,7 +110,7 @@ export async function specSetup(autoRun = false) {
|
|
|
110
110
|
if (pathExists('pnpm-workspace.yaml')) {
|
|
111
111
|
await updateTextFile('pnpm-workspace.yaml', ['shamefully-hoist: true'], isAutoRun, 'This will adjust \'pnpm-workspace.yaml\' file in your project. Continue?')
|
|
112
112
|
} else {
|
|
113
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4
|
|
113
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4/config/templates/pnpm-workspace.yaml.template',
|
|
114
114
|
'pnpm-workspace.yaml', isAutoRun, 'This will add \'pnpm-workspace.yaml\' file for your project. Continue?')
|
|
115
115
|
}
|
|
116
116
|
} catch (error) {
|
|
@@ -120,7 +120,7 @@ export async function specSetup(autoRun = false) {
|
|
|
120
120
|
|
|
121
121
|
// 4) create vitest.config.ts
|
|
122
122
|
try {
|
|
123
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4
|
|
123
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4/config/templates/vitest.config.ts.template',
|
|
124
124
|
'vitest.config.ts', isAutoRun, 'This will create a new \'vitest.config.ts\' file for your project. Continue?')
|
|
125
125
|
} catch (error) {
|
|
126
126
|
console.error('Error setting up \'vitest.config.ts\':\n', error.message)
|
|
@@ -129,7 +129,7 @@ export async function specSetup(autoRun = false) {
|
|
|
129
129
|
// 5) create .nuxtrc to prevent @nuxt/test-utils setup from running automatically on first start
|
|
130
130
|
if (!pathExists('.nuxtrc')) {
|
|
131
131
|
try {
|
|
132
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4
|
|
132
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4/.nuxtrc', '.nuxtrc', isAutoRun, 'This will create a \'.nuxtrc\' file to prevent @nuxt/test-utils setup from running automatically when dev server starts. Continue?')
|
|
133
133
|
} catch (error) {
|
|
134
134
|
console.error('Error creating \'.nuxtrc\':\n', error.message)
|
|
135
135
|
}
|
|
@@ -150,31 +150,31 @@ export async function specSetup(autoRun = false) {
|
|
|
150
150
|
const createSampleTests = isAutoRun || await promptUser('Do you want to create sample tests in \'/test\' folder?')
|
|
151
151
|
if (createSampleTests) {
|
|
152
152
|
try {
|
|
153
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4
|
|
153
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4/test/browser/vitest-browser.test.ts',
|
|
154
154
|
'test/browser/vitest-browser.test.ts', true)
|
|
155
155
|
} catch (error) {
|
|
156
156
|
console.error('Error setting up \'vitest-browser.test.ts\':\n', error.message)
|
|
157
157
|
}
|
|
158
158
|
try {
|
|
159
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4
|
|
159
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4/test/e2e/nuxt-e2e.test.ts',
|
|
160
160
|
'test/e2e/nuxt-e2e.test.ts', true)
|
|
161
161
|
} catch (error) {
|
|
162
162
|
console.error('Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
|
|
163
163
|
}
|
|
164
164
|
try {
|
|
165
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4
|
|
165
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4/test/e2e/nuxt-visual.test.ts',
|
|
166
166
|
'test/e2e/nuxt-visual.test.ts', true)
|
|
167
167
|
} catch (error) {
|
|
168
168
|
console.error('Error setting up \'nuxt-visual.test.ts\':\n', error.message)
|
|
169
169
|
}
|
|
170
170
|
try {
|
|
171
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4
|
|
171
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4/test/nuxt/nuxt-unit.test.ts',
|
|
172
172
|
'test/nuxt/nuxt-unit.test.ts', true)
|
|
173
173
|
} catch (error) {
|
|
174
174
|
console.error('Error setting up \'nuxt-unit.test.ts\':\n', error.message)
|
|
175
175
|
}
|
|
176
176
|
try {
|
|
177
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4
|
|
177
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.4/test/unit/vitest-unit.test.ts',
|
|
178
178
|
'test/unit/vitest-unit.test.ts', true)
|
|
179
179
|
} catch (error) {
|
|
180
180
|
console.error('Error setting up \'vitest-unit.test.ts\':\n', error.message)
|
package/package.json
CHANGED
|
@@ -74,6 +74,7 @@ export function screenshotSetup() {
|
|
|
74
74
|
process.env.SCREENSHOT_REPORT_TIMESTAMP = fileTimestamp
|
|
75
75
|
process.env.SCREENSHOT_REPORT_TITLE = titleTimestamp
|
|
76
76
|
|
|
77
|
+
// callback that is executed upon Vitest teardown phase
|
|
77
78
|
return () => {
|
|
78
79
|
if (!existsSync(REPORT_PATH)) return
|
|
79
80
|
|
|
@@ -83,6 +84,16 @@ export function screenshotSetup() {
|
|
|
83
84
|
if (!reportPath) return
|
|
84
85
|
if (!existsSync(reportPath)) return
|
|
85
86
|
|
|
87
|
+
// add "success" / "error" message as a conclusion
|
|
88
|
+
const reportBody = readFileSync(reportPath, 'utf-8')
|
|
89
|
+
const hasFailure = reportBody.includes('<div class="failure"')
|
|
90
|
+
if (hasFailure) {
|
|
91
|
+
appendFileSync(reportPath, '<p style="color: #b00; font-weight: 700; font-size: 18px;">Tests finished with errors</p>\n')
|
|
92
|
+
} else {
|
|
93
|
+
appendFileSync(reportPath, '<p style="color: #0b0; font-weight: 700; font-size: 18px;">All tests have passed</p>\n')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// wrap the report up with a footer
|
|
86
97
|
let footer = readFileSync(resolve(templatesDir, 'report-tail.html'), 'utf-8')
|
|
87
98
|
footer = footer.replace('{{TIMESTAMP}}', new Date().toISOString())
|
|
88
99
|
appendFileSync(reportPath, footer)
|