@@ -18,6 +18,7 @@ let { BatchInterceptor } = require('@mswjs/interceptors');
1818let nodeInterceptors = require ( '@mswjs/interceptors/lib/presets/node.js' ) ;
1919let fs = require ( "fs" ) ;
2020let _ = require ( "lodash" ) ;
21+ const path = require ( 'path' ) ;
2122let { AsyncLocalStorage } = require ( 'node:async_hooks' ) ;
2223// const duplexify = require('duplexify');
2324
@@ -36,6 +37,7 @@ class Pythagora {
3637 this . ignore = args . ignore ;
3738 this . fullCodeCoverageReport = args . full_code_coverage_report ;
3839 this . initCommand = args . init_command . join ( ' ' ) ;
40+ this . pythagora_root = args . pythagora_root
3941
4042 this . idSeq = 0 ;
4143 this . requests = { } ;
@@ -77,7 +79,7 @@ class Pythagora {
7779 if ( ! result ) {
7880 failedRequests . push ( request . endpoint ) ;
7981 console . log ( `Capture is not valid for endpoint ${ request . endpoint } (${ request . method } ). Erasing...` )
80- let reqFileName = `./ ${ PYTHAGORA_TESTS_DIR } / ${ request . endpoint . replace ( / \/ / g, PYTHAGORA_DELIMITER ) } .json`;
82+ let reqFileName = path . resolve ( this . pythagora_root , PYTHAGORA_TESTS_DIR , ` ${ request . endpoint . replace ( / \/ / g, PYTHAGORA_DELIMITER ) } .json`) ;
8183 if ( ! fs . existsSync ( reqFileName ) ) continue ;
8284 let fileContent = JSON . parse ( fs . readFileSync ( reqFileName ) ) ;
8385 if ( fileContent . length === 1 ) {
@@ -101,7 +103,7 @@ class Pythagora {
101103 logCaptureFinished ( savedRequests . length , failedRequests . length ) ;
102104 }
103105
104- fs . writeFileSync ( `./ ${ PYTHAGORA_METADATA_DIR } / finishingup` , 'done' ) ;
106+ fs . writeFileSync ( path . resolve ( this . pythagora_root , PYTHAGORA_METADATA_DIR , ' finishingup' ) , 'done' ) ;
105107 process . exit ( ) ;
106108 }
107109
@@ -128,7 +130,7 @@ class Pythagora {
128130 } ] ) ;
129131 this . metadata . runs = this . metadata . runs . slice ( - 10 ) ;
130132 this . metadata . initCommand = this . initCommand ;
131- fs . writeFileSync ( `./ ${ PYTHAGORA_METADATA_DIR } / ${ METADATA_FILENAME } ` , JSON . stringify ( this . metadata , getCircularReplacer ( ) , 2 ) ) ;
133+ fs . writeFileSync ( path . resolve ( this . pythagora_root , PYTHAGORA_METADATA_DIR , METADATA_FILENAME ) , JSON . stringify ( this . metadata , getCircularReplacer ( ) , 2 ) ) ;
132134 console . log ( 'Test run metadata saved.' ) ;
133135 }
134136
@@ -234,9 +236,9 @@ class Pythagora {
234236 }
235237
236238 async getRequestMockDataById ( req ) {
237- let path = `./ ${ PYTHAGORA_TESTS_DIR } / ${ req . path . replace ( / \/ / g, PYTHAGORA_DELIMITER ) } .json`;
238- if ( ! fs . existsSync ( path ) ) return ;
239- let capturedRequests = JSON . parse ( await fs . promises . readFile ( path , 'utf8' ) ) ;
239+ let reqPath = path . resolve ( this . pythagora_root , PYTHAGORA_TESTS_DIR , ` ${ req . path . replace ( / \/ / g, PYTHAGORA_DELIMITER ) } .json`) ;
240+ if ( ! fs . existsSync ( reqPath ) ) return ;
241+ let capturedRequests = JSON . parse ( await fs . promises . readFile ( reqPath , 'utf8' ) ) ;
240242 return capturedRequests . find ( request => request . id === req . headers [ 'pythagora-req-id' ] ) ;
241243 }
242244
0 commit comments