@@ -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" , ( ) => {
@@ -67,6 +71,12 @@ describe("Profile", () => {
6771 } ) ;
6872
6973 describe ( "getAuthConfigFilePath" , ( ) => {
74+ it ( "should return default.toml when no profile is active" , ( { expect } ) => {
75+ const filePath = getAuthConfigFilePath ( ) ;
76+ expect ( filePath ) . toContain ( "default.toml" ) ;
77+ expect ( filePath ) . not . toContain ( "profiles" ) ;
78+ } ) ;
79+
7080 it ( "should return default.toml for the default profile" , ( { expect } ) => {
7181 const filePath = getAuthConfigFilePath ( "default" ) ;
7282 expect ( filePath ) . toContain ( "default.toml" ) ;
@@ -82,10 +92,6 @@ describe("Profile", () => {
8292 } ) ;
8393
8494 describe ( "profileExists" , ( ) => {
85- it ( "should always return true for default" , ( { expect } ) => {
86- expect ( profileExists ( "default" ) ) . toBe ( true ) ;
87- } ) ;
88-
8995 it ( "should return false for non-existent profiles" , ( { expect } ) => {
9096 expect ( profileExists ( "nonexistent" ) ) . toBe ( false ) ;
9197 } ) ;
@@ -104,8 +110,8 @@ describe("Profile", () => {
104110 } ) ;
105111
106112 describe ( "getActiveProfileName" , ( ) => {
107- it ( "should return default when nothing is configured" , ( { expect } ) => {
108- expect ( getActiveProfileName ( ) ) . toBe ( "default" ) ;
113+ it ( "should return undefined when nothing is configured" , ( { expect } ) => {
114+ expect ( getActiveProfileName ( ) ) . toBeUndefined ( ) ;
109115 } ) ;
110116
111117 it ( "should respect WRANGLER_PROFILE env var" , ( { expect } ) => {
@@ -451,6 +457,65 @@ describe("Profile", () => {
451457 } ) ;
452458 } ) ;
453459
460+ describe ( "active profile in banner" , ( ) => {
461+ beforeEach ( ( ) => {
462+ msw . use ( ...mswSuccessUserHandlers ) ;
463+ } ) ;
464+
465+ it ( "should print the active profile under the banner" , async ( {
466+ expect,
467+ } ) => {
468+ writeAuthConfigFile (
469+ {
470+ oauth_token : "token" ,
471+ refresh_token : "refresh" ,
472+ expiration_time : "2030-01-01T00:00:00Z" ,
473+ } ,
474+ "work"
475+ ) ;
476+ setActiveProfile ( "work" ) ;
477+
478+ await runWrangler ( "whoami" ) ;
479+
480+ expect ( std . out ) . toContain ( "Using profile: work" ) ;
481+ } ) ;
482+
483+ it ( "should not print the active profile with --json" , async ( {
484+ expect,
485+ } ) => {
486+ writeAuthConfigFile (
487+ {
488+ oauth_token : "token" ,
489+ refresh_token : "refresh" ,
490+ expiration_time : "2030-01-01T00:00:00Z" ,
491+ } ,
492+ "work"
493+ ) ;
494+ setActiveProfile ( "work" ) ;
495+
496+ await runWrangler ( "whoami --json" ) ;
497+
498+ expect ( std . out ) . not . toContain ( "Using profile" ) ;
499+ const output = JSON . parse ( std . out ) ;
500+ expect ( output . loggedIn ) . toBe ( true ) ;
501+ expect ( output . profile ) . toBe ( "work" ) ;
502+ } ) ;
503+
504+ it ( "should not print profile line when using default profile" , async ( {
505+ expect,
506+ } ) => {
507+ writeAuthConfigFile ( {
508+ oauth_token : "token" ,
509+ refresh_token : "refresh" ,
510+ expiration_time : "2030-01-01T00:00:00Z" ,
511+ } ) ;
512+
513+ await runWrangler ( "whoami" ) ;
514+
515+ expect ( std . out ) . not . toContain ( "Using profile" ) ;
516+ } ) ;
517+ } ) ;
518+
454519 describe ( "wrangler profiles unset" , ( ) => {
455520 it ( "should reset the active profile to default" , async ( { expect } ) => {
456521 writeAuthConfigFile (
@@ -466,7 +531,7 @@ describe("Profile", () => {
466531
467532 await runWrangler ( "profiles unset" ) ;
468533
469- expect ( getActiveProfileName ( ) ) . toBe ( "default" ) ;
534+ expect ( getActiveProfileName ( ) ) . toBeUndefined ( ) ;
470535 expect ( std . out ) . toContain (
471536 'Switched from profile "work" back to the default profile.'
472537 ) ;
0 commit comments