File tree Expand file tree Collapse file tree 2 files changed +22
-18
lines changed
npm/webpack-batteries-included-preprocessor Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ const webpackPreprocessor = require('@cypress/webpack-preprocessor')
5
5
6
6
const debug = Debug ( 'cypress:webpack-batteries-included-preprocessor' )
7
7
8
+ class TsConfigNotFoundError extends Error {
9
+ constructor ( ) {
10
+ super ( 'No tsconfig.json found, but typescript is installed. ts-loader needs a tsconfig.json file to work. Please add one to your project in either the root or the cypress directory.' )
11
+ this . name = 'TsConfigNotFoundError'
12
+ }
13
+ }
14
+
8
15
const hasTsLoader = ( rules ) => {
9
16
return rules . some ( ( rule ) => {
10
17
if ( ! rule . use || ! Array . isArray ( rule . use ) ) return false
@@ -40,7 +47,13 @@ const addTypeScriptConfig = (file, options) => {
40
47
// returns null if tsconfig cannot be found in the path/parent hierarchy
41
48
const configFile = getTsConfig . getTsconfig ( file . filePath )
42
49
43
- configFile ? debug ( `found user tsconfig.json at ${ configFile ?. path } with compilerOptions: ${ JSON . stringify ( configFile ?. config ?. compilerOptions ) } ` ) : debug ( 'no user tsconfig.json found' )
50
+ if ( ! configFile && typescriptExtensionRegex . test ( file . filePath ) ) {
51
+ debug ( 'no user tsconfig.json found. Throwing TsConfigNotFoundError' )
52
+ // @see https://github.com/cypress-io/cypress/issues/18938
53
+ throw new TsConfigNotFoundError ( )
54
+ }
55
+
56
+ debug ( `found user tsconfig.json at ${ configFile ?. path } with compilerOptions: ${ JSON . stringify ( configFile ?. config ?. compilerOptions ) } ` )
44
57
45
58
webpackOptions . module . rules . push ( {
46
59
test : / \. t s x ? $ / ,
Original file line number Diff line number Diff line change @@ -104,30 +104,21 @@ describe('webpack-batteries-included-preprocessor', () => {
104
104
} )
105
105
} )
106
106
107
- it ( 'always returns loader options even if there is an error discovering the user\'s tsconfig.json' , ( ) => {
107
+ // @see https://github.com/cypress-io/cypress/issues/18938. ts-loader needs a tsconfig.json file to work.
108
+ it ( 'throws an error if the user\'s tsconfig.json is not found' , ( ) => {
108
109
getTsConfigMock . returns ( null )
109
110
110
111
const preprocessorCB = preprocessor ( {
111
112
typescript : true ,
112
113
webpackOptions,
113
114
} )
114
115
115
- preprocessorCB ( {
116
- filePath : 'foo.ts' ,
117
- outputPath : '.js' ,
118
- } )
119
-
120
- const tsLoader = webpackOptions . module . rules [ 0 ] . use [ 0 ]
121
-
122
- expect ( tsLoader . loader ) . to . contain ( 'ts-loader' )
123
-
124
- expect ( tsLoader . options . compiler ) . to . be . true
125
- expect ( tsLoader . options . logLevel ) . to . equal ( 'error' )
126
- expect ( tsLoader . options . silent ) . to . be . true
127
- expect ( tsLoader . options . transpileOnly ) . to . be . true
128
-
129
- // compilerOptions are overridden (sourceMap=true) by `@cypress/webpack-preprocessor` if ts-loader is present
130
- expect ( tsLoader . options . compilerOptions ) . to . be . undefined
116
+ expect ( ( ) => {
117
+ return preprocessorCB ( {
118
+ filePath : 'foo.ts' ,
119
+ outputPath : '.js' ,
120
+ } )
121
+ } ) . to . throw ( 'No tsconfig.json found, but typescript is installed. ts-loader needs a tsconfig.json file to work. Please add one to your project in either the root or the cypress directory.' )
131
122
} )
132
123
} )
133
124
} )
You can’t perform that action at this time.
0 commit comments