From 2635d5180c2a774bdede8d31f7fb76e946fe0b51 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Feb 2023 18:12:07 +0000 Subject: [PATCH 1/3] chore(deps): bump @oclif/core from 1.26.2 to 2.2.1 Bumps [@oclif/core](https://github.com/oclif/core) from 1.26.2 to 2.2.1. - [Release notes](https://github.com/oclif/core/releases) - [Changelog](https://github.com/oclif/core/blob/main/CHANGELOG.md) - [Commits](https://github.com/oclif/core/compare/1.26.2...2.2.1) --- updated-dependencies: - dependency-name: "@oclif/core" dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c413e71..a4c20ee 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "@adobe/aio-lib-core-logging": "^2.0.0", "@adobe/aio-lib-env": "^2.0.0", "@adobe/aio-lib-ims": "^6.0.0", - "@oclif/core": "^1.4.0", + "@oclif/core": "^2.2.1", "js-yaml": "^3.13.1" }, "devDependencies": { From ab8f367b0c5cc37915fe3c5b683fe384a4384083 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Mon, 14 Aug 2023 18:02:39 -0700 Subject: [PATCH 2/3] fix oclif2 args, ux, open --- package.json | 3 ++- src/commands/console/open.js | 4 ++-- src/commands/console/org/list.js | 4 ++-- src/commands/console/org/select.js | 14 +++++------ src/commands/console/project/list.js | 4 ++-- src/commands/console/project/select.js | 15 ++++++------ src/commands/console/publickey/delete.js | 15 ++++++------ src/commands/console/publickey/index.js | 4 ++-- src/commands/console/publickey/upload.js | 15 ++++++------ src/commands/console/workspace/download.js | 11 +++++---- src/commands/console/workspace/list.js | 4 ++-- src/commands/console/workspace/select.js | 15 ++++++------ test/commands/console/open.test.js | 24 +++++++------------ test/commands/console/org/index.test.js | 2 +- test/commands/console/org/select.test.js | 4 ++-- test/commands/console/project/index.test.js | 2 +- test/commands/console/project/select.test.js | 8 +++---- test/commands/console/publickey/index.test.js | 6 ++--- .../console/workspace/download.test.js | 10 ++++---- test/commands/console/workspace/index.test.js | 2 +- .../commands/console/workspace/select.test.js | 10 +++++--- 21 files changed, 87 insertions(+), 89 deletions(-) diff --git a/package.json b/package.json index 17cbaad..c583c96 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "@adobe/aio-lib-env": "^2.0.0", "@adobe/aio-lib-ims": "^6.0.0", "@oclif/core": "2.8.12", - "js-yaml": "^4.1.0" + "js-yaml": "^4.1.0", + "open": "^8.4.2" }, "devDependencies": { "@adobe/eslint-config-aio-lib-config": "^2.0.1", diff --git a/src/commands/console/open.js b/src/commands/console/open.js index 0af1b02..21e3c8f 100644 --- a/src/commands/console/open.js +++ b/src/commands/console/open.js @@ -10,7 +10,7 @@ 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 { CliUx } = require('@oclif/core') +const open = require('open') const { OPEN_URLS } = require('../../config') const ConsoleCommand = require('./index') @@ -33,7 +33,7 @@ class OpenCommand extends ConsoleCommand { } } aioLogger.debug(`opening url ${url}`) - CliUx.ux.open(url) + open(url) } } diff --git a/src/commands/console/org/list.js b/src/commands/console/org/list.js index 4214905..4a07e58 100644 --- a/src/commands/console/org/list.js +++ b/src/commands/console/org/list.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. */ const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:org:list', { provider: 'debug' }) -const { Flags, CliUx: { ux: cli } } = require('@oclif/core') +const { Flags, ux } = require('@oclif/core') const { ORG_TYPE_ENTERPRISE } = require('../../../config') const ConsoleCommand = require('../index') @@ -73,7 +73,7 @@ class ListCommand extends ConsoleCommand { header: 'Org Name' } } - cli.table(orgs, columns) + ux.table(orgs, columns) } } diff --git a/src/commands/console/org/select.js b/src/commands/console/org/select.js index 5f37204..2794dac 100644 --- a/src/commands/console/org/select.js +++ b/src/commands/console/org/select.js @@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:org:select', { provider: 'debug' }) +const { Args } = require('@oclif/core') const { CONFIG_KEYS } = require('../../../config') const ConsoleCommand = require('../index') @@ -53,13 +54,12 @@ class SelectCommand extends ConsoleCommand { SelectCommand.description = 'Select an Organization' -SelectCommand.args = [ - { - name: 'orgCode', - required: false, - description: 'Adobe Developer Console Org code' - } -] +SelectCommand.args = { + orgCode: Args.string({ + description: 'Adobe Developer Console Org code', + required: false + }) +} SelectCommand.aliases = [ 'console:org:sel' diff --git a/src/commands/console/project/list.js b/src/commands/console/project/list.js index fefc327..723c16d 100644 --- a/src/commands/console/project/list.js +++ b/src/commands/console/project/list.js @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:project:list', { provider: 'debug' }) -const { Flags, CliUx: { ux: cli } } = require('@oclif/core') +const { Flags, ux } = require('@oclif/core') const ConsoleCommand = require('../index') class ListCommand extends ConsoleCommand { @@ -67,7 +67,7 @@ class ListCommand extends ConsoleCommand { header: 'Title' } } - cli.table(projects, columns) + ux.table(projects, columns) } } diff --git a/src/commands/console/project/select.js b/src/commands/console/project/select.js index ee42013..b0c843a 100644 --- a/src/commands/console/project/select.js +++ b/src/commands/console/project/select.js @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:project:select', { provider: 'debug' }) -const { Flags } = require('@oclif/core') +const { Flags, Args } = require('@oclif/core') const { CONFIG_KEYS } = require('../../../config') const ConsoleCommand = require('../index') @@ -59,13 +59,12 @@ class SelectCommand extends ConsoleCommand { SelectCommand.description = 'Select a Project for the selected Organization' -SelectCommand.args = [ - { - name: 'projectIdOrName', - required: false, - description: 'Adobe Developer Console Project id or Project name' - } -] +SelectCommand.args = { + projectIdOrName: Args.string({ + description: 'Adobe Developer Console Project id or Project name', + required: false + }) +} SelectCommand.flags = { ...ConsoleCommand.flags, diff --git a/src/commands/console/publickey/delete.js b/src/commands/console/publickey/delete.js index faf7023..4573c79 100644 --- a/src/commands/console/publickey/delete.js +++ b/src/commands/console/publickey/delete.js @@ -10,7 +10,7 @@ governing permissions and limitations under the License. */ const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:publickey:list', { provider: 'debug' }) -const { Flags } = require('@oclif/core') +const { Flags, Args } = require('@oclif/core') const { CONFIG_KEYS } = require('../../../config') const ConsoleCommand = require('../index') @@ -83,13 +83,12 @@ DeleteCommand.flags = { }) } -DeleteCommand.args = [ - { - name: 'idOrFingerprint', - required: true, - description: 'The bindingId or the fingerprint of the public key binding to delete' - } -] +DeleteCommand.args = { + idOrFingerprint: Args.string({ + description: 'The bindingId or the fingerprint of the public key binding to delete', + required: true + }) +} DeleteCommand.aliases = [] diff --git a/src/commands/console/publickey/index.js b/src/commands/console/publickey/index.js index 933e0e0..5187cc3 100644 --- a/src/commands/console/publickey/index.js +++ b/src/commands/console/publickey/index.js @@ -9,7 +9,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const { Help, CliUx: { ux: cli } } = require('@oclif/core') +const { Help, ux } = require('@oclif/core') const ConsoleCommand = require('../') class IndexCommand extends ConsoleCommand { @@ -47,7 +47,7 @@ IndexCommand.printBindings = function (bindings) { decorated.expiresString = binding.notAfter ? this.formatExpiry(binding.notAfter) : '' decorateds.push(decorated) }) - cli.table(decorateds, columns) + ux.table(decorateds, columns) } /** diff --git a/src/commands/console/publickey/upload.js b/src/commands/console/publickey/upload.js index 445c15c..02fdc34 100644 --- a/src/commands/console/publickey/upload.js +++ b/src/commands/console/publickey/upload.js @@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const { Flags } = require('@oclif/core') +const { Flags, Args } = require('@oclif/core') const ConsoleCommand = require('../index') const IndexCommand = require('./index') const fs = require('fs') @@ -122,12 +122,11 @@ UploadAndBindCommand.flags = { UploadAndBindCommand.aliases = [] -UploadAndBindCommand.args = [ - { - name: 'file', - required: true, - description: 'Path to public key certificate file in PEM format' - } -] +UploadAndBindCommand.args = { + file: Args.file({ + description: 'Path to public key certificate file in PEM format', + required: true + }) +} module.exports = UploadAndBindCommand diff --git a/src/commands/console/workspace/download.js b/src/commands/console/workspace/download.js index 347a7b4..1c1b2f6 100644 --- a/src/commands/console/workspace/download.js +++ b/src/commands/console/workspace/download.js @@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const { Flags } = require('@oclif/core') +const { Flags, Args } = require('@oclif/core') const path = require('path') const ConsoleCommand = require('../index') const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:workspace:download', { provider: 'debug' }) @@ -102,8 +102,11 @@ DownloadCommand.aliases = [ 'console:ws:dl' ] -DownloadCommand.args = [ - { name: 'destination', required: false, description: 'Output file name or folder name where the Console Workspace configuration file should be saved' } -] +DownloadCommand.args = { + destination: Args.file({ + description: 'Output file name or folder name where the Console Workspace configuration file should be saved', + required: false + }) +} module.exports = DownloadCommand diff --git a/src/commands/console/workspace/list.js b/src/commands/console/workspace/list.js index fa6497b..a8862ac 100644 --- a/src/commands/console/workspace/list.js +++ b/src/commands/console/workspace/list.js @@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const { Flags, CliUx: { ux: cli } } = require('@oclif/core') +const { Flags, ux } = require('@oclif/core') const { CONFIG_KEYS } = require('../../../config') const ConsoleCommand = require('../index') @@ -44,7 +44,7 @@ class ListCommand extends ConsoleCommand { this.printYaml(workspaces) } else { // print formatted result - cli.table(workspaces, { + ux.table(workspaces, { id: { minWidth: 25 }, diff --git a/src/commands/console/workspace/select.js b/src/commands/console/workspace/select.js index 22f7a48..7da6fa9 100644 --- a/src/commands/console/workspace/select.js +++ b/src/commands/console/workspace/select.js @@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const { Flags } = require('@oclif/core') +const { Flags, Args } = require('@oclif/core') const ConsoleCommand = require('../index') const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:workspace:select', { provider: 'debug' }) const { CONFIG_KEYS } = require('../../../config') @@ -84,12 +84,11 @@ SelectCommand.flags = { }) } -SelectCommand.args = [ - { - name: 'workspaceIdOrName', - required: false, - description: 'Adobe Developer Console Workspace id or Workspace name' - } -] +SelectCommand.args = { + workspaceIdOrName: Args.string({ + description: 'Adobe Developer Console Workspace id or Workspace name', + required: false + }) +} module.exports = SelectCommand diff --git a/test/commands/console/open.test.js b/test/commands/console/open.test.js index b0e0d5b..a07f34d 100644 --- a/test/commands/console/open.test.js +++ b/test/commands/console/open.test.js @@ -12,18 +12,10 @@ governing permissions and limitations under the License. const TestCommand = require('../../../src/commands/console/open') const config = require('@adobe/aio-lib-core-config') const { STAGE_ENV } = require('@adobe/aio-lib-env') +const { Command } = require('@oclif/core') +const open = require('open') -jest.mock('@oclif/core', () => { - return { - ...jest.requireActual('@oclif/core'), - CliUx: { - ux: { - open: jest.fn() - } - } - } -}) -const { Command, CliUx: { ux: cli } } = require('@oclif/core') +jest.mock('open', () => jest.fn()) let command let ORIGINAL_AIO_CLI_ENV @@ -64,19 +56,19 @@ describe('console:open', () => { test('should open a browser', async () => { await expect(command.run()).resolves.not.toThrow() - expect(cli.open).toHaveBeenCalledWith('https://developer.adobe.com/console/projects') + expect(open).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(cli.open).toHaveBeenCalledWith('https://developer-stage.adobe.com/console/projects') + expect(open).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(cli.open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects') + expect(open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects') }) test('should open a browser with project overview', async () => { @@ -90,7 +82,7 @@ describe('console:open', () => { } }) await expect(command.run()).resolves.not.toThrow() - expect(cli.open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/overview') + expect(open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/overview') }) test('should open a browser with project workspace', async () => { @@ -105,6 +97,6 @@ describe('console:open', () => { workspace: { id: '4566206088344859372', name: 'Stage' } }) await expect(command.run()).resolves.not.toThrow() - expect(cli.open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/workspaces/4566206088344859372/details') + expect(open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/workspaces/4566206088344859372/details') }) }) diff --git a/test/commands/console/org/index.test.js b/test/commands/console/org/index.test.js index a59ec15..454cc86 100644 --- a/test/commands/console/org/index.test.js +++ b/test/commands/console/org/index.test.js @@ -23,7 +23,7 @@ test('description', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + expect(TheCommand.args).toStrictEqual({}) }) test('flags', async () => { diff --git a/test/commands/console/org/select.test.js b/test/commands/console/org/select.test.js index 223082f..c032d87 100644 --- a/test/commands/console/org/select.test.js +++ b/test/commands/console/org/select.test.js @@ -56,8 +56,8 @@ test('aliases', async () => { }) test('args', async () => { - const orgCode = SelectCommand.args[0] - expect(orgCode.name).toEqual('orgCode') + expect(SelectCommand.args.orgCode).toBeDefined() + const orgCode = SelectCommand.args.orgCode expect(orgCode.required).toEqual(false) expect(orgCode.description).toBeDefined() }) diff --git a/test/commands/console/project/index.test.js b/test/commands/console/project/index.test.js index e88e6be..9ce5ffc 100644 --- a/test/commands/console/project/index.test.js +++ b/test/commands/console/project/index.test.js @@ -23,7 +23,7 @@ test('description', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + expect(TheCommand.args).toStrictEqual({}) }) test('flags', async () => { diff --git a/test/commands/console/project/select.test.js b/test/commands/console/project/select.test.js index 9704d22..ccbc3ff 100644 --- a/test/commands/console/project/select.test.js +++ b/test/commands/console/project/select.test.js @@ -77,10 +77,10 @@ test('aliases', async () => { }) test('args', async () => { - const projectId = SelectCommand.args[0] - expect(projectId.name).toEqual('projectIdOrName') - expect(projectId.required).toEqual(false) - expect(projectId.description).toBeDefined() + expect(SelectCommand.args.projectIdOrName).toBeDefined() + const projectIdOrName = SelectCommand.args.projectIdOrName + expect(projectIdOrName.required).toEqual(false) + expect(projectIdOrName.description).toBeDefined() }) test('flags', async () => { diff --git a/test/commands/console/publickey/index.test.js b/test/commands/console/publickey/index.test.js index b933fcd..c1c1d86 100644 --- a/test/commands/console/publickey/index.test.js +++ b/test/commands/console/publickey/index.test.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. const TheCommand = require('../../../../src/commands/console/publickey') const ConsoleCommand = require('../../../../src/commands/console') -const { Help, CliUx: { ux: cli } } = require('@oclif/core') +const { Help, ux } = require('@oclif/core') test('exports', async () => { expect(typeof TheCommand).toEqual('function') @@ -23,7 +23,7 @@ test('description', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + expect(TheCommand.args).toStrictEqual({}) }) test('flags', async () => { @@ -39,7 +39,7 @@ test('formatExpiry', async () => { test('printBindings', async () => { expect(typeof TheCommand.printBindings).toEqual('function') const spyFormatExpiry = jest.spyOn(TheCommand, 'formatExpiry') - const spyTable = jest.spyOn(cli, 'table') + const spyTable = jest.spyOn(ux, 'table') const bindingWithExpires = { bindingId: 'testBinding1', orgId: 'testOrgId', diff --git a/test/commands/console/workspace/download.test.js b/test/commands/console/workspace/download.test.js index 2999500..95407b8 100644 --- a/test/commands/console/workspace/download.test.js +++ b/test/commands/console/workspace/download.test.js @@ -8,9 +8,10 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const fs = require('fs') -const { stdout } = require('stdout-stderr') + const { Command } = require('@oclif/core') +const { stdout } = require('stdout-stderr') +const fs = jest.requireActual('fs') const path = require('path') // mock data @@ -93,8 +94,9 @@ test('aliases', async () => { }) test('args', async () => { - const destination = DownloadCommand.args[0] - expect(destination.name).toEqual('destination') + expect(DownloadCommand.args).toBeDefined() + expect(DownloadCommand.args).toBeInstanceOf(Object) + const destination = DownloadCommand.args.destination expect(destination.required).toEqual(false) expect(destination.description).toBeDefined() }) diff --git a/test/commands/console/workspace/index.test.js b/test/commands/console/workspace/index.test.js index bfaee38..323f984 100644 --- a/test/commands/console/workspace/index.test.js +++ b/test/commands/console/workspace/index.test.js @@ -23,7 +23,7 @@ test('description', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + expect(TheCommand.args).toStrictEqual({}) }) test('flags', async () => { diff --git a/test/commands/console/workspace/select.test.js b/test/commands/console/workspace/select.test.js index b55d8ac..72ff5dc 100644 --- a/test/commands/console/workspace/select.test.js +++ b/test/commands/console/workspace/select.test.js @@ -71,9 +71,13 @@ test('aliases', async () => { }) test('args', async () => { - const workspaceId = SelectCommand.args[0] - expect(workspaceId.name).toEqual('workspaceIdOrName') - expect(workspaceId.required).toEqual(false) + expect(SelectCommand.args).toBeDefined() + expect(SelectCommand.args).toBeInstanceOf(Object) + + const workspaceIdOrName = SelectCommand.args.workspaceIdOrName + expect(workspaceIdOrName).toBeDefined() + expect(workspaceIdOrName.description).toEqual('Adobe Developer Console Workspace id or Workspace name') + expect(workspaceIdOrName.required).toEqual(false) }) describe('console:workspace:select', () => { From 7bce3da7813650d76b4c651d0148f887803f538f Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Mon, 14 Aug 2023 18:05:06 -0700 Subject: [PATCH 3/3] all but one test pass without fs mocks --- test/jest.setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jest.setup.js b/test/jest.setup.js index f4c6157..b553466 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -6,7 +6,7 @@ const path = require('path') jest.setTimeout(30000) // don't touch the real fs -jest.mock('fs', () => require('jest-plugin-fs/mock')) +// jest.mock('fs', () => require('jest-plugin-fs/mock')) // clear env variables