11import path from "node:path" ;
22import { findWranglerConfig } from "../../config/config-helpers" ;
33import { mockConsoleMethods } from "../helpers/mock-console" ;
4+ import { normalizeString } from "../helpers/normalize" ;
45import { runInTempDir } from "../helpers/run-in-tmp" ;
56import { seed } from "../helpers/seed" ;
67
@@ -163,10 +164,16 @@ describe("config findWranglerConfig()", () => {
163164 await seed ( {
164165 [ ".wrangler/deploy/config.json" ] : `INVALID JSON` ,
165166 } ) ;
166- expect ( ( ) =>
167- findWranglerConfig ( "." , { useRedirect : true } )
168- ) . toThrowErrorMatchingInlineSnapshot (
169- `[Error: Failed to load the deploy config at .wrangler/deploy/config.json]`
167+
168+ let error ;
169+ try {
170+ findWranglerConfig ( "." , { useRedirect : true } ) ;
171+ } catch ( e ) {
172+ error = e ;
173+ }
174+
175+ expect ( normalizeString ( `${ error } ` ) ) . toMatchInlineSnapshot (
176+ `"Error: Failed to load the deploy config at .wrangler/deploy/config.json"`
170177 ) ;
171178 expect ( std ) . toEqual ( NO_LOGS ) ;
172179 } ) ;
@@ -175,14 +182,21 @@ describe("config findWranglerConfig()", () => {
175182 await seed ( {
176183 [ ".wrangler/deploy/config.json" ] : `{}` ,
177184 } ) ;
178- expect ( ( ) => findWranglerConfig ( "." , { useRedirect : true } ) )
179- . toThrowErrorMatchingInlineSnapshot ( `
180- [Error: A redirect config was found at ".wrangler/deploy/config.json".
181- But this is not valid - the required "configPath" property was not found.
185+
186+ let error ;
187+ try {
188+ findWranglerConfig ( "." , { useRedirect : true } ) ;
189+ } catch ( e ) {
190+ error = e ;
191+ }
192+
193+ expect ( normalizeString ( `${ error } ` ) ) . toMatchInlineSnapshot ( `
194+ "Error: A redirect config was found at \\".wrangler/deploy/config.json\\".
195+ But this is not valid - the required \\"configPath\\" property was not found.
182196 Instead this file contains:
183197 \`\`\`
184198 {}
185- \`\`\`]
199+ \`\`\`"
186200 ` ) ;
187201 expect ( std ) . toEqual ( NO_LOGS ) ;
188202 } ) ;
@@ -191,10 +205,17 @@ describe("config findWranglerConfig()", () => {
191205 await seed ( {
192206 [ ".wrangler/deploy/config.json" ] : `{ "configPath": "missing/wrangler.json" }` ,
193207 } ) ;
194- expect ( ( ) => findWranglerConfig ( "." , { useRedirect : true } ) )
195- . toThrowErrorMatchingInlineSnapshot ( `
196- [Error: There is a redirect configuration at ".wrangler/deploy/config.json".
197- But the config path it points to, ".wrangler/deploy/missing/wrangler.json", does not exist.]
208+
209+ let error ;
210+ try {
211+ findWranglerConfig ( "." , { useRedirect : true } ) ;
212+ } catch ( e ) {
213+ error = e ;
214+ }
215+
216+ expect ( normalizeString ( `${ error } ` ) ) . toMatchInlineSnapshot ( `
217+ "Error: There is a redirect configuration at \\".wrangler/deploy/config.json\\".
218+ But the config path it points to, \\".wrangler/deploy/missing/wrangler.json\\", does not exist."
198219 ` ) ;
199220 expect ( std ) . toEqual ( NO_LOGS ) ;
200221 } ) ;
@@ -209,17 +230,32 @@ describe("config findWranglerConfig()", () => {
209230 [ "bar/.wrangler/deploy/config.json" ] : `{ "configPath": "../../dist/wrangler.json" }` ,
210231 [ `bar/dist/wrangler.json` ] : "DUMMY" ,
211232 } ) ;
212- expect ( ( ) => findWranglerConfig ( "foo/bar" , { useRedirect : true } ) )
213- . toThrowErrorMatchingInlineSnapshot ( `
214- [Error: Found both a user config file at "foo/wrangler.toml"
215- and a redirect config file at "foo/bar/.wrangler/deploy/config.json".
216- But these do not share the same base path so it is not clear which should be used.]
233+
234+ let error ;
235+ try {
236+ findWranglerConfig ( "foo/bar" , { useRedirect : true } ) ;
237+ } catch ( e ) {
238+ error = e ;
239+ }
240+
241+ expect ( normalizeString ( `${ error } ` ) ) . toMatchInlineSnapshot ( `
242+ "Error: Found both a user config file at \\"foo/wrangler.toml\\"
243+ and a redirect config file at \\"foo/bar/.wrangler/deploy/config.json\\".
244+ But these do not share the same base path so it is not clear which should be used."
217245 ` ) ;
218- expect ( ( ) => findWranglerConfig ( "bar/foo" , { useRedirect : true } ) )
219- . toThrowErrorMatchingInlineSnapshot ( `
220- [Error: Found both a user config file at "bar/foo/wrangler.toml"
221- and a redirect config file at "bar/.wrangler/deploy/config.json".
222- But these do not share the same base path so it is not clear which should be used.]
246+ expect ( std ) . toEqual ( NO_LOGS ) ;
247+
248+ try {
249+ error = undefined ;
250+ findWranglerConfig ( "bar/foo" , { useRedirect : true } ) ;
251+ } catch ( e ) {
252+ error = e ;
253+ }
254+
255+ expect ( normalizeString ( `${ error } ` ) ) . toMatchInlineSnapshot ( `
256+ "Error: Found both a user config file at \\"bar/foo/wrangler.toml\\"
257+ and a redirect config file at \\"bar/.wrangler/deploy/config.json\\".
258+ But these do not share the same base path so it is not clear which should be used."
223259 ` ) ;
224260 expect ( std ) . toEqual ( NO_LOGS ) ;
225261 } ) ;
0 commit comments