Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/commands/console/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ governing permissions and limitations under the License.
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:open', { provider: 'debug' })
const { getCliEnv } = require('@adobe/aio-lib-env')
const { OPEN_URLS } = require('../../config')
const open = require('open')
const ConsoleCommand = require('./index')
class OpenCommand extends ConsoleCommand {
async run () {
Expand All @@ -32,6 +31,8 @@ class OpenCommand extends ConsoleCommand {
}
}
aioLogger.debug(`opening url ${url}`)
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const { default: open } = await import('open')
open(url)
}
}
Expand Down
17 changes: 10 additions & 7 deletions test/commands/console/open.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const TestCommand = require('../../../src/commands/console/open')
const config = require('@adobe/aio-lib-core-config')
const { STAGE_ENV } = require('@adobe/aio-lib-env')

jest.mock('open', () => jest.fn())
const mockOpen = jest.fn()
jest.unstable_mockModule('open', () => ({
default: mockOpen
}))
const { Command } = require('@oclif/core')
const open = require('open')

let command
let ORIGINAL_AIO_CLI_ENV
Expand All @@ -24,6 +26,7 @@ beforeAll(() => {
})
beforeEach(() => {
config.get.mockReset()
mockOpen.mockReset()
command = new TestCommand([])
})
afterEach(() => {
Expand Down Expand Up @@ -56,19 +59,19 @@ describe('console:open', () => {

test('should open a browser', async () => {
await expect(command.run()).resolves.not.toThrow()
expect(open).toHaveBeenCalledWith('https://developer.adobe.com/console/projects')
expect(mockOpen).toHaveBeenCalledWith('https://developer.adobe.com/console/projects')
})

test('should open a browser (stage_env)', async () => {
process.env.AIO_CLI_ENV = STAGE_ENV
await expect(command.run()).resolves.not.toThrow()
expect(open).toHaveBeenCalledWith('https://developer-stage.adobe.com/console/projects')
expect(mockOpen).toHaveBeenCalledWith('https://developer-stage.adobe.com/console/projects')
})

test('should open a browser with default view if no project/workspace selected', async () => {
config.get.mockReturnValue(null)
await expect(command.run()).resolves.not.toThrow()
expect(open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects')
expect(mockOpen).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects')
})

test('should open a browser with project overview', async () => {
Expand All @@ -82,7 +85,7 @@ describe('console:open', () => {
}
})
await expect(command.run()).resolves.not.toThrow()
expect(open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/overview')
expect(mockOpen).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/overview')
})

test('should open a browser with project workspace', async () => {
Expand All @@ -97,6 +100,6 @@ describe('console:open', () => {
workspace: { id: '4566206088344859372', name: 'Stage' }
})
await expect(command.run()).resolves.not.toThrow()
expect(open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/workspaces/4566206088344859372/details')
expect(mockOpen).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/workspaces/4566206088344859372/details')
})
})