@@ -2,30 +2,32 @@ import test from 'node:test';
2
2
import assert from 'node:assert/strict' ;
3
3
import http from 'node:http' ;
4
4
5
- import PodiumHttpClient from '../lib/http-client.js' ;
5
+ import HttpClient from '../lib/http-client.js' ;
6
6
7
7
let httpServer ,
8
8
host = 'localhost' ,
9
9
port = 3003 ;
10
10
11
+ async function beforeEach ( ) {
12
+ httpServer = http . createServer ( async ( request , response ) => {
13
+ response . writeHead ( 200 ) ;
14
+ response . end ( ) ;
15
+ } ) ;
16
+ httpServer . listen ( port , host , ( ) => Promise . resolve ( ) ) ;
17
+ }
18
+
11
19
async function afterEach ( client ) {
12
20
await client . close ( ) ;
13
21
await httpServer . close ( ) ;
14
22
}
15
23
16
24
test ( 'http-client - basics' , async ( t ) => {
17
- t . beforeEach ( async function ( ) {
18
- httpServer = http . createServer ( async ( request , response ) => {
19
- response . writeHead ( 200 ) ;
20
- response . end ( ) ;
21
- } ) ;
22
- httpServer . listen ( port , host , ( ) => Promise . resolve ( ) ) ;
23
- } ) ;
24
25
await t . test (
25
26
'http-client: returns 200 response when given valid input' ,
26
27
async ( ) => {
28
+ await beforeEach ( ) ;
27
29
const url = `http://${ host } :${ port } ` ;
28
- const client = new PodiumHttpClient ( ) ;
30
+ const client = new HttpClient ( ) ;
29
31
const response = await client . request ( {
30
32
path : '/' ,
31
33
origin : url ,
@@ -37,8 +39,9 @@ test('http-client - basics', async (t) => {
37
39
) ;
38
40
39
41
await t . test ( 'does not cause havoc with built in fetch' , async ( ) => {
42
+ await beforeEach ( ) ;
40
43
const url = `http://${ host } :${ port } ` ;
41
- const client = new PodiumHttpClient ( ) ;
44
+ const client = new HttpClient ( ) ;
42
45
await fetch ( url ) ;
43
46
const response = await client . request ( {
44
47
path : '/' ,
@@ -51,9 +54,10 @@ test('http-client - basics', async (t) => {
51
54
await afterEach ( client ) ;
52
55
} ) ;
53
56
54
- test . skip ( 'http-client: should not invalid port input' , async ( ) => {
57
+ await test . skip ( 'http-client: should not invalid port input' , async ( ) => {
58
+ await beforeEach ( ) ;
55
59
const url = `http://${ host } :3013` ;
56
- const client = new PodiumHttpClient ( ) ;
60
+ const client = new HttpClient ( ) ;
57
61
await client . request ( {
58
62
path : '/' ,
59
63
origin : url ,
@@ -65,13 +69,15 @@ test('http-client - basics', async (t) => {
65
69
method : 'GET' ,
66
70
} ) ;
67
71
assert . strictEqual ( response . statusCode , 200 ) ;
72
+ await afterEach ( client ) ;
68
73
} ) ;
69
74
} ) ;
70
75
71
76
test . skip ( 'http-client circuit breaker behaviour' , async ( t ) => {
72
77
await t . test ( 'closes on failure threshold' , async ( ) => {
78
+ await beforeEach ( ) ;
73
79
const url = `http://${ host } :3014` ;
74
- const client = new PodiumHttpClient ( { threshold : 2 } ) ;
80
+ const client = new HttpClient ( { threshold : 2 } ) ;
75
81
await client . request ( {
76
82
path : '/' ,
77
83
origin : url ,
0 commit comments