7
7
8
8
import { assert , describe , it } from "vitest" ;
9
9
10
- import { CustomFetchHandler , HeadersInspectionHandler , HttpClient , Middleware , ParametersNameDecodingHandler , RedirectHandler , RetryHandler , UrlReplaceHandler , UserAgentHandler } from "../../src" ;
10
+ import { CustomFetchHandler , HeadersInspectionHandler , HttpClient , MiddlewareFactory , ParametersNameDecodingHandler , RedirectHandler , RetryHandler , UrlReplaceHandler , UserAgentHandler , CompressionHandler } from "../../src" ;
11
11
import { DummyFetchHandler } from "../common/middleware/dummyFetchHandler" ;
12
- import { CompressionHandler } from "../../src/middlewares/compressionHandler" ;
13
12
14
13
describe ( "browser - HTTPClient.ts" , ( ) => {
15
14
describe ( "constructor" , ( ) => {
@@ -40,10 +39,9 @@ describe("browser - HTTPClient.ts", () => {
40
39
assert . isTrue ( next instanceof RedirectHandler ) ;
41
40
assert . isTrue ( next ?. next instanceof ParametersNameDecodingHandler ) ;
42
41
assert . isTrue ( next ?. next ?. next instanceof UserAgentHandler ) ;
43
- assert . isTrue ( next ?. next ?. next ?. next instanceof CompressionHandler ) ;
44
- assert . isTrue ( next ?. next ?. next ?. next ?. next instanceof HeadersInspectionHandler ) ;
45
- assert . isTrue ( next ?. next ?. next ?. next ?. next ?. next instanceof UrlReplaceHandler ) ;
46
- assert . isTrue ( next ?. next ?. next ?. next ?. next ?. next ?. next instanceof CustomFetchHandler ) ;
42
+ assert . isTrue ( next ?. next ?. next ?. next instanceof HeadersInspectionHandler ) ;
43
+ assert . isTrue ( next ?. next ?. next ?. next ?. next instanceof UrlReplaceHandler ) ;
44
+ assert . isTrue ( next ?. next ?. next ?. next ?. next ?. next instanceof CustomFetchHandler ) ;
47
45
} ) ;
48
46
49
47
it ( "Should set default middleware array with customFetchHandler if middleware parameter is undefined && customFetch is defined" , ( ) => {
@@ -57,10 +55,9 @@ describe("browser - HTTPClient.ts", () => {
57
55
assert . isTrue ( next instanceof RedirectHandler ) ;
58
56
assert . isTrue ( next ?. next instanceof ParametersNameDecodingHandler ) ;
59
57
assert . isTrue ( next ?. next ?. next instanceof UserAgentHandler ) ;
60
- assert . isTrue ( next ?. next ?. next ?. next instanceof CompressionHandler ) ;
61
- assert . isTrue ( next ?. next ?. next ?. next ?. next instanceof HeadersInspectionHandler ) ;
62
- assert . isTrue ( next ?. next ?. next ?. next ?. next ?. next instanceof UrlReplaceHandler ) ;
63
- assert . isTrue ( next ?. next ?. next ?. next ?. next ?. next ?. next instanceof CustomFetchHandler ) ;
58
+ assert . isTrue ( next ?. next ?. next ?. next instanceof HeadersInspectionHandler ) ;
59
+ assert . isTrue ( next ?. next ?. next ?. next ?. next instanceof UrlReplaceHandler ) ;
60
+ assert . isTrue ( next ?. next ?. next ?. next ?. next ?. next instanceof CustomFetchHandler ) ;
64
61
} ) ;
65
62
66
63
it ( "Should set to default fetch handler middleware array if middleware parameter is null && customFetch is undefined" , ( ) => {
@@ -78,5 +75,21 @@ describe("browser - HTTPClient.ts", () => {
78
75
assert . equal ( client [ "customFetch" ] , dummyCustomFetch ) ;
79
76
assert . isTrue ( client [ "middleware" ] ?. next ?. next ?. next ?. next ?. next ?. next ?. next instanceof CustomFetchHandler ) ;
80
77
} ) ;
78
+
79
+ it ( "Should set performance middleware for the http client" , ( ) => {
80
+ const client = new HttpClient ( null , ...MiddlewareFactory . getPerformanceMiddlewares ( ) ) ;
81
+
82
+ assert . isNotNull ( client [ "middleware" ] ) ;
83
+ const next = client [ "middleware" ] . next ;
84
+
85
+ assert . isTrue ( client [ "middleware" ] instanceof RetryHandler ) ;
86
+ assert . isTrue ( next instanceof RedirectHandler ) ;
87
+ assert . isTrue ( next ?. next instanceof ParametersNameDecodingHandler ) ;
88
+ assert . isTrue ( next ?. next ?. next instanceof UserAgentHandler ) ;
89
+ assert . isTrue ( next ?. next ?. next ?. next instanceof CompressionHandler ) ;
90
+ assert . isTrue ( next ?. next ?. next ?. next ?. next instanceof HeadersInspectionHandler ) ;
91
+ assert . isTrue ( next ?. next ?. next ?. next ?. next ?. next instanceof UrlReplaceHandler ) ;
92
+ assert . isTrue ( next ?. next ?. next ?. next ?. next ?. next ?. next instanceof CustomFetchHandler ) ;
93
+ } ) ;
81
94
} ) ;
82
95
} ) ;
0 commit comments