1
1
const path = require ( 'path' ) ;
2
2
const fs = require ( 'fs' ) ;
3
- const vite = require ( './vite.js' ) ;
4
3
const getPort = require ( 'get-port' ) ;
5
-
4
+ const vite = require ( './vite.js' ) ;
6
5
const vite_dev_server = {
7
6
port : process . argv . includes ( '--test-worker' ) ? null : 5173
8
7
} ;
@@ -13,18 +12,21 @@ try {
13
12
//
14
13
}
15
14
16
-
17
15
const projectJsConfigFile = path . join ( process . cwd ( ) , 'vite.config.js' ) ;
18
16
const projectTsConfigFile = path . join ( process . cwd ( ) , 'vite.config.ts' ) ;
19
17
20
- const hasProjectJsConfigFile = ( ) => {
18
+ const hasProjectConfigFile = ( ) => {
21
19
try {
22
20
if ( fs . statSync ( projectJsConfigFile ) . isFile ( ) ) {
23
21
return projectJsConfigFile ;
24
22
}
25
23
} catch ( err ) {
26
- if ( fs . statSync ( projectTsConfigFile ) . isFile ( ) ) {
27
- return projectTsConfigFile ;
24
+ try {
25
+ if ( fs . statSync ( projectTsConfigFile ) . isFile ( ) ) {
26
+ return projectTsConfigFile ;
27
+ }
28
+ } catch ( err ) {
29
+ // nothing
28
30
}
29
31
30
32
return false ;
@@ -35,18 +37,26 @@ module.exports = async function() {
35
37
const viteConfig = {
36
38
port : vite_dev_server . port
37
39
} ;
38
-
40
+
39
41
if ( ! viteConfig . port ) {
40
42
viteConfig . port = await getPort ( ) ;
41
43
}
42
- const projectConfigFile = hasProjectJsConfigFile ( ) ;
43
- viteConfig . configFile = projectConfigFile ? projectConfigFile : path . join ( __dirname , '../vite.config.js' ) ;
44
-
44
+
45
+ const projectConfigFile = hasProjectConfigFile ( ) ;
46
+
47
+ let viteConfigFile = path . join ( __dirname , '../vite.config.js' ) ;
48
+ if ( projectConfigFile ) {
49
+ viteConfigFile = projectConfigFile ;
50
+ }
51
+ viteConfig . configFile = viteConfigFile ;
52
+
45
53
const viteServer = await vite . start ( viteConfig ) ;
46
- const nightwatchPlugin = viteServer . middlewares . stack . find ( item => item . route === '/_nightwatch' ) ;
54
+ const nightwatchPlugin = viteServer . middlewares . stack . find ( item => {
55
+ return item . route === '/_nightwatch' ;
56
+ } ) ;
47
57
48
58
if ( ! nightwatchPlugin ) {
49
- const error = new Error ( 'Missing vite-plugin-nightwatch in ' + projectConfigFile ) ;
59
+ const error = new Error ( 'Missing vite-plugin-nightwatch in ' + projectConfigFile ) ;
50
60
const code = `:
51
61
52
62
import nightwatchPlugin from 'vite-plugin-nightwatch'
@@ -60,12 +70,13 @@ module.exports = async function() {
60
70
]
61
71
};
62
72
` ;
63
- error . help = [ 'Please ensure that "vite-nightwatch-plugin" is loaded in your Vite config file ' + code ] ;
73
+ error . help = [ 'Please ensure that "vite-plugin-nightwatch" is loaded in your Vite config file ' + code ] ;
74
+ error . link = 'https://nightwatchjs.org/guide/component-testing/vite-plugin.html' ;
75
+
64
76
throw error ;
65
- }
77
+ }
78
+
66
79
global . viteServer = viteServer ;
67
80
68
81
return viteServer ;
69
82
} ;
70
-
71
-
0 commit comments