@@ -89,6 +89,7 @@ var createKarmaMiddleware = function (
8989 var client = injector . get ( 'config.client' )
9090 var customContextFile = injector . get ( 'config.customContextFile' )
9191 var customDebugFile = injector . get ( 'config.customDebugFile' )
92+ var customClientContextFile = injector . get ( 'config.customClientContextFile' )
9293 var jsVersion = injector . get ( 'config.jsVersion' )
9394 var includeCrossOriginAttribute = injector . get ( 'config.crossOriginAttribute' )
9495
@@ -112,11 +113,16 @@ var createKarmaMiddleware = function (
112113
113114 // serve client.html
114115 if ( requestUrl === '/' ) {
115- return serveStaticFile ( '/client.html' , requestedRangeHeader , response , function ( data ) {
116- return data
117- . replace ( '\n%X_UA_COMPATIBLE%' , getXUACompatibleMetaElement ( request . url ) )
118- . replace ( '%X_UA_COMPATIBLE_URL%' , getXUACompatibleUrl ( request . url ) )
119- } )
116+ // redirect client_with_context.html
117+ if ( ! client . useIframe && client . runInParent ) {
118+ requestUrl = '/client_with_context.html'
119+ } else { // serve client.html
120+ return serveStaticFile ( '/client.html' , requestedRangeHeader , response , function ( data ) {
121+ return data
122+ . replace ( '\n%X_UA_COMPATIBLE%' , getXUACompatibleMetaElement ( request . url ) )
123+ . replace ( '%X_UA_COMPATIBLE_URL%' , getXUACompatibleUrl ( request . url ) )
124+ } )
125+ }
120126 }
121127
122128 // serve karma.js, context.js, and debug.js
@@ -139,11 +145,12 @@ var createKarmaMiddleware = function (
139145 // or debug.html - execution context without channel to the server
140146 var isRequestingContextFile = requestUrl === '/context.html'
141147 var isRequestingDebugFile = requestUrl === '/debug.html'
142- if ( isRequestingContextFile || isRequestingDebugFile ) {
148+ var isRequestingClientContextFile = requestUrl === '/client_with_context.html'
149+ if ( isRequestingContextFile || isRequestingDebugFile || isRequestingClientContextFile ) {
143150 return filesPromise . then ( function ( files ) {
144151 var fileServer
145152 var requestedFileUrl
146- log . debug ( 'custom files' , customContextFile , customDebugFile )
153+ log . debug ( 'custom files' , customContextFile , customDebugFile , customClientContextFile )
147154 if ( isRequestingContextFile && customContextFile ) {
148155 log . debug ( 'Serving customContextFile %s' , customContextFile )
149156 fileServer = serveFile
@@ -152,6 +159,10 @@ var createKarmaMiddleware = function (
152159 log . debug ( 'Serving customDebugFile %s' , customDebugFile )
153160 fileServer = serveFile
154161 requestedFileUrl = customDebugFile
162+ } else if ( isRequestingClientContextFile && customClientContextFile ) {
163+ log . debug ( 'Serving customClientContextFile %s' , customClientContextFile )
164+ fileServer = serveFile
165+ requestedFileUrl = customClientContextFile
155166 } else {
156167 log . debug ( 'Serving static request %s' , requestUrl )
157168 fileServer = serveStaticFile
@@ -161,7 +172,10 @@ var createKarmaMiddleware = function (
161172 fileServer ( requestedFileUrl , requestedRangeHeader , response , function ( data ) {
162173 common . setNoCacheHeaders ( response )
163174
164- var scriptTags = files . included . map ( function ( file ) {
175+ var scriptTags = [ ]
176+ var scriptUrls = [ ]
177+ for ( var i in files . included ) {
178+ var file = files . included [ i ]
165179 var filePath = file . path
166180 var fileExt = path . extname ( filePath )
167181
@@ -173,12 +187,16 @@ var createKarmaMiddleware = function (
173187 }
174188 }
175189
190+ scriptUrls . push ( filePath )
191+
176192 if ( fileExt === '.css' ) {
177- return util . format ( LINK_TAG_CSS , filePath )
193+ scriptTags . push ( util . format ( LINK_TAG_CSS , filePath ) )
194+ continue
178195 }
179196
180197 if ( fileExt === '.html' ) {
181- return util . format ( LINK_TAG_HTML , filePath )
198+ scriptTags . push ( util . format ( LINK_TAG_HTML , filePath ) )
199+ continue
182200 }
183201
184202 // The script tag to be placed
@@ -190,8 +208,8 @@ var createKarmaMiddleware = function (
190208 }
191209
192210 var crossOriginAttribute = includeCrossOriginAttribute ? CROSSORIGIN_ATTRIBUTE : ''
193- return util . format ( SCRIPT_TAG , scriptType , filePath , crossOriginAttribute )
194- } )
211+ scriptTags . push ( util . format ( SCRIPT_TAG , scriptType , filePath , crossOriginAttribute ) )
212+ }
195213
196214 // TODO(vojta): don't compute if it's not in the template
197215 var mappings = files . served . map ( function ( file ) {
@@ -206,11 +224,14 @@ var createKarmaMiddleware = function (
206224
207225 var clientConfig = 'window.__karma__.config = ' + JSON . stringify ( client ) + ';\n'
208226
227+ var scriptUrlsJS = 'window.__karma__.scriptUrls = ' + JSON . stringify ( scriptUrls ) + ';\n'
228+
209229 mappings = 'window.__karma__.files = {\n' + mappings . join ( ',\n' ) + '\n};\n'
210230
211231 return data
212232 . replace ( '%SCRIPTS%' , scriptTags . join ( '\n' ) )
213233 . replace ( '%CLIENT_CONFIG%' , clientConfig )
234+ . replace ( '%SCRIPT_URL_ARRAY%' , scriptUrlsJS )
214235 . replace ( '%MAPPINGS%' , mappings )
215236 . replace ( '\n%X_UA_COMPATIBLE%' , getXUACompatibleMetaElement ( request . url ) )
216237 } )
0 commit comments