diff --git a/package.json b/package.json index 4facd99..76d0599 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,9 @@ "@adobe/aio-lib-core-logging": "^3", "@adobe/aio-lib-env": "^3", "@adobe/aio-lib-ims": "^7", - "@oclif/core": "^1.4.0", - "js-yaml": "^4.1.0" + "@oclif/core": "^2.0.0", + "js-yaml": "^4.1.0", + "open": "^10.2.0" }, "devDependencies": { "@adobe/eslint-config-aio-lib-config": "^4.0.0", @@ -34,7 +35,6 @@ "jest": "^29", "jest-haste-map": "^29.6.1", "jest-junit": "^16.0.0", - "jest-plugin-fs": "^2.9.0", "oclif": "^4.17.13", "stdout-stderr": "^0.1.9" }, @@ -69,7 +69,7 @@ "scripts": { "eslint": "eslint src test e2e", "test": "npm run unit-tests && npm run eslint", - "unit-tests": "jest --ci -w=2", + "unit-tests": "node --experimental-vm-modules node_modules/jest/bin/jest.js --ci -w=2", "prepack": "oclif manifest && oclif readme --no-aliases", "postpack": "rm -f oclif.manifest.json", "version": "oclif readme && git add README.md", diff --git a/src/commands/console/open.js b/src/commands/console/open.js index 0af1b02..c0f1a8b 100644 --- a/src/commands/console/open.js +++ b/src/commands/console/open.js @@ -10,9 +10,8 @@ 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_URLS } = require('../../config') - +const open = require('open') const ConsoleCommand = require('./index') class OpenCommand extends ConsoleCommand { async run () { @@ -33,7 +32,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..d48431e 100644 --- a/src/commands/console/org/select.js +++ b/src/commands/console/org/select.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:select', { provider: 'debug' }) const { CONFIG_KEYS } = require('../../../config') - +const { Args } = require('@oclif/core') const ConsoleCommand = require('../index') class SelectCommand extends ConsoleCommand { @@ -53,13 +53,12 @@ class SelectCommand extends ConsoleCommand { SelectCommand.description = 'Select an Organization' -SelectCommand.args = [ - { - name: 'orgCode', +SelectCommand.args = { + orgCode: Args.string({ required: false, description: 'Adobe Developer Console Org code' - } -] + }) +} 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 c99c949..68a954d 100644 --- a/src/commands/console/project/select.js +++ b/src/commands/console/project/select.js @@ -10,9 +10,8 @@ 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') class SelectCommand extends ConsoleCommand { @@ -59,13 +58,12 @@ class SelectCommand extends ConsoleCommand { SelectCommand.description = 'Select a Project for the selected Organization' -SelectCommand.args = [ - { - name: 'projectIdOrName', +SelectCommand.args = { + projectIdOrName: Args.string({ required: false, description: 'Adobe Developer Console Project id or Project name' - } -] + }) +} SelectCommand.flags = { ...ConsoleCommand.flags, diff --git a/src/commands/console/publickey/delete.js b/src/commands/console/publickey/delete.js index faf7023..e1b1746 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', +DeleteCommand.args = { + idOrFingerprint: Args.string({ required: true, description: 'The bindingId or the fingerprint of the public key binding to delete' - } -] + }) +} 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..a275c98 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', +UploadAndBindCommand.args = { + file: Args.string({ required: true, description: 'Path to public key certificate file in PEM format' - } -] + }) +} module.exports = UploadAndBindCommand diff --git a/src/commands/console/workspace/download.js b/src/commands/console/workspace/download.js index 347a7b4..efe04d6 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.string({ + required: false, + description: 'Output file name or folder name where the Console Workspace configuration file should be saved' + }) +} 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..46ca0df 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', +SelectCommand.args = { + workspaceIdOrName: Args.string({ required: false, description: 'Adobe Developer Console Workspace id or Workspace name' - } -] + }) +} module.exports = SelectCommand diff --git a/test/commands/console/open.test.js b/test/commands/console/open.test.js index b0e0d5b..f229d9a 100644 --- a/test/commands/console/open.test.js +++ b/test/commands/console/open.test.js @@ -13,17 +13,9 @@ 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('@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()) +const { Command } = require('@oclif/core') +const open = require('open') 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..c75891b 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).toEqual({}) }) test('flags', async () => { diff --git a/test/commands/console/org/select.test.js b/test/commands/console/org/select.test.js index 223082f..0c9a80b 100644 --- a/test/commands/console/org/select.test.js +++ b/test/commands/console/org/select.test.js @@ -56,8 +56,7 @@ test('aliases', async () => { }) test('args', async () => { - const orgCode = SelectCommand.args[0] - expect(orgCode.name).toEqual('orgCode') + 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..25036a7 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).toEqual({}) }) test('flags', async () => { diff --git a/test/commands/console/project/select.test.js b/test/commands/console/project/select.test.js index 9704d22..8745f3c 100644 --- a/test/commands/console/project/select.test.js +++ b/test/commands/console/project/select.test.js @@ -77,8 +77,7 @@ test('aliases', async () => { }) test('args', async () => { - const projectId = SelectCommand.args[0] - expect(projectId.name).toEqual('projectIdOrName') + const projectId = SelectCommand.args.projectIdOrName expect(projectId.required).toEqual(false) expect(projectId.description).toBeDefined() }) diff --git a/test/commands/console/publickey/index.test.js b/test/commands/console/publickey/index.test.js index b933fcd..bba2906 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).toEqual({}) }) 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/publickey/upload.test.js b/test/commands/console/publickey/upload.test.js index 7a8f72b..7b58267 100644 --- a/test/commands/console/publickey/upload.test.js +++ b/test/commands/console/publickey/upload.test.js @@ -56,22 +56,27 @@ jest.mock('@adobe/aio-cli-lib-console', () => ({ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance), cleanStdOut: jest.fn() })) -jest.spyOn(fs, 'statSync').mockImplementation(file => { - if (file === 'certificate_pub.crt') { - return { isFile: () => { return true } } - } else if (file === 'a_directory') { - return { isFile: () => { return false } } - } else { - throw new Error('file does not exist') - } -}) -jest.spyOn(fs, 'readFileSync').mockImplementation(file => { - if (file === 'certificate_pub.crt') { - return Buffer.from('a PEM encoded cert') - } else { - throw new Error('dOEs NoT c()MUPt3') - } -}) + +const realStatSync = fs.statSync +const realReadFileSync = fs.readFileSync +const mockStatSync = jest.spyOn(fs, 'statSync') +const mockReadFileSync = jest.spyOn(fs, 'readFileSync') + +/** @private */ +function setDefaultMockFs () { + mockStatSync.mockReset().mockImplementation(file => { + const fileStr = String(file) + if (fileStr === 'certificate_pub.crt') return { isFile: () => true } + if (fileStr === 'a_directory') return { isFile: () => false } + return realStatSync(file) + }) + + mockReadFileSync.mockReset().mockImplementation(file => { + const fileStr = String(file) + if (fileStr === 'certificate_pub.crt') return Buffer.from('a PEM encoded cert') + return realReadFileSync(file) + }) +} const UploadAndBindCommand = require('../../../../src/commands/console/publickey/upload') @@ -120,6 +125,7 @@ describe('console:publickey:upload', () => { beforeEach(() => { setDefaultMockConsoleCLI() setDefaultMockConfigGet() + setDefaultMockFs() config.set.mockReset() command = new UploadAndBindCommand([]) }) diff --git a/test/commands/console/workspace/download.test.js b/test/commands/console/workspace/download.test.js index c831171..9e6231b 100644 --- a/test/commands/console/workspace/download.test.js +++ b/test/commands/console/workspace/download.test.js @@ -93,8 +93,7 @@ test('aliases', async () => { }) test('args', async () => { - const destination = DownloadCommand.args[0] - expect(destination.name).toEqual('destination') + 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..cc9151f 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).toEqual({}) }) test('flags', async () => { diff --git a/test/commands/console/workspace/select.test.js b/test/commands/console/workspace/select.test.js index b55d8ac..03b4d7c 100644 --- a/test/commands/console/workspace/select.test.js +++ b/test/commands/console/workspace/select.test.js @@ -71,9 +71,9 @@ test('aliases', async () => { }) test('args', async () => { - const workspaceId = SelectCommand.args[0] - expect(workspaceId.name).toEqual('workspaceIdOrName') + const workspaceId = SelectCommand.args.workspaceIdOrName expect(workspaceId.required).toEqual(false) + expect(workspaceId.description).toBeDefined() }) describe('console:workspace:select', () => { diff --git a/test/jest.setup.js b/test/jest.setup.js index f4c6157..0af910f 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -5,9 +5,6 @@ const path = require('path') jest.setTimeout(30000) -// don't touch the real fs -jest.mock('fs', () => require('jest-plugin-fs/mock')) - // clear env variables // trap console log