@@ -10,7 +10,8 @@ import { tmpdir } from 'node:os'
10
10
import { join } from 'node:path'
11
11
import { fileURLToPath } from 'node:url'
12
12
import { vi } from 'vitest'
13
- import { EnhancedNetlifyPluginOptions } from '../../src/helpers/types.js'
13
+ import { streamToString } from './stream-to-string.js'
14
+ import type { NetlifyPluginConstants , NetlifyPluginOptions } from '@netlify/build'
14
15
15
16
export interface FixtureTestContext extends TestContext {
16
17
cwd : string
@@ -71,15 +72,20 @@ export async function runPluginAndExecute(
71
72
* @default 'GET'
72
73
*/
73
74
httpMethod ?: string
75
+ /**
76
+ * The relative path that should be requested
77
+ * @default '/'
78
+ */
79
+ url ?: string
74
80
/** The headers used for the invocation*/
75
81
headers ?: Record < string , string >
76
82
/** The body that is used for the invocation */
77
83
body ?: unknown
78
84
/** Additional constants or overrides that are used for the plugin execution */
79
- constants ?: Partial < EnhancedNetlifyPluginOptions >
85
+ constants ?: Partial < NetlifyPluginConstants >
80
86
} = { } ,
81
- ) : Promise < LambdaResponse > {
82
- const { constants, httpMethod, headers, body } = options
87
+ ) {
88
+ const { constants, httpMethod, headers, body, url } = options
83
89
const { onBuild } = await import ( '../../src/index.js' )
84
90
await onBuild ( {
85
91
constants : {
@@ -98,7 +104,7 @@ export async function runPluginAndExecute(
98
104
// INTERNAL_FUNCTIONS_SRC: '.netlify/functions-internal',
99
105
// INTERNAL_EDGE_FUNCTIONS_SRC: '.netlify/edge-functions',
100
106
} ,
101
- } as EnhancedNetlifyPluginOptions )
107
+ } as unknown as NetlifyPluginOptions )
102
108
103
109
// We need to do a dynamic import as we mock the `process.cwd()` inside the createFixture function
104
110
// If we import it before calling that it will resolve to the actual process working directory instead of the mocked one
@@ -135,15 +141,20 @@ export async function runPluginAndExecute(
135
141
) . toString ( 'base64' ) ,
136
142
}
137
143
138
- const response = await execute ( {
144
+ const response = ( await execute ( {
139
145
event : {
140
146
headers : headers || { } ,
141
147
httpMethod : httpMethod || 'GET' ,
142
- rawUrl : ' https://example.netlify',
148
+ rawUrl : new URL ( url || '/' , ' https://example.netlify') . href ,
143
149
} ,
144
150
environment,
145
151
lambdaFunc : { handler } ,
146
- } )
152
+ } ) ) as LambdaResponse
147
153
148
- return response as LambdaResponse
154
+ return {
155
+ statusCode : response . statusCode ,
156
+ body : await streamToString ( response . body ) ,
157
+ headers : response . headers ,
158
+ isBase64Encoded : response . isBase64Encoded ,
159
+ }
149
160
}
0 commit comments