@@ -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 } ) => {
@@ -418,6 +424,65 @@ describe("Profile", () => {
418424 } ) ;
419425 } ) ;
420426
427+ describe ( "active profile in banner" , ( ) => {
428+ beforeEach ( ( ) => {
429+ msw . use ( ...mswSuccessUserHandlers ) ;
430+ } ) ;
431+
432+ it ( "should print the active profile under the banner" , async ( {
433+ expect,
434+ } ) => {
435+ writeAuthConfigFile (
436+ {
437+ oauth_token : "token" ,
438+ refresh_token : "refresh" ,
439+ expiration_time : "2030-01-01T00:00:00Z" ,
440+ } ,
441+ "work"
442+ ) ;
443+ setActiveProfile ( "work" ) ;
444+
445+ await runWrangler ( "whoami" ) ;
446+
447+ expect ( std . out ) . toContain ( "Using profile: work" ) ;
448+ } ) ;
449+
450+ it ( "should not print the active profile with --json" , async ( {
451+ expect,
452+ } ) => {
453+ writeAuthConfigFile (
454+ {
455+ oauth_token : "token" ,
456+ refresh_token : "refresh" ,
457+ expiration_time : "2030-01-01T00:00:00Z" ,
458+ } ,
459+ "work"
460+ ) ;
461+ setActiveProfile ( "work" ) ;
462+
463+ await runWrangler ( "whoami --json" ) ;
464+
465+ expect ( std . out ) . not . toContain ( "Using profile" ) ;
466+ const output = JSON . parse ( std . out ) ;
467+ expect ( output . loggedIn ) . toBe ( true ) ;
468+ expect ( output . profile ) . toBe ( "work" ) ;
469+ } ) ;
470+
471+ it ( "should not print profile line when using default profile" , async ( {
472+ expect,
473+ } ) => {
474+ writeAuthConfigFile ( {
475+ oauth_token : "token" ,
476+ refresh_token : "refresh" ,
477+ expiration_time : "2030-01-01T00:00:00Z" ,
478+ } ) ;
479+
480+ await runWrangler ( "whoami" ) ;
481+
482+ expect ( std . out ) . not . toContain ( "Using profile" ) ;
483+ } ) ;
484+ } ) ;
485+
421486 describe ( "wrangler profiles unset" , ( ) => {
422487 it ( "should reset the active profile to default" , async ( { expect } ) => {
423488 writeAuthConfigFile (
@@ -433,7 +498,7 @@ describe("Profile", () => {
433498
434499 await runWrangler ( "profiles unset" ) ;
435500
436- expect ( getActiveProfileName ( ) ) . toBe ( "default" ) ;
501+ expect ( getActiveProfileName ( ) ) . toBeUndefined ( ) ;
437502 expect ( std . out ) . toContain (
438503 'Switched from profile "work" back to the default profile.'
439504 ) ;
0 commit comments