11import { crash } from "@cloudflare/cli" ;
2- import { processArgument } from "@cloudflare/cli/args " ;
2+ import { inputPrompt } from "@cloudflare/cli/interactive " ;
33import { mockPackageManager , mockSpinner } from "helpers/__tests__/mocks" ;
44import { runCommand } from "helpers/command" ;
55import { readFile } from "helpers/files" ;
@@ -10,7 +10,6 @@ import { createTestContext } from "./helpers";
1010
1111vi . mock ( "helpers/command" ) ;
1212vi . mock ( "../wrangler/accounts" ) ;
13- vi . mock ( "@cloudflare/cli/args" ) ;
1413vi . mock ( "@cloudflare/cli/interactive" ) ;
1514vi . mock ( "which-pm-runs" ) ;
1615vi . mock ( "@cloudflare/cli" ) ;
@@ -33,16 +32,24 @@ const mockInsideGitRepo = (isInside = true) => {
3332describe ( "deploy helpers" , async ( ) => {
3433 beforeEach ( ( ) => {
3534 mockPackageManager ( "npm" ) ;
36-
3735 mockSpinner ( ) ;
36+ vi . mocked ( inputPrompt ) . mockImplementation ( async ( options ) => {
37+ if ( options . acceptDefault ) {
38+ return options . defaultValue ;
39+ }
40+
41+ throw new Error (
42+ "If you don't want to accept the default, you must mock this function." ,
43+ ) ;
44+ } ) ;
3845 } ) ;
3946
4047 describe ( "offerToDeploy" , async ( ) => {
4148 test ( "user selects yes and succeeds" , async ( ) => {
4249 const ctx = createTestContext ( ) ;
4350 ctx . template . platform = "pages" ;
4451 // mock the user selecting yes when asked to deploy
45- vi . mocked ( processArgument ) . mockResolvedValueOnce ( true ) ;
52+ vi . mocked ( inputPrompt ) . mockResolvedValueOnce ( true ) ;
4653 // mock a successful wrangler login
4754 vi . mocked ( wranglerLogin ) . mockResolvedValueOnce ( true ) ;
4855
@@ -55,7 +62,7 @@ describe("deploy helpers", async () => {
5562 vi . mocked ( readFile ) . mockReturnValue ( `binding = "MY_QUEUE"` ) ;
5663
5764 await expect ( offerToDeploy ( ctx ) ) . resolves . toBe ( false ) ;
58- expect ( processArgument ) . toHaveBeenCalledOnce ( ) ;
65+ expect ( inputPrompt ) . toHaveBeenCalledOnce ( ) ;
5966 expect ( ctx . args . deploy ) . toBe ( false ) ;
6067 expect ( wranglerLogin ) . not . toHaveBeenCalled ( ) ;
6168 } ) ;
@@ -72,7 +79,7 @@ describe("deploy helpers", async () => {
7279 ` ) ;
7380
7481 await expect ( offerToDeploy ( ctx ) ) . resolves . toBe ( false ) ;
75- expect ( processArgument ) . toHaveBeenCalledOnce ( ) ;
82+ expect ( inputPrompt ) . toHaveBeenCalledOnce ( ) ;
7683 expect ( ctx . args . deploy ) . toBe ( false ) ;
7784 expect ( wranglerLogin ) . not . toHaveBeenCalled ( ) ;
7885 } ) ;
@@ -83,13 +90,13 @@ describe("deploy helpers", async () => {
8390 experimental_assets = { directory = "./dist", binding = "ASSETS" }
8491 ` ) ;
8592 // mock the user selecting yes when asked to deploy
86- vi . mocked ( processArgument ) . mockResolvedValueOnce ( true ) ;
93+ vi . mocked ( inputPrompt ) . mockResolvedValueOnce ( true ) ;
8794 // mock a successful wrangler login
8895 vi . mocked ( wranglerLogin ) . mockResolvedValueOnce ( true ) ;
8996
9097 await expect ( offerToDeploy ( ctx ) ) . resolves . toBe ( true ) ;
91- expect ( processArgument ) . toHaveBeenCalledOnce ( ) ;
92- expect ( ctx . args . deploy ) . toBe ( false ) ;
98+ expect ( inputPrompt ) . toHaveBeenCalledOnce ( ) ;
99+ expect ( ctx . args . deploy ) . toBe ( true ) ;
93100 expect ( wranglerLogin ) . toHaveBeenCalled ( ) ;
94101 } ) ;
95102
@@ -99,15 +106,15 @@ describe("deploy helpers", async () => {
99106 ctx . template . platform = "pages" ;
100107
101108 await expect ( offerToDeploy ( ctx ) ) . resolves . toBe ( false ) ;
102- expect ( processArgument ) . toHaveBeenCalledOnce ( ) ;
109+ expect ( inputPrompt ) . toHaveBeenCalledOnce ( ) ;
103110 expect ( ctx . args . deploy ) . toBe ( false ) ;
104111 expect ( wranglerLogin ) . not . toHaveBeenCalled ( ) ;
105112 } ) ;
106113
107114 test ( "wrangler login failure" , async ( ) => {
108115 const ctx = createTestContext ( ) ;
109116 ctx . template . platform = "pages" ;
110- vi . mocked ( processArgument ) . mockResolvedValueOnce ( true ) ;
117+ vi . mocked ( inputPrompt ) . mockResolvedValueOnce ( true ) ;
111118 vi . mocked ( wranglerLogin ) . mockResolvedValueOnce ( false ) ;
112119
113120 await expect ( offerToDeploy ( ctx ) ) . resolves . toBe ( false ) ;
0 commit comments