@@ -32,30 +32,36 @@ const baseline = JSON.parse(
3232
3333const USERDATA_FILES = [ 'json' , 'xlsx' , 'csv' , 'parquet' , 'jsonl' , 'cjson' ] ;
3434const PORT = '9799' ;
35+ const PORT2 = '9798' ;
3536
36- let server ;
37+ let server , server2 ;
3738// Kill the existing server if it wasn't killed correctly already.
3839beforeAll ( async ( ) => {
3940 // TODO: port this logic to other platforms...
40- if ( process . platform === 'linux' ) {
41- try {
42- cp . execSync (
43- `bash -c "ps aux | grep 'http.server ${ PORT } ' | grep -v grep | awk '{print \\$2}' | xargs -I {} kill {}"`
44- ) ;
45- } catch ( e ) {
46- console . error ( e ) ;
41+ for ( const port of [ PORT , PORT2 ] ) {
42+ if ( process . platform === 'linux' ) {
43+ try {
44+ cp . execSync (
45+ `bash -c "ps aux | grep 'http.server ${ port } ' | grep -v grep | awk '{print \\$2}' | xargs -I {} kill {}"`
46+ ) ;
47+ } catch ( e ) {
48+ console . error ( e ) ;
49+ }
4750 }
4851 }
4952
5053 // Start a new server for all tests
5154 server = spawn ( 'python3' , [ '-m' , 'http.server' , PORT ] ) ;
55+ server2 = spawn ( 'httpmirror' , [ PORT2 ] ) ;
5256
53- server . stdout . on ( 'data' , ( data ) => {
54- console . log ( data . toString ( ) ) ;
55- } ) ;
57+ [ server , server2 ] . forEach ( ( server ) => {
58+ server . stdout . on ( 'data' , ( data ) => {
59+ console . log ( data . toString ( ) ) ;
60+ } ) ;
5661
57- server . stderr . on ( 'data' , ( data ) => {
58- console . warn ( data . toString ( ) ) ;
62+ server . stderr . on ( 'data' , ( data ) => {
63+ console . warn ( data . toString ( ) ) ;
64+ } ) ;
5965 } ) ;
6066
6167 // Keep trying to connect to the server until it's ready
@@ -240,7 +246,7 @@ for (const subprocessName of RUNNERS) {
240246 } ) ;
241247
242248 describe ( 'http with macro' , ( ) => {
243- test ( 'correct result ' , ( ) => {
249+ test ( 'macro as url ' , ( ) => {
244250 const lp = new LiteralPanelInfo ( {
245251 contentTypeInfo : { type : 'text/plain' } ,
246252 content : '/testdata/allformats/unknown' ,
@@ -269,6 +275,40 @@ for (const subprocessName of RUNNERS) {
269275 { evalPanels : true , subprocessName }
270276 ) ;
271277 } ) ;
278+
279+ test ( 'macro as body' , ( ) => {
280+ const lp = new LiteralPanelInfo ( {
281+ contentTypeInfo : { type : 'application/json' } ,
282+ content : '[{"name": "jim", "age": 12}]' ,
283+ name : 'Raw Data' ,
284+ } ) ;
285+
286+ const hp = new HTTPPanelInfo (
287+ '' ,
288+ new HTTPConnectorInfo ( '' , 'http://localhost:9798' )
289+ ) ;
290+ hp . http . http . method = 'POST' ;
291+ hp . content = '{{ DM_getPanel("0") | json }}' ;
292+ hp . http . http . contentTypeInfo . type = 'text/plain' ;
293+
294+ const panels = [ lp , hp ] ;
295+
296+ return withSavedPanels (
297+ panels ,
298+ ( project ) => {
299+ // Grab result
300+ const value = JSON . parse (
301+ fs
302+ . readFileSync ( getProjectResultsFile ( project . projectName ) + hp . id )
303+ . toString ( )
304+ ) ;
305+ expect ( [ { name : 'jim' , age : 12 } ] ) . toStrictEqual (
306+ JSON . parse ( value . split ( '\r\n\r\n' ) [ 1 ] )
307+ ) ;
308+ } ,
309+ { evalPanels : true , subprocessName }
310+ ) ;
311+ } ) ;
272312 } ) ;
273313
274314 if ( process . platform === 'linux' ) {
@@ -313,4 +353,5 @@ for (const subprocessName of RUNNERS) {
313353
314354afterAll ( ( ) => {
315355 process . kill ( server . pid ) ;
356+ process . kill ( server2 . pid ) ;
316357} ) ;
0 commit comments