@@ -33,11 +33,18 @@ describe('webpack-batteries-included-preprocessor', () => {
33
33
34
34
context ( '#getTSCompilerOptionsForUser' , ( ) => {
35
35
const mockTsconfigPath = '/path/to/tsconfig.json'
36
+ let readFileTsConfigMock
36
37
let preprocessor
38
+ let readFileTsConfigStub
39
+ let webpackOptions
37
40
38
41
beforeEach ( ( ) => {
39
42
const tsConfigPathSpy = sinon . spy ( )
40
43
44
+ readFileTsConfigMock = ( ) => {
45
+ throw new Error ( 'Could not read file!' )
46
+ }
47
+
41
48
mock ( 'tsconfig-paths-webpack-plugin' , tsConfigPathSpy )
42
49
mock ( '@cypress/webpack-preprocessor' , ( options ) => {
43
50
return ( file ) => undefined
@@ -48,16 +55,14 @@ describe('webpack-batteries-included-preprocessor', () => {
48
55
sinon . stub ( tsconfig , 'findSync' ) . callsFake ( ( ) => mockTsconfigPath )
49
56
50
57
preprocessor = require ( '../../index' )
51
- } )
52
58
53
- afterEach ( ( ) => {
54
- // Remove the mock
55
- mock . stop ( 'tsconfig-paths-webpack-plugin' )
56
- mock . stop ( '@cypress/webpack-preprocessor' )
57
- } )
59
+ const fs = require ( 'fs-extra' )
58
60
59
- it ( 'always returns compilerOptions even if there is an error discovering the user\'s tsconfig.json' , ( ) => {
60
- const webpackOptions = {
61
+ readFileTsConfigStub = sinon . stub ( fs , 'readFileSync' ) . withArgs ( mockTsconfigPath , 'utf8' ) . callsFake ( ( ) => {
62
+ return readFileTsConfigMock ( )
63
+ } )
64
+
65
+ webpackOptions = {
61
66
module : {
62
67
rules : [ ] ,
63
68
} ,
@@ -66,17 +71,26 @@ describe('webpack-batteries-included-preprocessor', () => {
66
71
plugins : [ ] ,
67
72
} ,
68
73
}
74
+ } )
75
+
76
+ afterEach ( ( ) => {
77
+ // Remove the mock
78
+ mock . stop ( 'tsconfig-paths-webpack-plugin' )
79
+ mock . stop ( '@cypress/webpack-preprocessor' )
80
+ } )
81
+
82
+ it ( 'always returns compilerOptions even if there is an error discovering the user\'s tsconfig.json' , ( ) => {
69
83
const preprocessorCB = preprocessor ( {
70
84
typescript : true ,
71
85
webpackOptions,
72
86
} )
73
87
74
- // will not be able to find the user's tsconfig
75
88
preprocessorCB ( {
76
89
filePath : 'foo.ts' ,
77
90
outputPath : '.js' ,
78
91
} )
79
92
93
+ sinon . assert . calledOnce ( readFileTsConfigStub )
80
94
const tsLoader = webpackOptions . module . rules [ 0 ] . use [ 0 ]
81
95
82
96
expect ( tsLoader . loader ) . to . contain ( 'ts-loader' )
@@ -95,8 +109,6 @@ describe('webpack-batteries-included-preprocessor', () => {
95
109
} )
96
110
97
111
it ( 'turns inlineSourceMaps on by default even if none are configured' , ( ) => {
98
- const fs = require ( 'fs-extra' )
99
-
100
112
// make json5 compat schema
101
113
const mockTsConfig = `{
102
114
"compilerOptions": {
@@ -105,19 +117,8 @@ describe('webpack-batteries-included-preprocessor', () => {
105
117
}
106
118
}`
107
119
108
- const readFileTsConfigStub = sinon . stub ( fs , 'readFileSync' ) . withArgs ( mockTsconfigPath , 'utf8' ) . callsFake ( ( ) => {
109
- return mockTsConfig
110
- } )
120
+ readFileTsConfigMock = ( ) => mockTsConfig
111
121
112
- const webpackOptions = {
113
- module : {
114
- rules : [ ] ,
115
- } ,
116
- resolve : {
117
- extensions : [ ] ,
118
- plugins : [ ] ,
119
- } ,
120
- }
121
122
const preprocessorCB = preprocessor ( {
122
123
typescript : true ,
123
124
webpackOptions,
@@ -142,8 +143,6 @@ describe('webpack-batteries-included-preprocessor', () => {
142
143
} )
143
144
144
145
it ( 'turns on sourceMaps and disables inlineSourceMap and inlineSources if the sourceMap configuration option is set by the user' , ( ) => {
145
- const fs = require ( 'fs-extra' )
146
-
147
146
// make json5 compat schema
148
147
const mockTsConfig = `{
149
148
"compilerOptions": {
@@ -152,19 +151,8 @@ describe('webpack-batteries-included-preprocessor', () => {
152
151
}
153
152
}`
154
153
155
- const readFileTsConfigStub = sinon . stub ( fs , 'readFileSync' ) . withArgs ( mockTsconfigPath , 'utf8' ) . callsFake ( ( ) => {
156
- return mockTsConfig
157
- } )
154
+ readFileTsConfigMock = ( ) => mockTsConfig
158
155
159
- const webpackOptions = {
160
- module : {
161
- rules : [ ] ,
162
- } ,
163
- resolve : {
164
- extensions : [ ] ,
165
- plugins : [ ] ,
166
- } ,
167
- }
168
156
const preprocessorCB = preprocessor ( {
169
157
typescript : true ,
170
158
webpackOptions,
0 commit comments