11import path from 'path' ;
2+ import EventEmitter from 'events' ;
23
34import fs from 'fs-extra' ;
4- import MockExpressResponse from 'mock-express-response ' ;
5+ import httpMocks from 'node-mocks-http ' ;
56
67import {
78 viewFrontendVersionHandler ,
@@ -19,16 +20,16 @@ describe(__filename, () => {
1920 const _config = getFakeConfig ( { basePath } ) ;
2021 const handler = viewFrontendVersionHandler ( { _config } ) ;
2122
22- const res = new MockExpressResponse ( ) ;
23+ const res = httpMocks . createResponse ( {
24+ eventEmitter : EventEmitter ,
25+ } ) ;
2326 handler ( null , res ) ;
2427
25- res . on ( 'finish ' , ( ) => {
28+ res . on ( 'end ' , ( ) => {
2629 expect ( res . statusCode ) . toEqual ( 200 ) ;
27- expect ( res . get ( 'content-type' ) ) . toEqual (
28- 'application/json; charset=utf-8' ,
29- ) ;
30+ expect ( res . get ( 'content-type' ) ) . toEqual ( 'application/json' ) ;
3031 expect ( res . get ( 'access-control-allow-origin' ) ) . toEqual ( '*' ) ;
31- expect ( res . _getJSON ( ) ) . toMatchObject ( versionJson ) ;
32+ expect ( res . _getJSONData ( ) ) . toMatchObject ( versionJson ) ;
3233
3334 done ( ) ;
3435 } ) ;
@@ -50,11 +51,13 @@ describe(__filename, () => {
5051 ) ;
5152 const handler = viewFrontendVersionHandler ( { _config } ) ;
5253
53- const res = new MockExpressResponse ( ) ;
54+ const res = httpMocks . createResponse ( {
55+ eventEmitter : EventEmitter ,
56+ } ) ;
5457 handler ( null , res ) ;
5558
56- res . on ( 'finish ' , ( ) => {
57- expect ( res . _getJSON ( ) ) . toMatchObject ( {
59+ res . on ( 'end ' , ( ) => {
60+ expect ( res . _getJSONData ( ) ) . toMatchObject ( {
5861 ...versionJson ,
5962 experiments,
6063 feature_flags : {
@@ -73,10 +76,12 @@ describe(__filename, () => {
7376
7477 const handler = viewFrontendVersionHandler ( { _config, _log } ) ;
7578
76- const res = new MockExpressResponse ( ) ;
79+ const res = httpMocks . createResponse ( {
80+ eventEmitter : EventEmitter ,
81+ } ) ;
7782 handler ( null , res ) ;
7883
79- res . on ( 'finish ' , ( ) => {
84+ res . on ( 'end ' , ( ) => {
8085 expect ( res . statusCode ) . toEqual ( 415 ) ;
8186 sinon . assert . calledOnce ( _log . error ) ;
8287
@@ -94,7 +99,7 @@ describe(__filename, () => {
9499 const _fetch = jest . fn ( ) . mockResolvedValue ( { status : 200 } ) ;
95100 const handler = viewHeartbeatHandler ( { _config, _fetch } ) ;
96101
97- const res = new MockExpressResponse ( ) ;
102+ const res = httpMocks . createResponse ( ) ;
98103 await handler ( null , res ) ;
99104
100105 expect ( _fetch ) . toHaveBeenCalledWith (
@@ -107,7 +112,7 @@ describe(__filename, () => {
107112 const _fetch = jest . fn ( ) . mockResolvedValue ( { status : 400 } ) ;
108113 const handler = viewHeartbeatHandler ( { _fetch } ) ;
109114
110- const res = new MockExpressResponse ( ) ;
115+ const res = httpMocks . createResponse ( ) ;
111116 await handler ( null , res ) ;
112117
113118 expect ( res . statusCode ) . toEqual ( 500 ) ;
@@ -117,7 +122,7 @@ describe(__filename, () => {
117122 const _fetch = jest . fn ( ) . mockRejectedValue ( ) ;
118123 const handler = viewHeartbeatHandler ( { _fetch } ) ;
119124
120- const res = new MockExpressResponse ( ) ;
125+ const res = httpMocks . createResponse ( ) ;
121126 await handler ( null , res ) ;
122127
123128 expect ( res . statusCode ) . toEqual ( 500 ) ;
0 commit comments