Skip to content

Commit 367ca58

Browse files
authored
Merge pull request #239 from adobe/esm-open-fix
Fix require() of ES Module error
2 parents 64706a7 + bbaef7d commit 367ca58

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/commands/console/open.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ governing permissions and limitations under the License.
1111
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:open', { provider: 'debug' })
1212
const { getCliEnv } = require('@adobe/aio-lib-env')
1313
const { OPEN_URLS } = require('../../config')
14-
const open = require('open')
1514
const ConsoleCommand = require('./index')
1615
class OpenCommand extends ConsoleCommand {
1716
async run () {
@@ -32,6 +31,8 @@ class OpenCommand extends ConsoleCommand {
3231
}
3332
}
3433
aioLogger.debug(`opening url ${url}`)
34+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
35+
const { default: open } = await import('open')
3536
open(url)
3637
}
3738
}

test/commands/console/open.test.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ const TestCommand = require('../../../src/commands/console/open')
1313
const config = require('@adobe/aio-lib-core-config')
1414
const { 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+
}))
1720
const { Command } = require('@oclif/core')
18-
const open = require('open')
1921

2022
let command
2123
let ORIGINAL_AIO_CLI_ENV
@@ -24,6 +26,7 @@ beforeAll(() => {
2426
})
2527
beforeEach(() => {
2628
config.get.mockReset()
29+
mockOpen.mockReset()
2730
command = new TestCommand([])
2831
})
2932
afterEach(() => {
@@ -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

Comments
 (0)