@@ -14,6 +14,7 @@ log.setLevel('debug');
14
14
15
15
const tmpDir = path . resolve ( os . tmpdir ( ) , 'test' ) ;
16
16
const fileName = path . resolve ( tmpDir , 'bar.zip' ) ;
17
+ const ignoreSSL = true ;
17
18
const binaryUrl = proxyBaseUrl + '/spec/support/files/bar.zip' ;
18
19
const fooJsonUrl = proxyBaseUrl + '/spec/support/files/foo_json.json' ;
19
20
const fooArrayUrl = proxyBaseUrl + '/spec/support/files/foo_array.json' ;
@@ -22,31 +23,29 @@ const barZipSize = 171;
22
23
const headers = {
23
24
'host' : httpBaseUrl
24
25
} ;
26
+ const origTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
27
+ let httpProc : childProcess . ChildProcess ;
28
+ let proxyProc : childProcess . ChildProcess ;
25
29
26
- describe ( 'binary_utils' , ( ) => {
27
- const origTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
28
- let httpProc : childProcess . ChildProcess ;
29
- let proxyProc : childProcess . ChildProcess ;
30
-
31
- beforeAll ( ( done ) => {
30
+ describe ( 'binary_utils' , ( ) => {
31
+ beforeAll ( async ( ) => {
32
32
jasmine . DEFAULT_TIMEOUT_INTERVAL = 60000 ;
33
33
httpProc = spawnProcess ( 'node' , [ 'dist/spec/server/http_server.js' ] ) ;
34
34
log . debug ( 'http-server: ' + httpProc . pid ) ;
35
35
proxyProc = spawnProcess ( 'node' , [ 'dist/spec/server/proxy_server.js' ] ) ;
36
36
log . debug ( 'proxy-server: ' + proxyProc . pid ) ;
37
- setTimeout ( done , 3000 ) ;
37
+ await new Promise ( resolve => {
38
+ setTimeout ( resolve , 3000 ) ;
39
+ } ) ;
38
40
39
41
try {
40
42
fs . mkdirSync ( tmpDir ) ;
41
- } catch ( err ) {
42
- }
43
- try {
44
43
fs . unlinkSync ( fileName ) ;
45
44
} catch ( err ) {
46
45
}
47
46
} ) ;
48
47
49
- afterAll ( ( done ) => {
48
+ afterAll ( async ( ) => {
50
49
try {
51
50
fs . unlinkSync ( fileName ) ;
52
51
fs . rmdirSync ( tmpDir ) ;
@@ -55,48 +54,48 @@ describe('binary_utils', () => {
55
54
56
55
process . kill ( httpProc . pid ) ;
57
56
process . kill ( proxyProc . pid ) ;
58
- setTimeout ( done , 5000 ) ;
57
+ await new Promise ( resolve => {
58
+ setTimeout ( resolve , 5000 ) ;
59
+ } ) ;
59
60
jasmine . DEFAULT_TIMEOUT_INTERVAL = origTimeout ;
60
61
} ) ;
61
62
62
63
describe ( 'requestBinary' , ( ) => {
63
- it ( 'should download the file if no file exists or ' +
64
- 'the content lenght is different' ,
65
- ( done ) => {
66
- requestBinary ( binaryUrl , { fileName, fileSize : 0 , headers} )
67
- . then ( ( result ) => {
68
- expect ( result ) . toBeTruthy ( ) ;
69
- expect ( fs . statSync ( fileName ) . size ) . toBe ( barZipSize ) ;
70
- done ( ) ;
71
- } )
72
- . catch ( err => {
73
- done . fail ( err ) ;
74
- } ) ;
75
- } ) ;
64
+ it ( 'should download the file if no file exists or the content lenght ' +
65
+ 'is different' , async ( ) => {
66
+ try {
67
+ const result = await requestBinary (
68
+ binaryUrl , { fileName, fileSize : 0 , headers, ignoreSSL} ) ;
69
+ expect ( result ) . toBeTruthy ( ) ;
70
+ expect ( fs . statSync ( fileName ) . size ) . toBe ( barZipSize ) ;
71
+ } catch ( err ) {
72
+ fail ( err ) ;
73
+ }
74
+ } ) ;
76
75
77
- it ( 'should not download the file if the file exists' , ( done ) => {
78
- requestBinary ( binaryUrl , { fileName , fileSize : barZipSize , headers } )
79
- . then ( ( result ) => {
80
- expect ( result ) . toBeFalsy ( ) ;
81
- expect ( fs . statSync ( fileName ) . size ) . toBe ( barZipSize ) ;
82
- done ( ) ;
83
- } )
84
- . catch ( err => {
85
- done . fail ( err ) ;
86
- } ) ;
76
+ it ( 'should not download the file if the file exists' , async ( ) => {
77
+ try {
78
+ const result = await requestBinary (
79
+ binaryUrl , { fileName , fileSize : barZipSize , headers ,
80
+ ignoreSSL } ) ;
81
+ expect ( result ) . toBeFalsy ( ) ;
82
+ expect ( fs . statSync ( fileName ) . size ) . toBe ( barZipSize ) ;
83
+ } catch ( err ) {
84
+ fail ( err ) ;
85
+ }
87
86
} ) ;
88
87
} ) ;
89
88
90
89
describe ( 'requestBody' , ( ) => {
91
90
it ( 'should download a json object file' , async ( ) => {
92
- const foo = await requestBody ( fooJsonUrl , { headers} ) ;
91
+ const foo = await requestBody ( fooJsonUrl , { headers, ignoreSSL } ) ;
93
92
const fooJson = JSON . parse ( foo ) ;
94
93
expect ( fooJson [ 'foo' ] ) . toBe ( 'abc' ) ;
95
94
expect ( fooJson [ 'bar' ] ) . toBe ( 123 ) ;
96
95
} ) ;
97
96
98
97
it ( 'should download a json array file' , async ( ) => {
99
- const foo = await requestBody ( fooArrayUrl , { headers} ) ;
98
+ const foo = await requestBody ( fooArrayUrl , { headers, ignoreSSL } ) ;
100
99
const fooJson = JSON . parse ( foo ) ;
101
100
expect ( fooJson . length ) . toBe ( 3 ) ;
102
101
expect ( fooJson [ 0 ] [ 'foo' ] ) . toBe ( 'abc' ) ;
@@ -105,7 +104,7 @@ describe('binary_utils', () => {
105
104
} ) ;
106
105
107
106
it ( 'should get the xml file' , async ( ) => {
108
- const text = await requestBody ( fooXmlUrl , { headers} ) ;
107
+ const text = await requestBody ( fooXmlUrl , { headers, ignoreSSL } ) ;
109
108
expect ( text . length ) . toBeGreaterThan ( 0 ) ;
110
109
} ) ;
111
110
} ) ;
0 commit comments