nuxt-spec 0.1.13 → 0.1.14
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/cli.js +14 -7
- package/bin/setup.js +9 -6
- package/config/index.d.ts +12 -0
- package/config/{index.ts → index.mjs} +4 -13
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ If you don't want to use the CLI tool, or you want to understand its flow better
|
|
|
36
36
|
1) Add following dependency into your `package.json`:
|
|
37
37
|
|
|
38
38
|
```
|
|
39
|
-
"nuxt-spec": "0.1.
|
|
39
|
+
"nuxt-spec": "0.1.14"
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
2) Add following section into your `nuxt.config.ts`:
|
|
@@ -85,7 +85,7 @@ test/
|
|
|
85
85
|
└── vitest.test.ts
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
You can use sample files from the [project repository](https://github.com/AloisSeckar/nuxt-spec/tree/v0.1.
|
|
88
|
+
You can use sample files from the [project repository](https://github.com/AloisSeckar/nuxt-spec/tree/v0.1.14/test).
|
|
89
89
|
|
|
90
90
|
### Install and execute
|
|
91
91
|
|
|
@@ -244,11 +244,11 @@ Planned future development:
|
|
|
244
244
|
- reason about (not) using Vitest browser mode (or make it optional)
|
|
245
245
|
- solution for visual testing - either [backstopjs](https://www.npmjs.com/package/backstopjs) or Vitest's native (currently experimental)
|
|
246
246
|
|
|
247
|
-
See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.
|
|
247
|
+
See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.14/CHANGELOG.md) for the latest updates and features.
|
|
248
248
|
|
|
249
249
|
## Configuration
|
|
250
250
|
|
|
251
|
-
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.
|
|
251
|
+
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.14/config/index.mjs). The configuration is based on [Nuxt team recommendations](https://nuxt.com/docs/4.x/getting-started/testing) and our best judgement.
|
|
252
252
|
|
|
253
253
|
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:
|
|
254
254
|
|
package/bin/cli.js
CHANGED
|
@@ -17,14 +17,21 @@ const args = process.argv.slice(2);
|
|
|
17
17
|
// execute actions based on first param
|
|
18
18
|
// additional params might be passed into the called functions
|
|
19
19
|
(async () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
let status = 0
|
|
21
|
+
try {
|
|
22
|
+
switch (args[0]) {
|
|
23
|
+
case 'setup':
|
|
24
|
+
await (await import('./setup.js')).specSetup(args[1] || false)
|
|
25
|
+
break
|
|
26
|
+
default:
|
|
27
|
+
console.log(`Usage: \`${getCmd()} nuxt-spec setup [true|false]\``)
|
|
28
|
+
status = 1
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error('Setup failed:', error.message)
|
|
32
|
+
status = 1
|
|
27
33
|
}
|
|
34
|
+
process.exit(status)
|
|
28
35
|
})()
|
|
29
36
|
|
|
30
37
|
// try detecting what package manager was used
|
package/bin/setup.js
CHANGED
|
@@ -37,7 +37,7 @@ export async function specSetup(autoRun = false) {
|
|
|
37
37
|
// add nuxt-spec
|
|
38
38
|
try {
|
|
39
39
|
await updateJsonFile('package.json', 'dependencies', {
|
|
40
|
-
'nuxt-spec': '0.1.
|
|
40
|
+
'nuxt-spec': '0.1.14',
|
|
41
41
|
}, isAutoRun, 'This will add \'nuxt-spec\' dependency to your \'package.json\'. Continue?')
|
|
42
42
|
} catch (error) {
|
|
43
43
|
console.error('Error adding \'nuxt-spec\' dependency:\n', error.message)
|
|
@@ -107,7 +107,7 @@ export async function specSetup(autoRun = false) {
|
|
|
107
107
|
if (pathExists('.npmrc')) {
|
|
108
108
|
await updateTextFile('.npmrc', ['shamefully-hoist=true'], isAutoRun, 'This will adjust \'.npmrc\' file in your project. Continue?')
|
|
109
109
|
} else {
|
|
110
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.
|
|
110
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.14/.npmrc',
|
|
111
111
|
'.npmrc', isAutoRun, 'This will add \'.npmrc\' file for your project. Continue?')
|
|
112
112
|
}
|
|
113
113
|
} catch (error) {
|
|
@@ -117,7 +117,7 @@ export async function specSetup(autoRun = false) {
|
|
|
117
117
|
|
|
118
118
|
// 4) create vitest.config.ts
|
|
119
119
|
try {
|
|
120
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.
|
|
120
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.14/config/vitest.config.ts.template',
|
|
121
121
|
'vitest.config.ts', isAutoRun, 'This will create a new \'vitest.config.ts\' file for your project. Continue?')
|
|
122
122
|
} catch (error) {
|
|
123
123
|
console.error('Error setting up \'vitest.config.ts\':\n', error.message)
|
|
@@ -155,19 +155,19 @@ export async function specSetup(autoRun = false) {
|
|
|
155
155
|
const createSampleTests = isAutoRun || await promptUser('Do you want to create sample tests in \'/test\' folder?')
|
|
156
156
|
if (createSampleTests) {
|
|
157
157
|
try {
|
|
158
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.
|
|
158
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.14/test/e2e/nuxt-e2e.test.ts',
|
|
159
159
|
'test/e2e/nuxt-e2e.test.ts', true)
|
|
160
160
|
} catch (error) {
|
|
161
161
|
console.error('Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
|
|
162
162
|
}
|
|
163
163
|
try {
|
|
164
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.
|
|
164
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.14/test/nuxt/nuxt-unit.test.ts',
|
|
165
165
|
'test/nuxt/nuxt-unit.test.ts', true)
|
|
166
166
|
} catch (error) {
|
|
167
167
|
console.error('Error setting up \'nuxt-unit.test.ts\':\n', error.message)
|
|
168
168
|
}
|
|
169
169
|
try {
|
|
170
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.
|
|
170
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.14/test/unit/vitest.test.ts',
|
|
171
171
|
'test/unit/vitest.test.ts', true)
|
|
172
172
|
} catch (error) {
|
|
173
173
|
console.error('Error setting up \'vitest.test.ts\':\n', error.message)
|
|
@@ -225,4 +225,7 @@ export async function specSetup(autoRun = false) {
|
|
|
225
225
|
showMessage('')
|
|
226
226
|
showMessage('NUXT SPEC SETUP COMPLETE', 2)
|
|
227
227
|
showMessage(`Proceed with \`${packageManager} install\` to get started.`)
|
|
228
|
+
|
|
229
|
+
// force exit to prevent #20
|
|
230
|
+
process.exit(0)
|
|
228
231
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Prepare Vitest configuration object - user config merged with nuxt-spec defaults
|
|
5
|
+
* @param userVitestConfig - custom Vitest config passed from the user
|
|
6
|
+
* @param projects - can be used to suspend the default inclusion of "projects" in Vitest config
|
|
7
|
+
* @returns Promise resolving to defu-merged Vitest configuration
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadVitestConfig(
|
|
10
|
+
userVitestConfig: UserConfig,
|
|
11
|
+
projects?: boolean,
|
|
12
|
+
): Promise<UserConfig>
|
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
// this is the default Vitest config object
|
|
2
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
|
|
3
4
|
|
|
4
5
|
import { defu } from 'defu'
|
|
5
6
|
import { defineConfig } from 'vitest/config'
|
|
6
7
|
import { defineVitestProject } from '@nuxt/test-utils/config'
|
|
7
|
-
import type { UserConfig } from 'vite'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param userVitestConfig - custom Vitest config passed from the user
|
|
12
|
-
* @param projects - can be used to suspend the default inclusion of "projects" in Vitest config
|
|
13
|
-
* @returns Promise resolving to defu-merged Vitest configuration
|
|
14
|
-
*/
|
|
15
|
-
export async function loadVitestConfig(
|
|
16
|
-
userVitestConfig: UserConfig,
|
|
17
|
-
projects: boolean = true,
|
|
18
|
-
): Promise<UserConfig> {
|
|
19
|
-
const baseConfig: UserConfig = {
|
|
9
|
+
export async function loadVitestConfig(userVitestConfig, projects = true) {
|
|
10
|
+
const baseConfig = {
|
|
20
11
|
test: {},
|
|
21
12
|
}
|
|
22
13
|
|
|
23
14
|
if (projects === true) {
|
|
24
|
-
baseConfig.test
|
|
15
|
+
baseConfig.test.projects = [
|
|
25
16
|
// default fallback to catch tests in /test folder
|
|
26
17
|
{
|
|
27
18
|
test: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-spec",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Test-pack layer for Nuxt Applications",
|
|
5
5
|
"repository": "github:AloisSeckar/nuxt-spec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": "./nuxt.config.ts",
|
|
14
14
|
"./config": {
|
|
15
|
-
"types": "./config/index.ts",
|
|
16
|
-
"import": "./config/index.
|
|
17
|
-
"default": "./config/index.
|
|
15
|
+
"types": "./config/index.d.ts",
|
|
16
|
+
"import": "./config/index.mjs",
|
|
17
|
+
"default": "./config/index.mjs"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"files": [
|