1010
1111import axios from 'axios' ;
1212import log from 'loglevel' ;
13- import { CSISHelpers } from 'csis-helpers-js' ;
1413import express from 'express' ;
14+
15+ // required because of https://github.com/clarity-h2020/simple-table-component/issues/4#issuecomment-595114163
16+ import 'react-app-polyfill/ie9' ;
17+ import 'react-app-polyfill/stable' ;
18+
19+ import { CSISHelpers } from 'csis-helpers-js' ;
1520import apiResponseStudy from './../__fixtures__/study.json' ;
1621import apiResponseDataPackage from './../__fixtures__/dataPackage.json' ;
1722import apiResponseResources from './../__fixtures__/resources.json' ;
@@ -21,6 +26,9 @@ const app = express();
2126var server ;
2227
2328beforeAll ( ( ) => {
29+ // required because of https://github.com/clarity-h2020/map-component/issues/43#issuecomment-595621339
30+ axios . defaults . adapter = require ( 'axios/lib/adapters/http' ) ;
31+
2432 app . get ( '/jsonapi/group/study' , function ( req , res ) {
2533 res . json ( apiResponseStudy ) ;
2634 } ) ;
@@ -41,14 +49,21 @@ beforeAll(() => {
4149 res . json ( apiResponseResources ) ;
4250 } ) ;
4351
44- server = app . listen ( 31336 , ( ) => log . debug ( 'Example app listening on port 31336!' ) ) ;
52+ // this is just unbelievable: log.debug() is not printed to console when running the tests in VSCode. WTF?!
53+ server = app . listen ( 0 , ( ) => log . debug ( `Example app listening on http://${ server . address ( ) . address } :${ server . address ( ) . port } ` ) ) ;
54+ log . debug ( `Example app listening on http://${ server . address ( ) . address } :${ server . address ( ) . port } ` ) ;
4555} ) ;
4656
4757test ( 'test extract study area from study json' , async ( done ) => {
4858
49- const response = await axios . get (
50- 'http://localhost:31336/jsonapi/group/study?filter[id][condition][path]=id&filter[id][condition][operator]=%3D&filter[id][condition][value]=c3609e3e-f80f-482b-9e9f-3a26226a6859'
51- ) ;
59+ // does not work if bound d to ipv6 adaress. :-()
60+ // const url = `http://${server.address().address}:${server.address().port}/jsonapi/group/study?filter[id][condition][path]=id&filter[id][condition][operator]=%3D&filter[id][condition][value]=c3609e3e-f80f-482b-9e9f-3a26226a6859`;
61+ const url = `http://localhost:${ server . address ( ) . port } /jsonapi/group/study?filter[id][condition][path]=id&filter[id][condition][operator]=%3D&filter[id][condition][value]=c3609e3e-f80f-482b-9e9f-3a26226a6859` ;
62+ // unbelievable: does not print to console. See https://github.com/facebook/jest/issues/2441
63+ log . info ( url ) ;
64+ const response = await axios . get ( url ) ;
65+ // -> error 400 ?! This used to work with a fixed port. since simple things like logging don't seem
66+ // to be possible with jest, and debugging tests in vscode works only 50% of the time, we disable this test.
5267
5368 expect . assertions ( 5 ) ;
5469 expect ( response ) . toBeDefined ( ) ;
@@ -158,8 +173,16 @@ test('check for emikat id in study', () => {
158173
159174afterAll ( ( ) => {
160175 log . debug ( 'afterAll' ) ;
161- server . close ( ( ) => {
162- //console.log('JSON Server closed');
163- //process.exit(0);
164- } ) ;
176+ if ( server ) {
177+ server . close ( ( ) => {
178+ //console.log('JSON Server closed');
179+ //process.exit(0);
180+ } ) ;
181+ } else {
182+ // WTF?!!!!
183+ // https://github.com/clarity-h2020/map-component/issues/43#issuecomment-595637179
184+
185+ // unfortunely, we'll never see this because of https://github.com/facebook/jest/issues/2441
186+ log . warn ( 'server undefined' ) ;
187+ }
165188} ) ;
0 commit comments