@@ -24,68 +24,36 @@ function createConfig() {
24
24
return new WebpackConfig ( runtimeConfig ) ;
25
25
}
26
26
27
- /**
28
- * Some tests are very specific to different operating systems.
29
- * We use this to only run them when needed.
30
- *
31
- * @returns {boolean }
32
- */
33
- function isWindows ( ) {
34
- return process . platform === 'win32' ;
35
- }
27
+ const isWindows = ( process . platform === 'win32' ) ;
36
28
37
29
describe ( 'path-util getContentBase()' , ( ) => {
38
30
describe ( 'getContentBase()' , ( ) => {
39
31
it ( 'contentBase is calculated correctly' , function ( ) {
40
- if ( isWindows ( ) ) {
41
- this . skip ( ) ;
42
- }
43
-
44
32
const config = createConfig ( ) ;
45
33
config . runtimeConfig . useDevServer = true ;
46
34
config . runtimeConfig . devServerUrl = 'http://localhost:8080/' ;
47
- config . outputPath = '/tmp/public/build' ;
35
+ config . outputPath = isWindows ? 'C:\\tmp\\public\\build' : '/tmp/public/build' ;
48
36
config . setPublicPath ( '/build/' ) ;
49
37
config . addEntry ( 'main' , './main' ) ;
50
38
51
39
const actualContentBase = pathUtil . getContentBase ( config ) ;
52
40
// contentBase should point to the "document root", which
53
41
// is calculated as outputPath, but without the publicPath portion
54
- expect ( actualContentBase ) . to . equal ( '/tmp/public' ) ;
42
+ expect ( actualContentBase ) . to . equal ( isWindows ? 'C:\\tmp\\public' : '/tmp/public' ) ;
55
43
} ) ;
56
44
57
45
it ( 'contentBase works ok with manifestKeyPrefix' , function ( ) {
58
- if ( isWindows ( ) ) {
59
- this . skip ( ) ;
60
- }
61
-
62
46
const config = createConfig ( ) ;
63
47
config . runtimeConfig . useDevServer = true ;
64
48
config . runtimeConfig . devServerUrl = 'http://localhost:8080/' ;
65
- config . outputPath = '/tmp/public/build' ;
49
+ config . outputPath = isWindows ? 'C:\\tmp\\public\\build' : '/tmp/public/build' ;
66
50
config . setPublicPath ( '/subdirectory/build' ) ;
67
51
// this "fixes" the incompatibility between outputPath and publicPath
68
52
config . setManifestKeyPrefix ( '/build/' ) ;
69
53
config . addEntry ( 'main' , './main' ) ;
70
54
71
55
const actualContentBase = pathUtil . getContentBase ( config ) ;
72
- expect ( actualContentBase ) . to . equal ( '/tmp/public' ) ;
73
- } ) ;
74
-
75
- it ( 'contentBase is calculated correctly on Windows' , function ( ) {
76
- if ( ! isWindows ( ) ) {
77
- this . skip ( ) ;
78
- }
79
-
80
- const config = createConfig ( ) ;
81
- config . runtimeConfig . useDevServer = true ;
82
- config . runtimeConfig . devServerUrl = 'http://localhost:8080/' ;
83
- config . outputPath = 'C:\\projects\\webpack-encore\\public\\build' ;
84
- config . setPublicPath ( '/build/' ) ;
85
- config . addEntry ( 'main' , './main' ) ;
86
-
87
- const actualContentBase = pathUtil . getContentBase ( config ) ;
88
- expect ( actualContentBase ) . to . equal ( 'C:\\projects\\webpack-encore\\public' ) ;
56
+ expect ( actualContentBase ) . to . equal ( isWindows ? 'C:\\tmp\\public' : '/tmp/public' ) ;
89
57
} ) ;
90
58
} ) ;
91
59
@@ -114,7 +82,8 @@ describe('path-util getContentBase()', () => {
114
82
115
83
it ( 'when outputPath and publicPath are incompatible, manifestKeyPrefix must be set' , ( ) => {
116
84
const config = createConfig ( ) ;
117
- config . outputPath = '/tmp/public/build' ;
85
+
86
+ config . outputPath = isWindows ? 'C:\\tmp\\public\\build' : '/tmp/public/build' ;
118
87
config . addEntry ( 'main' , './main' ) ;
119
88
// pretend we're installed to a subdirectory
120
89
config . setPublicPath ( '/subdirectory/build' ) ;
@@ -126,30 +95,18 @@ describe('path-util getContentBase()', () => {
126
95
} ) ;
127
96
128
97
describe ( 'getRelativeOutputPath' , ( ) => {
129
- it ( 'Works with Unix paths' , function ( ) {
130
- if ( isWindows ( ) ) {
131
- this . skip ( ) ;
132
- }
133
-
98
+ it ( 'basic usage' , function ( ) {
134
99
const config = createConfig ( ) ;
135
- config . runtimeConfig . context = '/tmp/webpack-encore' ;
136
- config . outputPath = '/tmp/webpack-encore/public/build' ;
137
-
138
- const actualPath = pathUtil . getRelativeOutputPath ( config ) ;
139
- expect ( actualPath ) . to . equal ( 'public/build' ) ;
140
- } ) ;
141
-
142
- it ( 'Works with Windows paths' , function ( ) {
143
- if ( ! isWindows ( ) ) {
144
- this . skip ( ) ;
100
+ if ( isWindows ) {
101
+ config . runtimeConfig . context = 'C:\\projects\\webpack-encore' ;
102
+ config . outputPath = 'C:\\projects\\webpack-encore\\public\\build' ;
103
+ } else {
104
+ config . runtimeConfig . context = '/tmp/webpack-encore' ;
105
+ config . outputPath = '/tmp/webpack-encore/public/build' ;
145
106
}
146
107
147
- const config = createConfig ( ) ;
148
- config . runtimeConfig . context = 'C:\\projects\\webpack-encore' ;
149
- config . outputPath = 'C:\\projects\\webpack-encore\\public\\build' ;
150
-
151
108
const actualPath = pathUtil . getRelativeOutputPath ( config ) ;
152
- expect ( actualPath ) . to . equal ( 'public\\build' ) ;
109
+ expect ( actualPath ) . to . equal ( isWindows ? 'public\\build' : 'public/ build') ;
153
110
} ) ;
154
111
} ) ;
155
112
} ) ;
0 commit comments