@@ -13,9 +13,11 @@ const TestCommand = require('../../../src/commands/console/open')
1313const config = require ( '@adobe/aio-lib-core-config' )
1414const { STAGE_ENV } = require ( '@adobe/aio-lib-env' )
1515
16- jest . mock ( 'open' , ( ) => jest . fn ( ) )
16+ const mockOpen = jest . fn ( )
17+ jest . unstable_mockModule ( 'open' , ( ) => ( {
18+ default : mockOpen
19+ } ) )
1720const { Command } = require ( '@oclif/core' )
18- const open = require ( 'open' )
1921
2022let command
2123let ORIGINAL_AIO_CLI_ENV
@@ -24,6 +26,7 @@ beforeAll(() => {
2426} )
2527beforeEach ( ( ) => {
2628 config . get . mockReset ( )
29+ mockOpen . mockReset ( )
2730 command = new TestCommand ( [ ] )
2831} )
2932afterEach ( ( ) => {
@@ -56,19 +59,19 @@ describe('console:open', () => {
5659
5760 test ( 'should open a browser' , async ( ) => {
5861 await expect ( command . run ( ) ) . resolves . not . toThrow ( )
59- expect ( open ) . toHaveBeenCalledWith ( 'https://developer.adobe.com/console/projects' )
62+ expect ( mockOpen ) . toHaveBeenCalledWith ( 'https://developer.adobe.com/console/projects' )
6063 } )
6164
6265 test ( 'should open a browser (stage_env)' , async ( ) => {
6366 process . env . AIO_CLI_ENV = STAGE_ENV
6467 await expect ( command . run ( ) ) . resolves . not . toThrow ( )
65- expect ( open ) . toHaveBeenCalledWith ( 'https://developer-stage.adobe.com/console/projects' )
68+ expect ( mockOpen ) . toHaveBeenCalledWith ( 'https://developer-stage.adobe.com/console/projects' )
6669 } )
6770
6871 test ( 'should open a browser with default view if no project/workspace selected' , async ( ) => {
6972 config . get . mockReturnValue ( null )
7073 await expect ( command . run ( ) ) . resolves . not . toThrow ( )
71- expect ( open ) . toHaveBeenLastCalledWith ( 'https://developer.adobe.com/console/projects' )
74+ expect ( mockOpen ) . toHaveBeenLastCalledWith ( 'https://developer.adobe.com/console/projects' )
7275 } )
7376
7477 test ( 'should open a browser with project overview' , async ( ) => {
@@ -82,7 +85,7 @@ describe('console:open', () => {
8285 }
8386 } )
8487 await expect ( command . run ( ) ) . resolves . not . toThrow ( )
85- expect ( open ) . toHaveBeenLastCalledWith ( 'https://developer.adobe.com/console/projects/53444/4566206088344853970/overview' )
88+ expect ( mockOpen ) . toHaveBeenLastCalledWith ( 'https://developer.adobe.com/console/projects/53444/4566206088344853970/overview' )
8689 } )
8790
8891 test ( 'should open a browser with project workspace' , async ( ) => {
@@ -97,6 +100,6 @@ describe('console:open', () => {
97100 workspace : { id : '4566206088344859372' , name : 'Stage' }
98101 } )
99102 await expect ( command . run ( ) ) . resolves . not . toThrow ( )
100- expect ( open ) . toHaveBeenLastCalledWith ( 'https://developer.adobe.com/console/projects/53444/4566206088344853970/workspaces/4566206088344859372/details' )
103+ expect ( mockOpen ) . toHaveBeenLastCalledWith ( 'https://developer.adobe.com/console/projects/53444/4566206088344853970/workspaces/4566206088344859372/details' )
101104 } )
102105} )
0 commit comments