File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* eslint-disable */
2
+ const httpProxy = require ( 'http-proxy' ) ;
3
+
4
+ /*
5
+ This can be installed as a testem middleware to make testem run against an
6
+ arbitrary real webserver at targetURL.
7
+
8
+ It allows testem to handle the well-known testem-specific paths and proxies
9
+ everything else, while rewriting the testem-added prefix out of your
10
+ "/tests/index.html" URL.
11
+ */
12
+
13
+ module . exports = function testemProxy ( targetURL ) {
14
+ return function testemProxyHandler ( app ) {
15
+ const proxy = httpProxy . createProxyServer ( {
16
+ changeOrigin : true ,
17
+ ignorePath : true ,
18
+ } ) ;
19
+
20
+ proxy . on ( 'error' , ( err , _req , res ) => {
21
+ res && res . status && res . status ( 500 ) . json ( err ) ;
22
+ } ) ;
23
+
24
+ app . all ( '*' , ( req , res , next ) => {
25
+ let url = req . url ;
26
+ if ( url === '/testem.js' || url . startsWith ( '/testem/' ) ) {
27
+ return next ( ) ;
28
+ }
29
+ let m = / ^ ( \/ \d + ) \/ t e s t s \/ i n d e x .h t m l / . exec ( url ) ;
30
+ if ( m ) {
31
+ url = url . slice ( m [ 1 ] . length ) ;
32
+ }
33
+ proxy . web ( req , res , { target : targetURL + url } ) ;
34
+ } ) ;
35
+ } ;
36
+ } ;
You can’t perform that action at this time.
0 commit comments