diff --git a/__tests__/commands/phpmyadmin.ts b/__tests__/commands/phpmyadmin.ts index e1f1ab1740..e115c376e8 100644 --- a/__tests__/commands/phpmyadmin.ts +++ b/__tests__/commands/phpmyadmin.ts @@ -3,7 +3,6 @@ * External dependencies */ import { beforeEach, describe, expect, it, jest } from '@jest/globals'; -import opn from 'opn'; /** * Internal dependencies @@ -23,7 +22,6 @@ const mutationMock = jest.fn( async () => { } ); jest.mock( '../../src/lib/api' ); -jest.mock( 'opn' ); jest.mocked( API ).mockImplementation( () => { return Promise.resolve( { mutate: mutationMock, @@ -38,6 +36,11 @@ describe( 'commands/PhpMyAdminCommand', () => { const env = { id: 456, jobs: [] }; const tracker = jest.fn() as CommandTracker; const cmd = new PhpMyAdminCommand( app, env, tracker ); + const openUrl = jest.spyOn( cmd, 'openUrl' ); + + beforeEach( () => { + openUrl.mockReset(); + } ); it( 'should generate a URL by calling the right mutation', async () => { await cmd.run(); @@ -50,9 +53,10 @@ describe( 'commands/PhpMyAdminCommand', () => { }, } ); } ); + it( 'should open the generated URL in browser', async () => { await cmd.run(); - expect( opn ).toHaveBeenCalledWith( 'http://test-url.com', { wait: false } ); + expect( openUrl ).toHaveBeenCalledWith( 'http://test-url.com' ); } ); } ); } ); diff --git a/src/commands/phpmyadmin.ts b/src/commands/phpmyadmin.ts index d350a6354e..33ea934725 100644 --- a/src/commands/phpmyadmin.ts +++ b/src/commands/phpmyadmin.ts @@ -4,7 +4,6 @@ import chalk from 'chalk'; import { GraphQLFormattedError } from 'graphql'; import gql from 'graphql-tag'; -import opn from 'opn'; /** * Internal dependencies @@ -66,6 +65,11 @@ export class PhpMyAdminCommand { console.log( msg ); } + async openUrl( url: string ) { + const { default: open } = await import( 'open' ); + void open( url, { wait: false } ); + } + async run( silent = false ) { this.silent = silent; @@ -92,9 +96,7 @@ export class PhpMyAdminCommand { } ); exit.withError( `Failed to generate PhpMyAdmin URL: ${ error.message }` ); } - - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - void opn( url, { wait: false } ); + void this.openUrl( url ); this.log( 'PhpMyAdmin is opened in your default browser.' ); } } diff --git a/src/global.d.ts b/src/global.d.ts deleted file mode 100644 index bb06f98972..0000000000 --- a/src/global.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'opn';