@@ -20,7 +20,11 @@ import { mockConsoleMethods } from "./helpers/mock-console";
2020import { mockConfirm } from "./helpers/mock-dialogs" ;
2121import { useMockIsTTY } from "./helpers/mock-istty" ;
2222import { mockOAuthFlow } from "./helpers/mock-oauth-flow" ;
23- import { msw , mswSuccessOauthHandlers } from "./helpers/msw" ;
23+ import {
24+ msw ,
25+ mswSuccessOauthHandlers ,
26+ mswSuccessUserHandlers ,
27+ } from "./helpers/msw" ;
2428import { runWrangler } from "./helpers/run-wrangler" ;
2529
2630describe ( "Profile" , ( ) => {
@@ -51,6 +55,12 @@ describe("Profile", () => {
5155 } ) ;
5256
5357 describe ( "getAuthConfigFilePath" , ( ) => {
58+ it ( "should return default.toml when no profile is active" , ( { expect } ) => {
59+ const filePath = getAuthConfigFilePath ( ) ;
60+ expect ( filePath ) . toContain ( "default.toml" ) ;
61+ expect ( filePath ) . not . toContain ( "profiles" ) ;
62+ } ) ;
63+
5464 it ( "should return default.toml for the default profile" , ( { expect } ) => {
5565 const filePath = getAuthConfigFilePath ( "default" ) ;
5666 expect ( filePath ) . toContain ( "default.toml" ) ;
@@ -66,10 +76,6 @@ describe("Profile", () => {
6676 } ) ;
6777
6878 describe ( "profileExists" , ( ) => {
69- it ( "should always return true for default" , ( { expect } ) => {
70- expect ( profileExists ( "default" ) ) . toBe ( true ) ;
71- } ) ;
72-
7379 it ( "should return false for non-existent profiles" , ( { expect } ) => {
7480 expect ( profileExists ( "nonexistent" ) ) . toBe ( false ) ;
7581 } ) ;
@@ -88,8 +94,8 @@ describe("Profile", () => {
8894 } ) ;
8995
9096 describe ( "getActiveProfileName" , ( ) => {
91- it ( "should return default when nothing is configured" , ( { expect } ) => {
92- expect ( getActiveProfileName ( ) ) . toBe ( "default" ) ;
97+ it ( "should return undefined when nothing is configured" , ( { expect } ) => {
98+ expect ( getActiveProfileName ( ) ) . toBeUndefined ( ) ;
9399 } ) ;
94100
95101 it ( "should respect WRANGLER_PROFILE env var" , ( { expect } ) => {
@@ -152,7 +158,6 @@ describe("Profile", () => {
152158 } ) ;
153159 expect ( getProfileForDirectory ( dir ) ) . toBe ( "child-profile" ) ;
154160 } ) ;
155-
156161 } ) ;
157162
158163 describe ( "CLI commands" , ( ) => {
@@ -418,6 +423,65 @@ describe("Profile", () => {
418423 } ) ;
419424 } ) ;
420425
426+ describe ( "active profile in banner" , ( ) => {
427+ beforeEach ( ( ) => {
428+ msw . use ( ...mswSuccessUserHandlers ) ;
429+ } ) ;
430+
431+ it ( "should print the active profile under the banner" , async ( {
432+ expect,
433+ } ) => {
434+ writeAuthConfigFile (
435+ {
436+ oauth_token : "token" ,
437+ refresh_token : "refresh" ,
438+ expiration_time : "2030-01-01T00:00:00Z" ,
439+ } ,
440+ "work"
441+ ) ;
442+ setActiveProfile ( "work" ) ;
443+
444+ await runWrangler ( "whoami" ) ;
445+
446+ expect ( std . out ) . toContain ( "Using profile: work" ) ;
447+ } ) ;
448+
449+ it ( "should not print the active profile with --json" , async ( {
450+ expect,
451+ } ) => {
452+ writeAuthConfigFile (
453+ {
454+ oauth_token : "token" ,
455+ refresh_token : "refresh" ,
456+ expiration_time : "2030-01-01T00:00:00Z" ,
457+ } ,
458+ "work"
459+ ) ;
460+ setActiveProfile ( "work" ) ;
461+
462+ await runWrangler ( "whoami --json" ) ;
463+
464+ expect ( std . out ) . not . toContain ( "Using profile" ) ;
465+ const output = JSON . parse ( std . out ) ;
466+ expect ( output . loggedIn ) . toBe ( true ) ;
467+ expect ( output . profile ) . toBe ( "work" ) ;
468+ } ) ;
469+
470+ it ( "should not print profile line when using default profile" , async ( {
471+ expect,
472+ } ) => {
473+ writeAuthConfigFile ( {
474+ oauth_token : "token" ,
475+ refresh_token : "refresh" ,
476+ expiration_time : "2030-01-01T00:00:00Z" ,
477+ } ) ;
478+
479+ await runWrangler ( "whoami" ) ;
480+
481+ expect ( std . out ) . not . toContain ( "Using profile" ) ;
482+ } ) ;
483+ } ) ;
484+
421485 describe ( "wrangler profiles unset" , ( ) => {
422486 it ( "should reset the active profile to default" , async ( { expect } ) => {
423487 writeAuthConfigFile (
@@ -433,7 +497,7 @@ describe("Profile", () => {
433497
434498 await runWrangler ( "profiles unset" ) ;
435499
436- expect ( getActiveProfileName ( ) ) . toBe ( "default" ) ;
500+ expect ( getActiveProfileName ( ) ) . toBeUndefined ( ) ;
437501 expect ( std . out ) . toContain (
438502 'Switched from profile "work" back to the default profile.'
439503 ) ;
0 commit comments