@@ -74,6 +74,31 @@ describe('express', () => {
7474 }
7575 } ) ;
7676 }
77+
78+ it ( 'should allow manipulating the response from the request context' , async ( ) => {
79+ const app = express ( ) ;
80+ app . all (
81+ '/' ,
82+ createExpressHandler ( {
83+ schema,
84+ context ( req ) {
85+ req . context . res . setHeader ( 'x-test' , 'test-x' ) ;
86+ return undefined ;
87+ } ,
88+ } ) ,
89+ ) ;
90+
91+ const [ url , dispose ] = startDisposableServer ( app . listen ( 0 ) ) ;
92+
93+ const res = await fetch ( url + '?query={hello}' ) ;
94+
95+ await expect ( res . text ( ) ) . resolves . toMatchInlineSnapshot (
96+ `"{"data":{"hello":"world"}}"` ,
97+ ) ;
98+ expect ( res . headers . get ( 'x-test' ) ) . toBe ( 'test-x' ) ;
99+
100+ await dispose ( ) ;
101+ } ) ;
77102} ) ;
78103
79104describe ( 'fastify' , ( ) => {
@@ -104,6 +129,35 @@ describe('fastify', () => {
104129 }
105130 } ) ;
106131 }
132+
133+ it ( 'should allow manipulating the response from the request context' , async ( ) => {
134+ const app = fastify ( ) ;
135+
136+ app . all (
137+ '/' ,
138+ createFastifyHandler ( {
139+ schema,
140+ context ( req ) {
141+ req . context . reply . header ( 'x-test' , 'test-x' ) ;
142+ return undefined ;
143+ } ,
144+ } ) ,
145+ ) ;
146+
147+ // call ready since we're not calling listen
148+ app . ready ( ) ;
149+
150+ const [ url , dispose ] = startDisposableServer ( app . server ) ;
151+
152+ const res = await fetch ( url + '?query={hello}' ) ;
153+
154+ await expect ( res . text ( ) ) . resolves . toMatchInlineSnapshot (
155+ `"{"data":{"hello":"world"}}"` ,
156+ ) ;
157+ expect ( res . headers . get ( 'x-test' ) ) . toBe ( 'test-x' ) ;
158+
159+ await dispose ( ) ;
160+ } ) ;
107161} ) ;
108162
109163describe ( 'fetch' , ( ) => {
@@ -137,4 +191,31 @@ describe('koa', () => {
137191 }
138192 } ) ;
139193 }
194+
195+ it ( 'should allow manipulating the response from the request context' , async ( ) => {
196+ const app = new Koa ( ) ;
197+ app . use (
198+ mount (
199+ '/' ,
200+ createKoaHandler ( {
201+ schema,
202+ context ( req ) {
203+ req . context . res . set ( 'x-test' , 'test-x' ) ;
204+ return undefined ;
205+ } ,
206+ } ) ,
207+ ) ,
208+ ) ;
209+
210+ const [ url , dispose ] = startDisposableServer ( app . listen ( 0 ) ) ;
211+
212+ const res = await fetch ( url + '?query={hello}' ) ;
213+
214+ await expect ( res . text ( ) ) . resolves . toMatchInlineSnapshot (
215+ `"{"data":{"hello":"world"}}"` ,
216+ ) ;
217+ expect ( res . headers . get ( 'x-test' ) ) . toBe ( 'test-x' ) ;
218+
219+ await dispose ( ) ;
220+ } ) ;
140221} ) ;
0 commit comments