From b346612a48e3f63eb9d4ed1a6c027484a774a815 Mon Sep 17 00:00:00 2001 From: riprajap Date: Tue, 13 Jan 2026 14:01:48 -0800 Subject: [PATCH 1/6] Update @adobe/aio-cli-plugin-runtime to @oclif/core v2 --- package.json | 3 +- src/commands/runtime/action/create.js | 15 ++---- src/commands/runtime/action/delete.js | 11 ++-- src/commands/runtime/action/get.js | 11 ++-- src/commands/runtime/action/invoke.js | 11 ++-- src/commands/runtime/action/list.js | 13 ++--- src/commands/runtime/action/update.js | 14 ++--- src/commands/runtime/activation/get.js | 10 ++-- src/commands/runtime/activation/list.js | 12 ++--- src/commands/runtime/activation/logs.js | 10 ++-- src/commands/runtime/activation/result.js | 10 ++-- src/commands/runtime/api/create.js | 31 +++--------- src/commands/runtime/api/delete.js | 21 ++------ src/commands/runtime/api/get.js | 11 ++-- src/commands/runtime/api/list.js | 24 +++------ src/commands/runtime/namespace/get.js | 10 ++-- src/commands/runtime/namespace/list.js | 4 +- src/commands/runtime/package/bind.js | 14 ++--- src/commands/runtime/package/create.js | 11 ++-- src/commands/runtime/package/delete.js | 9 ++-- src/commands/runtime/package/get.js | 10 ++-- src/commands/runtime/package/list.js | 12 ++--- src/commands/runtime/package/update.js | 10 ++-- src/commands/runtime/property/get.js | 4 +- src/commands/runtime/rule/create.js | 24 +++------ src/commands/runtime/rule/delete.js | 12 ++--- src/commands/runtime/rule/disable.js | 11 ++-- src/commands/runtime/rule/enable.js | 11 ++-- src/commands/runtime/rule/get.js | 11 ++-- src/commands/runtime/rule/list.js | 4 +- src/commands/runtime/rule/status.js | 11 ++-- src/commands/runtime/rule/update.js | 23 +++------ src/commands/runtime/trigger/create.js | 12 ++--- src/commands/runtime/trigger/delete.js | 11 ++-- src/commands/runtime/trigger/fire.js | 12 ++--- src/commands/runtime/trigger/get.js | 11 ++-- src/commands/runtime/trigger/list.js | 4 +- src/commands/runtime/trigger/update.js | 11 ++-- test/jest.setup.js | 62 ++++++++++++++++------- 39 files changed, 202 insertions(+), 319 deletions(-) diff --git a/package.json b/package.json index 98e7758c..96e41068 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "@adobe/aio-lib-env": "^3.0.1", "@adobe/aio-lib-ims": "^8.0.1", "@adobe/aio-lib-runtime": "^7.1.0", - "@oclif/core": "^1.3.0", + "@oclif/core": "^2.8.12", "@types/jest": "^29.5.3", "chalk": "^4.1.2", "dayjs": "^1.10.4", @@ -46,7 +46,6 @@ "execa": "^4.0.0", "jest": "^29.6.2", "jest-junit": "^16.0.0", - "jest-plugin-fs": "^2.9.0", "oclif": "^3.2.0", "stdout-stderr": "^0.1.9" }, diff --git a/src/commands/runtime/action/create.js b/src/commands/runtime/action/create.js index 85e3d0b2..630e7c79 100644 --- a/src/commands/runtime/action/create.js +++ b/src/commands/runtime/action/create.js @@ -13,7 +13,7 @@ governing permissions and limitations under the License. const fs = require('fs') const { createKeyValueArrayFromFlag, createKeyValueArrayFromFile, createComponentsfromSequence, getKeyValueArrayFromMergedParameters } = require('@adobe/aio-lib-runtime').utils const { kindForFileExtension } = require('../../../kinds') -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') const DeployServiceCommand = require('../../../DeployServiceCommand') class ActionCreate extends DeployServiceCommand { @@ -224,15 +224,10 @@ class ActionCreate extends DeployServiceCommand { } } -ActionCreate.args = [ - { - name: 'actionName', - required: true - }, - { - name: 'actionPath' - } -] +ActionCreate.args = { + actionName: Args.string({ required: true }), + actionPath: Args.string({ required: false }) +} ActionCreate.flags = { ...DeployServiceCommand.flags, diff --git a/src/commands/runtime/action/delete.js b/src/commands/runtime/action/delete.js index 4d69aad5..31058523 100644 --- a/src/commands/runtime/action/delete.js +++ b/src/commands/runtime/action/delete.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. */ const DeployServiceCommand = require('../../../DeployServiceCommand') -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class ActionDelete extends DeployServiceCommand { async run () { @@ -29,12 +29,9 @@ class ActionDelete extends DeployServiceCommand { } } -ActionDelete.args = [ - { - name: 'actionName', - required: true - } -] +ActionDelete.args = { + actionName: Args.string({ required: true }) +} ActionDelete.flags = { ...DeployServiceCommand.flags, diff --git a/src/commands/runtime/action/get.js b/src/commands/runtime/action/get.js index 23553f53..00693396 100644 --- a/src/commands/runtime/action/get.js +++ b/src/commands/runtime/action/get.js @@ -13,7 +13,7 @@ governing permissions and limitations under the License. const fs = require('fs') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const { fileExtensionForKind } = require('../../../kinds') -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class ActionGet extends RuntimeBaseCommand { async run () { @@ -93,12 +93,9 @@ class ActionGet extends RuntimeBaseCommand { } } -ActionGet.args = [ - { - name: 'actionName', - required: true - } -] +ActionGet.args = { + actionName: Args.string({ required: true }) +} ActionGet.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/action/invoke.js b/src/commands/runtime/action/invoke.js index 4f0f4968..dd596180 100644 --- a/src/commands/runtime/action/invoke.js +++ b/src/commands/runtime/action/invoke.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') const { getKeyValueObjectFromMergedParameters } = require('@adobe/aio-lib-runtime').utils class ActionInvoke extends RuntimeBaseCommand { @@ -49,12 +49,9 @@ class ActionInvoke extends RuntimeBaseCommand { } } -ActionInvoke.args = [ - { - name: 'actionName', - required: true - } -] +ActionInvoke.args = { + actionName: Args.string({ required: true }) +} ActionInvoke.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/action/list.js b/src/commands/runtime/action/list.js index 87f0bd1c..a9ba0377 100644 --- a/src/commands/runtime/action/list.js +++ b/src/commands/runtime/action/list.js @@ -13,7 +13,7 @@ governing permissions and limitations under the License. const moment = require('dayjs') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const { parsePackageName } = require('@adobe/aio-lib-runtime').utils -const { Flags, CliUx: cli } = require('@oclif/core') +const { Args, Flags, ux } = require('@oclif/core') const decorators = require('../../../decorators').decorators() class ActionList extends RuntimeBaseCommand { @@ -86,7 +86,7 @@ class ActionList extends RuntimeBaseCommand { } } } - cli.ux.table(result, columns) + ux.table(result, columns) } } catch (err) { await this.handleError('failed to list the actions', err) @@ -94,12 +94,9 @@ class ActionList extends RuntimeBaseCommand { } } -ActionList.args = [ - { - name: 'packageName', - required: false - } -] +ActionList.args = { + packageName: Args.string({ required: false }) +} ActionList.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/action/update.js b/src/commands/runtime/action/update.js index fe830c41..a65d8cff 100644 --- a/src/commands/runtime/action/update.js +++ b/src/commands/runtime/action/update.js @@ -11,20 +11,16 @@ governing permissions and limitations under the License. */ const ActionCreate = require('./create') +const { Args } = require('@oclif/core') class ActionUpdate extends ActionCreate { isUpdate () { return true } } -ActionUpdate.args = [ - { - name: 'actionName', - required: true - }, - { - name: 'actionPath' - } -] +ActionUpdate.args = { + actionName: Args.string({ required: true }), + actionPath: Args.string({ required: false }) +} ActionUpdate.flags = ActionCreate.flags diff --git a/src/commands/runtime/activation/get.js b/src/commands/runtime/activation/get.js index a4772f5a..4f5c11ce 100644 --- a/src/commands/runtime/activation/get.js +++ b/src/commands/runtime/activation/get.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 { Args, Flags } = require('@oclif/core') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const { printLogs } = require('@adobe/aio-lib-runtime').utils @@ -45,11 +45,9 @@ class ActivationGet extends RuntimeBaseCommand { } } -ActivationGet.args = [ - { - name: 'activationID' - } -] +ActivationGet.args = { + activationID: Args.string({ required: false }) +} ActivationGet.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/activation/list.js b/src/commands/runtime/activation/list.js index 8e447cc6..6bc54e23 100644 --- a/src/commands/runtime/activation/list.js +++ b/src/commands/runtime/activation/list.js @@ -12,7 +12,7 @@ governing permissions and limitations under the License. const moment = require('dayjs') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags, CliUx: cli } = require('@oclif/core') +const { Args, Flags, ux } = require('@oclif/core') const decorators = require('../../../decorators').decorators() const statusStrings = ['success', 'app error', 'dev error', 'sys error'] @@ -187,7 +187,7 @@ class ActivationList extends RuntimeBaseCommand { } } if (listActivation) { - cli.ux.table(listActivation, columns, { + ux.table(listActivation, columns, { 'no-truncate': true }) } @@ -198,11 +198,9 @@ class ActivationList extends RuntimeBaseCommand { } } -ActivationList.args = [ - { - name: 'action_name' - } -] +ActivationList.args = { + action_name: Args.string({ required: false }) +} ActivationList.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/activation/logs.js b/src/commands/runtime/activation/logs.js index 9c906cb5..57a73868 100644 --- a/src/commands/runtime/activation/logs.js +++ b/src/commands/runtime/activation/logs.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 { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const rtLib = require('@adobe/aio-lib-runtime') const printLogs = rtLib.utils.printLogs @@ -86,11 +86,9 @@ class ActivationLogs extends RuntimeBaseCommand { } } -ActivationLogs.args = [ - { - name: 'activationId' - } -] +ActivationLogs.args = { + activationId: Args.string({ required: false }) +} ActivationLogs.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/activation/result.js b/src/commands/runtime/activation/result.js index 270e7181..0120fde3 100644 --- a/src/commands/runtime/activation/result.js +++ b/src/commands/runtime/activation/result.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 { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') class ActivationResult extends RuntimeBaseCommand { @@ -35,11 +35,9 @@ class ActivationResult extends RuntimeBaseCommand { } } -ActivationResult.args = [ - { - name: 'activationID' - } -] +ActivationResult.args = { + activationID: Args.string({ required: false }) +} ActivationResult.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/api/create.js b/src/commands/runtime/api/create.js index 4d8de262..7734dc19 100644 --- a/src/commands/runtime/api/create.js +++ b/src/commands/runtime/api/create.js @@ -10,7 +10,7 @@ governing permissions and limitations under the License. */ const DeployServiceCommand = require('../../../DeployServiceCommand') -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') const fs = require('fs') class ApiCreate extends DeployServiceCommand { @@ -48,29 +48,12 @@ class ApiCreate extends DeployServiceCommand { } } -ApiCreate.args = [ - { - name: 'basePath', - required: false, - description: 'The base path of the api' - }, - { - name: 'relPath', - required: false, - description: 'The path of the api relative to the base path' - }, - { - name: 'apiVerb', - required: false, - description: 'The http verb', - options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] - }, - { - name: 'action', - required: false, - description: 'The action to call' - } -] +ApiCreate.args = { + basePath: Args.string({ required: false, description: 'The base path of the api' }), + relPath: Args.string({ required: false, description: 'The path of the api relative to the base path' }), + apiVerb: Args.string({ required: false, description: 'The http verb', options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] }), + action: Args.string({ required: false, description: 'The action to call' }) +} ApiCreate.flags = { ...DeployServiceCommand.flags, diff --git a/src/commands/runtime/api/delete.js b/src/commands/runtime/api/delete.js index df0acc91..09eafbce 100644 --- a/src/commands/runtime/api/delete.js +++ b/src/commands/runtime/api/delete.js @@ -31,22 +31,11 @@ class ApiDelete extends DeployServiceCommand { } } -ApiDelete.args = [ - { - name: 'basePathOrApiName', - required: true, - description: 'The base path or api name' - }, - { - name: 'relPath', - description: 'The path of the api relative to the base path' - }, - { - name: 'apiVerb', - description: 'The http verb', - options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] - } -] +ApiDelete.args = { + basePathOrApiName: Args.string({ required: true, description: 'The base path or api name' }), + relPath: Args.string({ required: false, description: 'The path of the api relative to the base path' }), + apiVerb: Args.string({ required: false, description: 'The http verb', options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] }) +} ApiDelete.flags = { ...DeployServiceCommand.flags diff --git a/src/commands/runtime/api/get.js b/src/commands/runtime/api/get.js index f3c32567..96b950ec 100644 --- a/src/commands/runtime/api/get.js +++ b/src/commands/runtime/api/get.js @@ -10,6 +10,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') +const { Args } = require('@oclif/core') // eslint-disable-next-line no-unused-vars class ApiGet extends RuntimeBaseCommand { @@ -30,13 +31,9 @@ class ApiGet extends RuntimeBaseCommand { } } -ApiGet.args = [ - { - name: 'basePathOrApiName', - required: true, - description: 'The base path or api name' - } -] +ApiGet.args = { + basePathOrApiName: Args.string({ required: true, description: 'The base path or api name' }) +} ApiGet.flags = { ...RuntimeBaseCommand.flags diff --git a/src/commands/runtime/api/list.js b/src/commands/runtime/api/list.js index f88ade06..3b75973d 100644 --- a/src/commands/runtime/api/list.js +++ b/src/commands/runtime/api/list.js @@ -10,7 +10,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags, CliUx: cli } = require('@oclif/core') +const { Args, Flags, ux } = require('@oclif/core') /** @private */ function processApi (api) { @@ -66,7 +66,7 @@ class ApiList extends RuntimeBaseCommand { }, data) }) - cli.ux.table(data, { + ux.table(data, { Action: { minWidth: 10 }, Verb: { minWidth: 10 }, APIName: { header: 'API Name', minWidth: 10 }, @@ -83,21 +83,11 @@ class ApiList extends RuntimeBaseCommand { } } -ApiList.args = [ - { - name: 'basePath', - description: 'The base path of the api' - }, - { - name: 'relPath', - description: 'The path of the api relative to the base path' - }, - { - name: 'apiVerb', - description: 'The http verb', - options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] - } -] +ApiList.args = { + basePath: Args.string({ required: false, description: 'The base path of the api' }), + relPath: Args.string({ required: false, description: 'The path of the api relative to the base path' }), + apiVerb: Args.string({ required: false, description: 'The http verb', options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] }) +} ApiList.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/namespace/get.js b/src/commands/runtime/namespace/get.js index 29d588d6..613bf475 100644 --- a/src/commands/runtime/namespace/get.js +++ b/src/commands/runtime/namespace/get.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags, CliUx: cli } = require('@oclif/core') +const { Flags, ux } = require('@oclif/core') /** @private */ function createColumns (columnName) { @@ -79,10 +79,10 @@ class NamespaceGet extends RuntimeBaseCommand { } else { this.log('Entities in namespace:') - cli.ux.table(data.packages, createColumns('packages')) - cli.ux.table(data.actions, createColumns('actions')) - cli.ux.table(data.triggers, createColumns('triggers')) - cli.ux.table(data.rules, createColumns('rules')) + ux.table(data.packages, createColumns('packages')) + ux.table(data.actions, createColumns('actions')) + ux.table(data.triggers, createColumns('triggers')) + ux.table(data.rules, createColumns('rules')) } } catch (err) { await this.handleError('failed to get the data for a namespace', err) diff --git a/src/commands/runtime/namespace/list.js b/src/commands/runtime/namespace/list.js index a2106ee4..1cd804a2 100644 --- a/src/commands/runtime/namespace/list.js +++ b/src/commands/runtime/namespace/list.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags, CliUx: cli } = require('@oclif/core') +const { Flags, ux } = require('@oclif/core') class NamespaceList extends RuntimeBaseCommand { async run () { @@ -29,7 +29,7 @@ class NamespaceList extends RuntimeBaseCommand { get: row => row } } - cli.ux.table(result, columns) + ux.table(result, columns) } } catch (err) { await this.handleError('failed to list namespaces', err) diff --git a/src/commands/runtime/package/bind.js b/src/commands/runtime/package/bind.js index 47aecb10..da3f9011 100644 --- a/src/commands/runtime/package/bind.js +++ b/src/commands/runtime/package/bind.js @@ -42,16 +42,10 @@ class PackageBind extends RuntimeBaseCommand { } } -PackageBind.args = [ - { - name: 'packageName', - required: true - }, - { - name: 'bindPackageName', - required: true - } -] +PackageBind.args = { + packageName: Args.string({ required: true }), + bindPackageName: Args.string({ required: true }) +} PackageBind.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/package/create.js b/src/commands/runtime/package/create.js index baae386f..e878dceb 100644 --- a/src/commands/runtime/package/create.js +++ b/src/commands/runtime/package/create.js @@ -12,7 +12,7 @@ governing permissions and limitations under the License. const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const { getKeyValueArrayFromMergedParameters } = require('@adobe/aio-lib-runtime').utils -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class PackageCreate extends RuntimeBaseCommand { isUpdate () { return false } @@ -59,12 +59,9 @@ class PackageCreate extends RuntimeBaseCommand { } } -PackageCreate.args = [ - { - name: 'packageName', - required: true - } -] +PackageCreate.args = { + packageName: Args.string({ required: true }) +} PackageCreate.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/package/delete.js b/src/commands/runtime/package/delete.js index 0cc603a0..d085335d 100644 --- a/src/commands/runtime/package/delete.js +++ b/src/commands/runtime/package/delete.js @@ -74,12 +74,9 @@ async function recursivelyDeletePackage (ow, pkg) { return ow.packages.delete(pkg) } -PackageDelete.args = [ - { - name: 'packageName', - required: true - } -] +PackageDelete.args = { + packageName: Args.string({ required: true }) +} PackageDelete.flags = { json: Flags.boolean({ diff --git a/src/commands/runtime/package/get.js b/src/commands/runtime/package/get.js index e9de0be1..2f69fced 100644 --- a/src/commands/runtime/package/get.js +++ b/src/commands/runtime/package/get.js @@ -11,6 +11,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') +const { Args } = require('@oclif/core') const { parsePackageName } = require('@adobe/aio-lib-runtime').utils class PackageGet extends RuntimeBaseCommand { @@ -27,12 +28,9 @@ class PackageGet extends RuntimeBaseCommand { } } -PackageGet.args = [ - { - name: 'packageName', - required: true - } -] +PackageGet.args = { + packageName: Args.string({ required: true }) +} PackageGet.flags = { ...RuntimeBaseCommand.flags diff --git a/src/commands/runtime/package/list.js b/src/commands/runtime/package/list.js index bf06c6a0..c2ed66eb 100644 --- a/src/commands/runtime/package/list.js +++ b/src/commands/runtime/package/list.js @@ -12,7 +12,7 @@ governing permissions and limitations under the License. const moment = require('dayjs') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags, CliUx: cli } = require('@oclif/core') +const { Args, Flags, ux } = require('@oclif/core') class PackageList extends RuntimeBaseCommand { async run () { @@ -78,7 +78,7 @@ class PackageList extends RuntimeBaseCommand { get: row => row.name } } - cli.ux.table(result, columns) + ux.table(result, columns) } } catch (err) { await this.handleError('failed to list the packages', err) @@ -114,11 +114,9 @@ PackageList.flags = { }) } -PackageList.args = [ - { - name: 'namespace' - } -] +PackageList.args = { + namespace: Args.string({ required: false }) +} PackageList.description = 'Lists all the Packages' diff --git a/src/commands/runtime/package/update.js b/src/commands/runtime/package/update.js index f49a2a32..27f8d9d8 100644 --- a/src/commands/runtime/package/update.js +++ b/src/commands/runtime/package/update.js @@ -11,17 +11,15 @@ governing permissions and limitations under the License. */ const PackageCreate = require('./create') +const { Args } = require('@oclif/core') class PackageUpdate extends PackageCreate { isUpdate () { return true } } -PackageUpdate.args = [ - { - name: 'packageName', - required: true - } -] +PackageUpdate.args = { + packageName: Args.string({ required: true }) +} PackageUpdate.flags = PackageCreate.flags diff --git a/src/commands/runtime/property/get.js b/src/commands/runtime/property/get.js index 0d5b1b7f..a041de77 100644 --- a/src/commands/runtime/property/get.js +++ b/src/commands/runtime/property/get.js @@ -10,7 +10,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags, CliUx: { ux: cli } } = require('@oclif/core') +const { Flags, ux } = require('@oclif/core') const { createFetch } = require('@adobe/aio-lib-core-networking') const { PropertyKey, PropertyDefault, propertiesFile, PropertyEnv } = require('../../../properties') const debug = require('debug')('aio-cli-plugin-runtime/property') @@ -90,7 +90,7 @@ class PropertyGet extends RuntimeBaseCommand { data.push({ Property: PropertyGet.flags.apibuildno.description, Value: result.buildno }) } } - cli.table(data, + ux.table(data, { Property: { minWidth: 10 }, Value: { minWidth: 20 } diff --git a/src/commands/runtime/rule/create.js b/src/commands/runtime/rule/create.js index e4b29152..58c1b063 100644 --- a/src/commands/runtime/rule/create.js +++ b/src/commands/runtime/rule/create.js @@ -10,7 +10,7 @@ governing permissions and limitations under the License. */ const DeployServiceCommand = require('../../../DeployServiceCommand') -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class RuleCreate extends DeployServiceCommand { isUpdate () { return false } @@ -34,23 +34,11 @@ class RuleCreate extends DeployServiceCommand { RuleCreate.description = 'Create a Rule' -RuleCreate.args = [ - { - name: 'name', - required: true, - description: 'Name of the rule' - }, - { - name: 'trigger', - required: true, - description: 'Name of the trigger' - }, - { - name: 'action', - required: true, - description: 'Name of the action' - } -] +RuleCreate.args = { + name: Args.string({ required: true, description: 'Name of the rule' }), + trigger: Args.string({ required: true, description: 'Name of the trigger' }), + action: Args.string({ required: true, description: 'Name of the action' }) +} RuleCreate.flags = { ...DeployServiceCommand.flags, diff --git a/src/commands/runtime/rule/delete.js b/src/commands/runtime/rule/delete.js index bce60716..bb92b621 100644 --- a/src/commands/runtime/rule/delete.js +++ b/src/commands/runtime/rule/delete.js @@ -10,7 +10,7 @@ governing permissions and limitations under the License. */ const DeployServiceCommand = require('../../../DeployServiceCommand') -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class RuleDelete extends DeployServiceCommand { async run () { @@ -30,13 +30,9 @@ class RuleDelete extends DeployServiceCommand { RuleDelete.description = 'Delete a Rule' -RuleDelete.args = [ - { - name: 'name', - required: true, - description: 'Name of the rule' - } -] +RuleDelete.args = { + name: Args.string({ required: true, description: 'Name of the rule' }) +} RuleDelete.flags = { ...DeployServiceCommand.flags, diff --git a/src/commands/runtime/rule/disable.js b/src/commands/runtime/rule/disable.js index ac23bb2f..3e4490f9 100644 --- a/src/commands/runtime/rule/disable.js +++ b/src/commands/runtime/rule/disable.js @@ -10,6 +10,7 @@ governing permissions and limitations under the License. */ const DeployServiceCommand = require('../../../DeployServiceCommand') +const { Args } = require('@oclif/core') class RuleDisable extends DeployServiceCommand { async run () { @@ -27,13 +28,9 @@ class RuleDisable extends DeployServiceCommand { RuleDisable.description = 'Disable a Rule' -RuleDisable.args = [ - { - name: 'name', - required: true, - description: 'Name of the rule' - } -] +RuleDisable.args = { + name: Args.string({ required: true, description: 'Name of the rule' }) +} RuleDisable.flags = { ...DeployServiceCommand.flags diff --git a/src/commands/runtime/rule/enable.js b/src/commands/runtime/rule/enable.js index 04d10955..85d2086c 100644 --- a/src/commands/runtime/rule/enable.js +++ b/src/commands/runtime/rule/enable.js @@ -10,6 +10,7 @@ governing permissions and limitations under the License. */ const DeployServiceCommand = require('../../../DeployServiceCommand') +const { Args } = require('@oclif/core') class RuleEnable extends DeployServiceCommand { async run () { @@ -27,13 +28,9 @@ class RuleEnable extends DeployServiceCommand { RuleEnable.description = 'Enable a Rule' -RuleEnable.args = [ - { - name: 'name', - required: true, - description: 'Name of the rule' - } -] +RuleEnable.args = { + name: Args.string({ required: true, description: 'Name of the rule' }) +} RuleEnable.flags = { ...DeployServiceCommand.flags diff --git a/src/commands/runtime/rule/get.js b/src/commands/runtime/rule/get.js index fc57e538..c2ddbe86 100644 --- a/src/commands/runtime/rule/get.js +++ b/src/commands/runtime/rule/get.js @@ -10,6 +10,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') +const { Args } = require('@oclif/core') class RuleGet extends RuntimeBaseCommand { async run () { @@ -27,13 +28,9 @@ class RuleGet extends RuntimeBaseCommand { RuleGet.description = 'Retrieves a Rule' -RuleGet.args = [ - { - name: 'name', - required: true, - description: 'Name of the rule' - } -] +RuleGet.args = { + name: Args.string({ required: true, description: 'Name of the rule' }) +} RuleGet.flags = { ...RuntimeBaseCommand.flags diff --git a/src/commands/runtime/rule/list.js b/src/commands/runtime/rule/list.js index 8cbf839b..cbcf4580 100644 --- a/src/commands/runtime/rule/list.js +++ b/src/commands/runtime/rule/list.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. const moment = require('dayjs') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags, CliUx: cli } = require('@oclif/core') +const { Flags, ux } = require('@oclif/core') class RuleList extends RuntimeBaseCommand { async run () { @@ -68,7 +68,7 @@ class RuleList extends RuntimeBaseCommand { get: row => row.name } } - cli.ux.table(resultsWithStatus, columns) + ux.table(resultsWithStatus, columns) } }) return p diff --git a/src/commands/runtime/rule/status.js b/src/commands/runtime/rule/status.js index e23326c3..db502f50 100644 --- a/src/commands/runtime/rule/status.js +++ b/src/commands/runtime/rule/status.js @@ -10,6 +10,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') +const { Args } = require('@oclif/core') class RuleStatus extends RuntimeBaseCommand { async run () { @@ -27,13 +28,9 @@ class RuleStatus extends RuntimeBaseCommand { RuleStatus.description = 'Gets the status of a rule' -RuleStatus.args = [ - { - name: 'name', - required: true, - description: 'Name of the rule' - } -] +RuleStatus.args = { + name: Args.string({ required: true, description: 'Name of the rule' }) +} RuleStatus.flags = { ...RuntimeBaseCommand.flags diff --git a/src/commands/runtime/rule/update.js b/src/commands/runtime/rule/update.js index 1556ba40..0f69dd16 100644 --- a/src/commands/runtime/rule/update.js +++ b/src/commands/runtime/rule/update.js @@ -10,6 +10,7 @@ governing permissions and limitations under the License. */ const RuleCreate = require('./create') +const { Args } = require('@oclif/core') class RuleUpdate extends RuleCreate { isUpdate () { return true } @@ -17,23 +18,11 @@ class RuleUpdate extends RuleCreate { RuleUpdate.description = 'Update a Rule' -RuleUpdate.args = [ - { - name: 'name', - required: true, - description: 'Name of the rule' - }, - { - name: 'trigger', - required: true, - description: 'Name of the trigger' - }, - { - name: 'action', - required: true, - description: 'Name of the action' - } -] +RuleUpdate.args = { + name: Args.string({ required: true, description: 'Name of the rule' }), + trigger: Args.string({ required: true, description: 'Name of the trigger' }), + action: Args.string({ required: true, description: 'Name of the action' }) +} RuleUpdate.flags = RuleCreate.flags diff --git a/src/commands/runtime/trigger/create.js b/src/commands/runtime/trigger/create.js index 5878a66a..f3959850 100644 --- a/src/commands/runtime/trigger/create.js +++ b/src/commands/runtime/trigger/create.js @@ -12,7 +12,7 @@ governing permissions and limitations under the License. const DeployServiceCommand = require('../../../DeployServiceCommand') const { getKeyValueArrayFromMergedParameters } = require('@adobe/aio-lib-runtime').utils -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class TriggerCreate extends DeployServiceCommand { isUpdate () { return false } @@ -53,13 +53,9 @@ class TriggerCreate extends DeployServiceCommand { } } -TriggerCreate.args = [ - { - name: 'triggerName', - required: true, - description: 'The name of the trigger' - } -] +TriggerCreate.args = { + triggerName: Args.string({ required: true, description: 'The name of the trigger' }) +} TriggerCreate.flags = { ...DeployServiceCommand.flags, diff --git a/src/commands/runtime/trigger/delete.js b/src/commands/runtime/trigger/delete.js index 39b22bdd..64a53ffd 100644 --- a/src/commands/runtime/trigger/delete.js +++ b/src/commands/runtime/trigger/delete.js @@ -11,6 +11,7 @@ governing permissions and limitations under the License. */ const DeployServiceCommand = require('../../../DeployServiceCommand') +const { Args } = require('@oclif/core') const { parsePathPattern } = require('@adobe/aio-lib-runtime').utils class TriggerDelete extends DeployServiceCommand { @@ -29,13 +30,9 @@ class TriggerDelete extends DeployServiceCommand { } } -TriggerDelete.args = [ - { - name: 'triggerPath', - required: true, - description: 'The name of the trigger, in the format /NAMESPACE/NAME' - } -] +TriggerDelete.args = { + triggerPath: Args.string({ required: true, description: 'The name of the trigger, in the format /NAMESPACE/NAME' }) +} TriggerDelete.flags = { ...DeployServiceCommand.flags diff --git a/src/commands/runtime/trigger/fire.js b/src/commands/runtime/trigger/fire.js index 531cf322..9dd2b32f 100644 --- a/src/commands/runtime/trigger/fire.js +++ b/src/commands/runtime/trigger/fire.js @@ -12,7 +12,7 @@ governing permissions and limitations under the License. const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const { getKeyValueObjectFromMergedParameters } = require('@adobe/aio-lib-runtime').utils -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class TriggerFire extends RuntimeBaseCommand { async run () { @@ -34,13 +34,9 @@ class TriggerFire extends RuntimeBaseCommand { } } -TriggerFire.args = [ - { - name: 'triggerName', - required: true, - description: 'The name of the trigger' - } -] +TriggerFire.args = { + triggerName: Args.string({ required: true, description: 'The name of the trigger' }) +} TriggerFire.flags = { ...RuntimeBaseCommand.flags, diff --git a/src/commands/runtime/trigger/get.js b/src/commands/runtime/trigger/get.js index 1b5557b4..c1499063 100644 --- a/src/commands/runtime/trigger/get.js +++ b/src/commands/runtime/trigger/get.js @@ -11,6 +11,7 @@ governing permissions and limitations under the License. */ const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') +const { Args } = require('@oclif/core') const { parsePathPattern } = require('@adobe/aio-lib-runtime').utils class TriggerGet extends RuntimeBaseCommand { @@ -34,13 +35,9 @@ TriggerGet.flags = { ...RuntimeBaseCommand.flags } -TriggerGet.args = [ - { - name: 'triggerPath', - required: true, - description: 'The name/path of the trigger, in the format /NAMESPACE/NAME' - } -] +TriggerGet.args = { + triggerPath: Args.string({ required: true, description: 'The name/path of the trigger, in the format /NAMESPACE/NAME' }) +} TriggerGet.description = 'Get a trigger for Adobe I/O Runtime' diff --git a/src/commands/runtime/trigger/list.js b/src/commands/runtime/trigger/list.js index d3dad9df..81179072 100644 --- a/src/commands/runtime/trigger/list.js +++ b/src/commands/runtime/trigger/list.js @@ -12,7 +12,7 @@ governing permissions and limitations under the License. const moment = require('dayjs') const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') -const { Flags, CliUx: cli } = require('@oclif/core') +const { Flags, ux } = require('@oclif/core') class TriggerList extends RuntimeBaseCommand { async run () { @@ -84,7 +84,7 @@ class TriggerList extends RuntimeBaseCommand { get: row => row.name } } - cli.ux.table(resultsWithStatus, columns) + ux.table(resultsWithStatus, columns) } }) } catch (err) { diff --git a/src/commands/runtime/trigger/update.js b/src/commands/runtime/trigger/update.js index 959c5c9b..43335290 100644 --- a/src/commands/runtime/trigger/update.js +++ b/src/commands/runtime/trigger/update.js @@ -11,19 +11,16 @@ governing permissions and limitations under the License. */ const TriggerCreate = require('./create') +const { Args } = require('@oclif/core') const cloneDeep = require('lodash.clonedeep') class TriggerUpdate extends TriggerCreate { isUpdate () { return true } } -TriggerUpdate.args = [ - { - name: 'triggerName', - required: true, - description: 'The name of the trigger' - } -] +TriggerUpdate.args = { + triggerName: Args.string({ required: true, description: 'The name of the trigger' }) +} TriggerUpdate.flags = cloneDeep(TriggerCreate.flags) // TODO: Updating a feed is not supported as per wsk cli. Need to check if we can still support it. diff --git a/test/jest.setup.js b/test/jest.setup.js index 255cb69c..920c83f4 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -17,8 +17,44 @@ const eol = require('eol') jest.setTimeout(30000) jest.useFakeTimers() -// dont touch the real fs -jest.mock('fs', () => require('jest-plugin-fs/mock')) +global.__mockFs = {} +jest.mock('fs', () => { + const actualFs = jest.requireActual('fs') + return { + ...actualFs, + readFileSync: jest.fn((path) => { + if (global.__mockFs[path]) { + return typeof global.__mockFs[path] === 'string' ? global.__mockFs[path] : Buffer.from(global.__mockFs[path]) + } + return actualFs.readFileSync(path) + }), + writeFileSync: jest.fn((path, data) => { + global.__mockFs[path] = data + }), + existsSync: jest.fn((path) => { + return global.__mockFs.hasOwnProperty(path) || actualFs.existsSync(path) + }), + statSync: jest.fn((path) => { + if (global.__mockFs.hasOwnProperty(path)) { + return { + isFile: () => true, + isDirectory: () => false, + size: typeof global.__mockFs[path] === 'string' ? Buffer.byteLength(global.__mockFs[path]) : global.__mockFs[path].length + } + } + return actualFs.statSync(path) + }), + readdirSync: jest.fn((path) => { + const files = [] + for (const filePath in global.__mockFs) { + if (filePath.startsWith(path)) { + files.push(filePath.replace(path + '/', '')) + } + } + return files.length > 0 ? files : actualFs.readdirSync(path) + }) + } +}) // ensure a mocked openwhisk module for unit-tests jest.mock('openwhisk') @@ -120,36 +156,28 @@ const emptyWskPropsFs = { [wskprops]: global.fixtureFile('empty-wsk.properties') } -// set the fake filesystem -const ffs = require('jest-plugin-fs').default - global.fakeFileSystem = { addJson: (json) => { // add to existing - ffs.mock(json) + Object.assign(global.__mockFs, json) }, removeKeys: (arr) => { // remove from existing - const files = ffs.files() - for (const prop in files) { - if (arr.includes(prop)) { - delete files[prop] - } + for (const prop of arr) { + delete global.__mockFs[prop] } - ffs.restore() - ffs.mock(files) }, clear: () => { // reset to empty - ffs.restore() + Object.keys(global.__mockFs).forEach(key => delete global.__mockFs[key]) }, reset: ({ emptyWskProps = false } = {}) => { // reset to file system with wskprops - ffs.restore() - ffs.mock(emptyWskProps ? emptyWskPropsFs : wskPropsFs) + Object.keys(global.__mockFs).forEach(key => delete global.__mockFs[key]) + Object.assign(global.__mockFs, emptyWskProps ? emptyWskPropsFs : wskPropsFs) }, files: () => { - return ffs.files() + return { ...global.__mockFs } } } // seed the fake filesystem From 5a6318f75c55b6deeb03f788239fed3ccbde6693 Mon Sep 17 00:00:00 2001 From: riprajap Date: Tue, 13 Jan 2026 14:34:38 -0800 Subject: [PATCH 2/6] fix undefined args --- test/commands/runtime/action/create.test.js | 12 ++++---- test/commands/runtime/action/delete.test.js | 8 +++--- test/commands/runtime/action/get.test.js | 8 +++--- test/commands/runtime/action/index.test.js | 6 +++- test/commands/runtime/action/invoke.test.js | 8 +++--- test/commands/runtime/action/update.test.js | 12 ++++---- test/commands/runtime/activation/get.test.js | 6 ++-- .../commands/runtime/activation/index.test.js | 6 +++- test/commands/runtime/activation/list.test.js | 6 ++-- test/commands/runtime/activation/logs.test.js | 6 ++-- .../runtime/activation/result.test.js | 6 ++-- test/commands/runtime/api/create.test.js | 28 +++++++++---------- test/commands/runtime/api/delete.test.js | 18 ++++++------ test/commands/runtime/api/get.test.js | 8 +++--- test/commands/runtime/api/index.test.js | 6 +++- test/commands/runtime/api/list.test.js | 18 ++++++------ test/commands/runtime/index.test.js | 6 +++- test/commands/runtime/namespace/get.test.js | 6 +++- test/commands/runtime/namespace/index.test.js | 6 +++- test/commands/runtime/namespace/list.test.js | 6 +++- test/commands/runtime/package/bind.test.js | 14 ++++------ test/commands/runtime/package/create.test.js | 8 +++--- test/commands/runtime/package/delete.test.js | 8 +++--- test/commands/runtime/package/get.test.js | 8 +++--- test/commands/runtime/package/index.test.js | 7 +++-- test/commands/runtime/package/list.test.js | 6 ++-- test/commands/runtime/package/update.test.js | 8 +++--- test/commands/runtime/property/get.test.js | 6 +++- test/commands/runtime/property/index.test.js | 6 +++- test/commands/runtime/property/set.test.js | 6 +++- test/commands/runtime/property/unset.test.js | 6 +++- test/commands/runtime/rule/create.test.js | 20 ++++++------- test/commands/runtime/rule/delete.test.js | 8 +++--- test/commands/runtime/rule/disable.test.js | 8 +++--- test/commands/runtime/rule/enable.test.js | 8 +++--- test/commands/runtime/rule/get.test.js | 8 +++--- test/commands/runtime/rule/index.test.js | 6 +++- test/commands/runtime/rule/status.test.js | 8 +++--- test/commands/runtime/rule/update.test.js | 20 ++++++------- test/commands/runtime/trigger/create.test.js | 11 ++++---- test/commands/runtime/trigger/delete.test.js | 11 ++++---- test/commands/runtime/trigger/fire.test.js | 11 ++++---- test/commands/runtime/trigger/get.test.js | 11 ++++---- test/commands/runtime/trigger/index.test.js | 6 +++- test/commands/runtime/trigger/list.test.js | 6 +++- test/commands/runtime/trigger/update.test.js | 11 ++++---- 46 files changed, 235 insertions(+), 187 deletions(-) diff --git a/test/commands/runtime/action/create.test.js b/test/commands/runtime/action/create.test.js index c7f7d0fa..cb7f382f 100644 --- a/test/commands/runtime/action/create.test.js +++ b/test/commands/runtime/action/create.test.js @@ -52,13 +52,11 @@ test('flags', async () => { }) test('args', async () => { - const actionName = TheCommand.args[0] - expect(actionName.name).toBeDefined() - expect(actionName.name).toEqual('actionName') - expect(actionName.required).toEqual(true) - const actionPath = TheCommand.args[1] - expect(actionPath.name).toBeDefined() - expect(actionPath.name).toEqual('actionPath') + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.actionName).toBeDefined() + expect(args.actionName.required).toEqual(true) + expect(args.actionPath).toBeDefined() }) test('aliases', async () => { diff --git a/test/commands/runtime/action/delete.test.js b/test/commands/runtime/action/delete.test.js index 5b46bb80..859bae09 100644 --- a/test/commands/runtime/action/delete.test.js +++ b/test/commands/runtime/action/delete.test.js @@ -32,10 +32,10 @@ test('aliases', async () => { }) test('args', async () => { - const deleteName = TheCommand.args[0] - expect(deleteName.name).toBeDefined() - expect(deleteName.name).toEqual('actionName') - expect(deleteName.required).toEqual(true) + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.actionName).toBeDefined() + expect(args.actionName.required).toEqual(true) }) describe('instance methods', () => { diff --git a/test/commands/runtime/action/get.test.js b/test/commands/runtime/action/get.test.js index 84ce7c48..50ca88bd 100644 --- a/test/commands/runtime/action/get.test.js +++ b/test/commands/runtime/action/get.test.js @@ -33,10 +33,10 @@ test('aliases', async () => { }) test('args', async () => { - const getName = TheCommand.args[0] - expect(getName.name).toBeDefined() - expect(getName.name).toEqual('actionName') - expect(getName.required).toEqual(true) + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.actionName).toBeDefined() + expect(args.actionName.required).toEqual(true) }) describe('instance methods', () => { diff --git a/test/commands/runtime/action/index.test.js b/test/commands/runtime/action/index.test.js index 056f77e7..8386fd35 100644 --- a/test/commands/runtime/action/index.test.js +++ b/test/commands/runtime/action/index.test.js @@ -30,7 +30,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/action/invoke.test.js b/test/commands/runtime/action/invoke.test.js index 6ba5abe0..4d95a3cd 100644 --- a/test/commands/runtime/action/invoke.test.js +++ b/test/commands/runtime/action/invoke.test.js @@ -47,10 +47,10 @@ test('flags', async () => { }) test('args', async () => { - const invokeName = TheCommand.args[0] - expect(invokeName.name).toBeDefined() - expect(invokeName.name).toEqual('actionName') - expect(invokeName.required).toEqual(true) + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.actionName).toBeDefined() + expect(args.actionName.required).toEqual(true) }) describe('instance methods', () => { diff --git a/test/commands/runtime/action/update.test.js b/test/commands/runtime/action/update.test.js index c2248ebe..8a5a6c8c 100644 --- a/test/commands/runtime/action/update.test.js +++ b/test/commands/runtime/action/update.test.js @@ -62,13 +62,11 @@ test('flags', async () => { }) test('args', async () => { - const actionName = TheCommand.args[0] - expect(actionName.name).toBeDefined() - expect(actionName.name).toEqual('actionName') - expect(actionName.required).toEqual(true) - const actionPath = TheCommand.args[1] - expect(actionPath.name).toBeDefined() - expect(actionPath.name).toEqual('actionPath') + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.actionName).toBeDefined() + expect(args.actionName.required).toEqual(true) + expect(args.actionPath).toBeDefined() }) describe('instance methods', () => { diff --git a/test/commands/runtime/activation/get.test.js b/test/commands/runtime/activation/get.test.js index e2898bde..df06a490 100644 --- a/test/commands/runtime/activation/get.test.js +++ b/test/commands/runtime/activation/get.test.js @@ -33,9 +33,9 @@ test('aliases', async () => { }) test('args', async () => { - const getName = TheCommand.args[0] - expect(getName.name).toBeDefined() - expect(getName.name).toEqual('activationID') + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.activationID).toBeDefined() }) test('flags', async () => { diff --git a/test/commands/runtime/activation/index.test.js b/test/commands/runtime/activation/index.test.js index 6926cb9b..501eb83d 100644 --- a/test/commands/runtime/activation/index.test.js +++ b/test/commands/runtime/activation/index.test.js @@ -30,7 +30,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/activation/list.test.js b/test/commands/runtime/activation/list.test.js index 9003aab5..b0a4206f 100644 --- a/test/commands/runtime/activation/list.test.js +++ b/test/commands/runtime/activation/list.test.js @@ -41,9 +41,9 @@ test('flags', async () => { }) test('args', async () => { - const logName = TheCommand.args[0] - expect(logName.name).toBeDefined() - expect(logName.name).toEqual('action_name') + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.action_name).toBeDefined() }) describe('instance methods', () => { diff --git a/test/commands/runtime/activation/logs.test.js b/test/commands/runtime/activation/logs.test.js index fa259c0d..a2a26d3e 100644 --- a/test/commands/runtime/activation/logs.test.js +++ b/test/commands/runtime/activation/logs.test.js @@ -32,9 +32,9 @@ test('aliases', async () => { }) test('args', async () => { - const logName = TheCommand.args[0] - expect(logName.name).toBeDefined() - expect(logName.name).toEqual('activationId') + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.activationId).toBeDefined() }) test('flags', async () => { diff --git a/test/commands/runtime/activation/result.test.js b/test/commands/runtime/activation/result.test.js index 57d87099..0359d4ab 100644 --- a/test/commands/runtime/activation/result.test.js +++ b/test/commands/runtime/activation/result.test.js @@ -32,9 +32,9 @@ test('aliases', async () => { }) test('args', async () => { - const logName = TheCommand.args[0] - expect(logName.name).toBeDefined() - expect(logName.name).toEqual('activationID') + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.activationID).toBeDefined() }) test('flags', async () => { diff --git a/test/commands/runtime/api/create.test.js b/test/commands/runtime/api/create.test.js index 2948ff28..a92b8657 100644 --- a/test/commands/runtime/api/create.test.js +++ b/test/commands/runtime/api/create.test.js @@ -34,24 +34,24 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(4) + expect(Object.keys(args).length).toEqual(4) - expect(args[0].name).toEqual('basePath') - expect(args[0].required).not.toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.basePath).toBeDefined() + expect(args.basePath.required).not.toBeTruthy() + expect(args.basePath.description).toBeDefined() - expect(args[1].name).toEqual('relPath') - expect(args[1].required).not.toBeTruthy() - expect(args[1].description).toBeDefined() + expect(args.relPath).toBeDefined() + expect(args.relPath.required).not.toBeTruthy() + expect(args.relPath.description).toBeDefined() - expect(args[2].name).toEqual('apiVerb') - expect(args[2].required).not.toBeTruthy() - expect(args[2].options).toMatchObject(['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) - expect(args[2].description).toBeDefined() + expect(args.apiVerb).toBeDefined() + expect(args.apiVerb.required).not.toBeTruthy() + expect(args.apiVerb.options).toMatchObject(['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) + expect(args.apiVerb.description).toBeDefined() - expect(args[3].name).toEqual('action') - expect(args[3].required).not.toBeTruthy() - expect(args[3].description).toBeDefined() + expect(args.action).toBeDefined() + expect(args.action.required).not.toBeTruthy() + expect(args.action.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/api/delete.test.js b/test/commands/runtime/api/delete.test.js index da484ade..c408403c 100644 --- a/test/commands/runtime/api/delete.test.js +++ b/test/commands/runtime/api/delete.test.js @@ -34,18 +34,18 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(3) + expect(Object.keys(args).length).toEqual(3) - expect(args[0].name).toEqual('basePathOrApiName') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.basePathOrApiName).toBeDefined() + expect(args.basePathOrApiName.required).toBeTruthy() + expect(args.basePathOrApiName.description).toBeDefined() - expect(args[1].name).toEqual('relPath') - expect(args[1].required).toBeFalsy() - expect(args[1].description).toBeDefined() + expect(args.relPath).toBeDefined() + expect(args.relPath.required).toBeFalsy() + expect(args.relPath.description).toBeDefined() - expect(args[2].name).toEqual('apiVerb') - expect(args[2].required).toBeFalsy() + expect(args.apiVerb).toBeDefined() + expect(args.apiVerb.required).toBeFalsy() expect(args[2].options).toMatchObject(['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) expect(args[2].description).toBeDefined() }) diff --git a/test/commands/runtime/api/get.test.js b/test/commands/runtime/api/get.test.js index 2009a773..a5816e93 100644 --- a/test/commands/runtime/api/get.test.js +++ b/test/commands/runtime/api/get.test.js @@ -34,11 +34,11 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(1) + expect(Object.keys(args).length).toEqual(1) - expect(args[0].name).toEqual('basePathOrApiName') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.basePathOrApiName).toBeDefined() + expect(args.basePathOrApiName.required).toBeTruthy() + expect(args.basePathOrApiName.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/api/index.test.js b/test/commands/runtime/api/index.test.js index 0226b8ec..2796bdb1 100644 --- a/test/commands/runtime/api/index.test.js +++ b/test/commands/runtime/api/index.test.js @@ -30,7 +30,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/api/list.test.js b/test/commands/runtime/api/list.test.js index d4210a94..5a5870a0 100644 --- a/test/commands/runtime/api/list.test.js +++ b/test/commands/runtime/api/list.test.js @@ -34,18 +34,18 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(3) + expect(Object.keys(args).length).toEqual(3) - expect(args[0].name).toEqual('basePath') - expect(args[0].required).toBeFalsy() - expect(args[0].description).toBeDefined() + expect(args.basePath).toBeDefined() + expect(args.basePath.required).toBeFalsy() + expect(args.basePath.description).toBeDefined() - expect(args[1].name).toEqual('relPath') - expect(args[1].required).toBeFalsy() - expect(args[1].description).toBeDefined() + expect(args.relPath).toBeDefined() + expect(args.relPath.required).toBeFalsy() + expect(args.relPath.description).toBeDefined() - expect(args[2].name).toEqual('apiVerb') - expect(args[2].required).toBeFalsy() + expect(args.apiVerb).toBeDefined() + expect(args.apiVerb.required).toBeFalsy() expect(args[2].options).toMatchObject(['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) expect(args[2].description).toBeDefined() }) diff --git a/test/commands/runtime/index.test.js b/test/commands/runtime/index.test.js index d9499c5e..bb6ea377 100644 --- a/test/commands/runtime/index.test.js +++ b/test/commands/runtime/index.test.js @@ -34,7 +34,11 @@ test('flags', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/namespace/get.test.js b/test/commands/runtime/namespace/get.test.js index bb5692cb..0b500289 100644 --- a/test/commands/runtime/namespace/get.test.js +++ b/test/commands/runtime/namespace/get.test.js @@ -33,7 +33,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).not.toBeDefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/namespace/index.test.js b/test/commands/runtime/namespace/index.test.js index de454562..d5d779ff 100644 --- a/test/commands/runtime/namespace/index.test.js +++ b/test/commands/runtime/namespace/index.test.js @@ -30,7 +30,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/namespace/list.test.js b/test/commands/runtime/namespace/list.test.js index f313954b..a124294e 100644 --- a/test/commands/runtime/namespace/list.test.js +++ b/test/commands/runtime/namespace/list.test.js @@ -32,7 +32,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).not.toBeDefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/package/bind.test.js b/test/commands/runtime/package/bind.test.js index d6c5e1d1..0cc3c472 100644 --- a/test/commands/runtime/package/bind.test.js +++ b/test/commands/runtime/package/bind.test.js @@ -46,14 +46,12 @@ test('flags', async () => { }) test('args', async () => { - const packageName = TheCommand.args[0] - expect(packageName.name).toBeDefined() - expect(packageName.name).toEqual('packageName') - expect(packageName.required).toEqual(true) - const bindPackageName = TheCommand.args[1] - expect(bindPackageName.name).toBeDefined() - expect(bindPackageName.name).toEqual('bindPackageName') - expect(bindPackageName.required).toEqual(true) + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.packageName).toBeDefined() + expect(args.packageName.required).toEqual(true) + expect(args.bindPackageName).toBeDefined() + expect(args.bindPackageName.required).toEqual(true) }) describe('instance methods', () => { diff --git a/test/commands/runtime/package/create.test.js b/test/commands/runtime/package/create.test.js index f854933a..d5eb8a24 100644 --- a/test/commands/runtime/package/create.test.js +++ b/test/commands/runtime/package/create.test.js @@ -47,10 +47,10 @@ test('flags', async () => { }) test('args', async () => { - const packageName = TheCommand.args[0] - expect(packageName.name).toBeDefined() - expect(packageName.name).toEqual('packageName') - expect(packageName.required).toEqual(true) + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.packageName).toBeDefined() + expect(args.packageName.required).toEqual(true) }) describe('instance methods', () => { diff --git a/test/commands/runtime/package/delete.test.js b/test/commands/runtime/package/delete.test.js index 632e6277..9d4c687c 100644 --- a/test/commands/runtime/package/delete.test.js +++ b/test/commands/runtime/package/delete.test.js @@ -33,10 +33,10 @@ test('aliases', async () => { }) test('args', async () => { - const deleteName = TheCommand.args[0] - expect(deleteName.name).toBeDefined() - expect(deleteName.name).toEqual('packageName') - expect(deleteName.required).toEqual(true) + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.packageName).toBeDefined() + expect(args.packageName.required).toEqual(true) }) describe('instance methods', () => { diff --git a/test/commands/runtime/package/get.test.js b/test/commands/runtime/package/get.test.js index 6442b444..33f9bc76 100644 --- a/test/commands/runtime/package/get.test.js +++ b/test/commands/runtime/package/get.test.js @@ -33,10 +33,10 @@ test('aliases', async () => { }) test('args', async () => { - const getName = TheCommand.args[0] - expect(getName.name).toBeDefined() - expect(getName.name).toEqual('packageName') - expect(getName.required).toEqual(true) + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.packageName).toBeDefined() + expect(args.packageName.required).toEqual(true) }) describe('instance methods', () => { diff --git a/test/commands/runtime/package/index.test.js b/test/commands/runtime/package/index.test.js index c9f968f3..4e8e6ca2 100644 --- a/test/commands/runtime/package/index.test.js +++ b/test/commands/runtime/package/index.test.js @@ -29,8 +29,11 @@ test('aliases', async () => { expect(TheCommand.aliases.length).toBeGreaterThan(0) }) -test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/package/list.test.js b/test/commands/runtime/package/list.test.js index 2d9054ca..5b85d49e 100644 --- a/test/commands/runtime/package/list.test.js +++ b/test/commands/runtime/package/list.test.js @@ -39,9 +39,9 @@ test('flags', async () => { }) test('args', async () => { - const listName = TheCommand.args[0] - expect(listName.name).toBeDefined() - expect(listName.name).toEqual('namespace') + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.namespace).toBeDefined() }) describe('instance methods', () => { diff --git a/test/commands/runtime/package/update.test.js b/test/commands/runtime/package/update.test.js index a60a5485..e1a61de0 100644 --- a/test/commands/runtime/package/update.test.js +++ b/test/commands/runtime/package/update.test.js @@ -47,10 +47,10 @@ test('flags', async () => { }) test('args', async () => { - const packageName = TheCommand.args[0] - expect(packageName.name).toBeDefined() - expect(packageName.name).toEqual('packageName') - expect(packageName.required).toEqual(true) + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.packageName).toBeDefined() + expect(args.packageName.required).toEqual(true) }) describe('instance methods', () => { diff --git a/test/commands/runtime/property/get.test.js b/test/commands/runtime/property/get.test.js index b32bdbfe..4aa0394b 100644 --- a/test/commands/runtime/property/get.test.js +++ b/test/commands/runtime/property/get.test.js @@ -36,7 +36,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).not.toBeDefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/property/index.test.js b/test/commands/runtime/property/index.test.js index adf90f10..0f1f0aab 100644 --- a/test/commands/runtime/property/index.test.js +++ b/test/commands/runtime/property/index.test.js @@ -34,7 +34,11 @@ test('flags', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/property/set.test.js b/test/commands/runtime/property/set.test.js index dd16af02..9bb02d07 100644 --- a/test/commands/runtime/property/set.test.js +++ b/test/commands/runtime/property/set.test.js @@ -30,7 +30,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).not.toBeDefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/property/unset.test.js b/test/commands/runtime/property/unset.test.js index a809c677..11bbae06 100644 --- a/test/commands/runtime/property/unset.test.js +++ b/test/commands/runtime/property/unset.test.js @@ -29,7 +29,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).not.toBeDefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/rule/create.test.js b/test/commands/runtime/rule/create.test.js index 46ff20bc..235ffecf 100644 --- a/test/commands/runtime/rule/create.test.js +++ b/test/commands/runtime/rule/create.test.js @@ -34,19 +34,19 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(3) + expect(Object.keys(args).length).toEqual(3) - expect(args[0].name).toEqual('name') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.name).toBeDefined() + expect(args.name.required).toBeTruthy() + expect(args.name.description).toBeDefined() - expect(args[1].name).toEqual('trigger') - expect(args[1].required).toBeTruthy() - expect(args[1].description).toBeDefined() + expect(args.trigger).toBeDefined() + expect(args.trigger.required).toBeTruthy() + expect(args.trigger.description).toBeDefined() - expect(args[2].name).toEqual('action') - expect(args[2].required).toBeTruthy() - expect(args[2].description).toBeDefined() + expect(args.action).toBeDefined() + expect(args.action.required).toBeTruthy() + expect(args.action.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/rule/delete.test.js b/test/commands/runtime/rule/delete.test.js index e266ca01..801e4e65 100644 --- a/test/commands/runtime/rule/delete.test.js +++ b/test/commands/runtime/rule/delete.test.js @@ -34,11 +34,11 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(1) + expect(Object.keys(args).length).toEqual(1) - expect(args[0].name).toEqual('name') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.name).toBeDefined() + expect(args.name.required).toBeTruthy() + expect(args.name.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/rule/disable.test.js b/test/commands/runtime/rule/disable.test.js index 44586ee9..fd6a8225 100644 --- a/test/commands/runtime/rule/disable.test.js +++ b/test/commands/runtime/rule/disable.test.js @@ -34,11 +34,11 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(1) + expect(Object.keys(args).length).toEqual(1) - expect(args[0].name).toEqual('name') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.name).toBeDefined() + expect(args.name.required).toBeTruthy() + expect(args.name.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/rule/enable.test.js b/test/commands/runtime/rule/enable.test.js index 1ceb59d8..6a26444a 100644 --- a/test/commands/runtime/rule/enable.test.js +++ b/test/commands/runtime/rule/enable.test.js @@ -34,11 +34,11 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(1) + expect(Object.keys(args).length).toEqual(1) - expect(args[0].name).toEqual('name') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.name).toBeDefined() + expect(args.name.required).toBeTruthy() + expect(args.name.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/rule/get.test.js b/test/commands/runtime/rule/get.test.js index 7355dced..e8a55030 100644 --- a/test/commands/runtime/rule/get.test.js +++ b/test/commands/runtime/rule/get.test.js @@ -34,11 +34,11 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(1) + expect(Object.keys(args).length).toEqual(1) - expect(args[0].name).toEqual('name') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.name).toBeDefined() + expect(args.name.required).toBeTruthy() + expect(args.name.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/rule/index.test.js b/test/commands/runtime/rule/index.test.js index 3e555b4d..33e534ed 100644 --- a/test/commands/runtime/rule/index.test.js +++ b/test/commands/runtime/rule/index.test.js @@ -30,7 +30,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/rule/status.test.js b/test/commands/runtime/rule/status.test.js index b3d5a20f..200c3087 100644 --- a/test/commands/runtime/rule/status.test.js +++ b/test/commands/runtime/rule/status.test.js @@ -34,11 +34,11 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(1) + expect(Object.keys(args).length).toEqual(1) - expect(args[0].name).toEqual('name') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.name).toBeDefined() + expect(args.name.required).toBeTruthy() + expect(args.name.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/rule/update.test.js b/test/commands/runtime/rule/update.test.js index b91a6469..4f8551f9 100644 --- a/test/commands/runtime/rule/update.test.js +++ b/test/commands/runtime/rule/update.test.js @@ -34,19 +34,19 @@ test('aliases', async () => { test('args', async () => { const args = TheCommand.args expect(args).toBeDefined() - expect(args.length).toEqual(3) + expect(Object.keys(args).length).toEqual(3) - expect(args[0].name).toEqual('name') - expect(args[0].required).toBeTruthy() - expect(args[0].description).toBeDefined() + expect(args.name).toBeDefined() + expect(args.name.required).toBeTruthy() + expect(args.name.description).toBeDefined() - expect(args[1].name).toEqual('trigger') - expect(args[1].required).toBeTruthy() - expect(args[1].description).toBeDefined() + expect(args.trigger).toBeDefined() + expect(args.trigger.required).toBeTruthy() + expect(args.trigger.description).toBeDefined() - expect(args[2].name).toEqual('action') - expect(args[2].required).toBeTruthy() - expect(args[2].description).toBeDefined() + expect(args.action).toBeDefined() + expect(args.action.required).toBeTruthy() + expect(args.action.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/trigger/create.test.js b/test/commands/runtime/trigger/create.test.js index 6798d98c..5138a89b 100644 --- a/test/commands/runtime/trigger/create.test.js +++ b/test/commands/runtime/trigger/create.test.js @@ -63,12 +63,11 @@ test('flags', async () => { }) test('args', async () => { - const triggerName = TheCommand.args[0] - - expect(triggerName).toBeDefined() - expect(triggerName.name).toEqual('triggerName') - expect(triggerName.required).toEqual(true) - expect(triggerName.description).toBeDefined() + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.triggerName).toBeDefined() + expect(args.triggerName.required).toEqual(true) + expect(args.triggerName.description).toBeDefined() }) describe('instance methods', () => { diff --git a/test/commands/runtime/trigger/delete.test.js b/test/commands/runtime/trigger/delete.test.js index 6259ed23..97175c30 100644 --- a/test/commands/runtime/trigger/delete.test.js +++ b/test/commands/runtime/trigger/delete.test.js @@ -33,12 +33,11 @@ test('aliases', async () => { }) test('args', async () => { - const triggerPath = TheCommand.args[0] - - expect(triggerPath).toBeDefined() - expect(triggerPath.name).toEqual('triggerPath') - expect(triggerPath.required).toEqual(true) - expect(triggerPath.description).toBeDefined() + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.triggerPath).toBeDefined() + expect(args.triggerPath.required).toEqual(true) + expect(args.triggerPath.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/trigger/fire.test.js b/test/commands/runtime/trigger/fire.test.js index 9eba40b3..de348f4b 100644 --- a/test/commands/runtime/trigger/fire.test.js +++ b/test/commands/runtime/trigger/fire.test.js @@ -33,12 +33,11 @@ test('aliases', async () => { }) test('args', async () => { - const triggerName = TheCommand.args[0] - - expect(triggerName).toBeDefined() - expect(triggerName.name).toEqual('triggerName') - expect(triggerName.required).toEqual(true) - expect(triggerName.description).toBeDefined() + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.triggerName).toBeDefined() + expect(args.triggerName.required).toEqual(true) + expect(args.triggerName.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/trigger/get.test.js b/test/commands/runtime/trigger/get.test.js index a6834949..ecaee8ef 100644 --- a/test/commands/runtime/trigger/get.test.js +++ b/test/commands/runtime/trigger/get.test.js @@ -33,12 +33,11 @@ test('aliases', async () => { }) test('args', async () => { - const triggerPath = TheCommand.args[0] - - expect(triggerPath).toBeDefined() - expect(triggerPath.name).toEqual('triggerPath') - expect(triggerPath.required).toEqual(true) - expect(triggerPath.description).toBeDefined() + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.triggerPath).toBeDefined() + expect(args.triggerPath.required).toEqual(true) + expect(args.triggerPath.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/trigger/index.test.js b/test/commands/runtime/trigger/index.test.js index 617fe968..2c071183 100644 --- a/test/commands/runtime/trigger/index.test.js +++ b/test/commands/runtime/trigger/index.test.js @@ -34,7 +34,11 @@ test('flags', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/trigger/list.test.js b/test/commands/runtime/trigger/list.test.js index 73f2e3d5..ce29e076 100644 --- a/test/commands/runtime/trigger/list.test.js +++ b/test/commands/runtime/trigger/list.test.js @@ -32,7 +32,11 @@ test('aliases', async () => { }) test('args', async () => { - expect(TheCommand.args).not.toBeDefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/trigger/update.test.js b/test/commands/runtime/trigger/update.test.js index d030d054..164d77ba 100644 --- a/test/commands/runtime/trigger/update.test.js +++ b/test/commands/runtime/trigger/update.test.js @@ -58,12 +58,11 @@ test('flags', async () => { }) test('args', async () => { - const triggerName = TheCommand.args[0] - - expect(triggerName).toBeDefined() - expect(triggerName.name).toEqual('triggerName') - expect(triggerName.required).toEqual(true) - expect(triggerName.description).toBeDefined() + const args = TheCommand.args + expect(args).toBeDefined() + expect(args.triggerName).toBeDefined() + expect(args.triggerName.required).toEqual(true) + expect(args.triggerName.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect From f1e5702334b369dd97ca78ec167b17546192079d Mon Sep 17 00:00:00 2001 From: riprajap Date: Tue, 13 Jan 2026 15:13:58 -0800 Subject: [PATCH 3/6] fix relative path issue --- src/commands/runtime/api/delete.js | 2 +- src/commands/runtime/package/bind.js | 2 +- src/commands/runtime/package/delete.js | 2 +- test/commands/runtime/action/create.test.js | 66 ++++++++++---------- test/commands/runtime/action/update.test.js | 60 +++++++++--------- test/commands/runtime/property/set.test.js | 2 +- test/commands/runtime/property/unset.test.js | 2 +- test/jest.setup.js | 15 +++++ 8 files changed, 83 insertions(+), 68 deletions(-) diff --git a/src/commands/runtime/api/delete.js b/src/commands/runtime/api/delete.js index 09eafbce..34114f40 100644 --- a/src/commands/runtime/api/delete.js +++ b/src/commands/runtime/api/delete.js @@ -10,7 +10,7 @@ governing permissions and limitations under the License. */ const DeployServiceCommand = require('../../../DeployServiceCommand') -// eslint-disable-next-line no-unused-vars +const { Args } = require('@oclif/core') class ApiDelete extends DeployServiceCommand { async run () { diff --git a/src/commands/runtime/package/bind.js b/src/commands/runtime/package/bind.js index da3f9011..3e11b39d 100644 --- a/src/commands/runtime/package/bind.js +++ b/src/commands/runtime/package/bind.js @@ -13,7 +13,7 @@ governing permissions and limitations under the License. const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const { parsePackageName } = require('@adobe/aio-lib-runtime').utils const { getKeyValueArrayFromMergedParameters } = require('@adobe/aio-lib-runtime').utils -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class PackageBind extends RuntimeBaseCommand { async run () { diff --git a/src/commands/runtime/package/delete.js b/src/commands/runtime/package/delete.js index d085335d..115ad5f5 100644 --- a/src/commands/runtime/package/delete.js +++ b/src/commands/runtime/package/delete.js @@ -12,7 +12,7 @@ governing permissions and limitations under the License. const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const { parsePackageName } = require('@adobe/aio-lib-runtime').utils -const { Flags } = require('@oclif/core') +const { Args, Flags } = require('@oclif/core') class PackageDelete extends RuntimeBaseCommand { async run () { diff --git a/test/commands/runtime/action/create.test.js b/test/commands/runtime/action/create.test.js index cb7f382f..0de1fc4d 100644 --- a/test/commands/runtime/action/create.test.js +++ b/test/commands/runtime/action/create.test.js @@ -105,7 +105,7 @@ describe('instance methods', () => { test('creates an action with action name and action path', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js'] + command.argv = [name, 'action/actionFile.js'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ name, action: { name, exec: { code: jsFile, kind: 'nodejs:default' } } }) @@ -155,7 +155,7 @@ describe('instance methods', () => { test('creates an action with action name and action path and --docker flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--docker', 'some-image'] + command.argv = [name, 'action/actionFile.js', '--docker', 'some-image'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ @@ -176,7 +176,7 @@ describe('instance methods', () => { test('creates an action with action name and action path --json', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--json'] + command.argv = [name, 'action/actionFile.js', '--json'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ @@ -197,7 +197,7 @@ describe('instance methods', () => { const name = 'hello' const zipFile = Buffer.from('fakezipfile').toString('base64') const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/zipAction.zip', '--kind', 'nodejs:8'] + command.argv = [name, 'action/zipAction.zip', '--kind', 'nodejs:8'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ @@ -218,7 +218,7 @@ describe('instance methods', () => { const name = 'hello' const zipFile = Buffer.from('fakezipfile').toString('base64') const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/zipAction.bin', '--kind', 'nodejs:8', '--binary'] + command.argv = [name, 'action/zipAction.bin', '--kind', 'nodejs:8', '--binary'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ @@ -238,7 +238,7 @@ describe('instance methods', () => { test('creates an action with action name, action path and --param flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation(params => params && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() .then(() => { @@ -259,10 +259,10 @@ describe('instance methods', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => file && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) - command.argv = [name, '/action/actionFile.js', '--param-file', '/action/parameters.json'] + command.argv = [name, 'action/actionFile.js', '--param-file', 'action/parameters.json'] return command.run() .then(() => { - expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, '/action/parameters.json') + expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, 'action/parameters.json') expect(cmd).toHaveBeenCalledWith({ action: { exec: { code: jsFile, kind: 'nodejs:default' }, @@ -278,7 +278,7 @@ describe('instance methods', () => { test('creates an action with action name, action path, --param-file and param flag (precedence)', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, '') - command.argv = [name, '/action/actionFile.js', '--param', 'param1', 'fromcmdline1', '--param', 'cmdparam', 'fromcmdline2', '--param-file', '/action/parameters.json'] + command.argv = [name, 'action/actionFile.js', '--param', 'param1', 'fromcmdline1', '--param', 'cmdparam', 'fromcmdline2', '--param-file', 'action/parameters.json'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && file && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() @@ -301,7 +301,7 @@ describe('instance methods', () => { test('creates an action with action name, action path, --params flag and limits', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--logsize', '8', '--memory', '128', '--timeout', '20000'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--logsize', '8', '--memory', '128', '--timeout', '20000'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() .then(() => { @@ -332,7 +332,7 @@ describe('instance methods', () => { test('creates an action with action name, action path, --params flag and limits with shorter flag version', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-l', '8', '-m', '128', '-t', '20000'] + command.argv = [name, 'action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-l', '8', '-m', '128', '-t', '20000'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() .then(() => { @@ -363,7 +363,7 @@ describe('instance methods', () => { test('creates an action with action name, action path, --params flag, limits and kind', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--logsize', '8', '--memory', '128', '--concurrency', '1', '--kind', 'nodejs:10'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--logsize', '8', '--memory', '128', '--concurrency', '1', '--kind', 'nodejs:10'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && ([{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }])) return command.run() .then(() => { @@ -394,7 +394,7 @@ describe('instance methods', () => { test('creates an action with action name, action path, --params flag, only concurrency limit and kind', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--concurrency', '1', '--kind', 'nodejs:10'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--concurrency', '1', '--kind', 'nodejs:10'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && ([{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }])) return command.run() .then(() => { @@ -423,7 +423,7 @@ describe('instance methods', () => { test('creates an action with action name, action path and --env flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--env', 'a', 'b', '--env', 'c', 'd'] + command.argv = [name, 'action/actionFile.js', '--env', 'a', 'b', '--env', 'c', 'd'] rtUtils.createKeyValueArrayFromFlag.mockReturnValue([{ key: 'fakeEnv', value: 'abc' }]) return command.run() .then(() => { @@ -450,7 +450,7 @@ describe('instance methods', () => { test('creates an action with action name, action path and --e flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--env', 'a', 'b', '-e', 'c', 'd'] + command.argv = [name, 'action/actionFile.js', '--env', 'a', 'b', '-e', 'c', 'd'] rtUtils.createKeyValueArrayFromFlag.mockReturnValue([{ key: 'fakeEnv', value: 'abc' }]) return command.run() .then(() => { @@ -477,7 +477,7 @@ describe('instance methods', () => { test('creates an action with action name, action path and --env and --param flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--env', 'a', 'b', '--param', 'c', 'd'] + command.argv = [name, 'action/actionFile.js', '--env', 'a', 'b', '--param', 'c', 'd'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) rtUtils.createKeyValueArrayFromFlag.mockReturnValue([{ key: 'fakeEnv', value: 'abc' }]) return command.run() @@ -506,7 +506,7 @@ describe('instance methods', () => { test('creates an action with action name, action path and overlapping --env and --param keys', async () => { rtLib.mockRejected(rtAction, '') const name = 'hello' - command.argv = [name, '/action/actionFile.js', '--env', 'a', 'b', '--param', 'a', 'd'] + command.argv = [name, 'action/actionFile.js', '--env', 'a', 'b', '--param', 'a', 'd'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && [{ key: 'same', value: 'kv' }]) rtUtils.createKeyValueArrayFromFlag.mockReturnValue([{ key: 'same', value: 'abc' }]) const error = ['failed to create the action', new Error('Invalid argument(s). Environment variables and function parameters may not overlap')] @@ -516,11 +516,11 @@ describe('instance methods', () => { test('creates an action with action name, action path and --env-file flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--env-file', '/action/parameters.json'] + command.argv = [name, 'action/actionFile.js', '--env-file', 'action/parameters.json'] rtUtils.createKeyValueArrayFromFile.mockReturnValue([{ key: 'fakeEnv', value: 'abc' }]) return command.run() .then(() => { - expect(rtUtils.createKeyValueArrayFromFile).toHaveBeenCalledWith('/action/parameters.json') + expect(rtUtils.createKeyValueArrayFromFile).toHaveBeenCalledWith('action/parameters.json') expect(cmd).toHaveBeenCalledWith({ name, action: { @@ -543,7 +543,7 @@ describe('instance methods', () => { test('creates an action with action name, action path, --params flag and annotation flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--annotation', 'desc', 'Description'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--annotation', 'desc', 'Description'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => [{ key: 'fake', value: 'abc' }]) return command.run() .then(() => { @@ -574,12 +574,12 @@ describe('instance methods', () => { test('creates an action with action name, action path, --params flag and annotation-file flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-A', '/action/parameters.json'] + command.argv = [name, 'action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-A', 'action/parameters.json'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }]) || (file && [{ key: 'fakeAnno', value: 'tation' }])) return command.run() .then(() => { expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(['a', 'b', 'c', 'd'], undefined) - expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, '/action/parameters.json') + expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, 'action/parameters.json') expect(cmd).toHaveBeenCalledWith({ name, action: { @@ -605,7 +605,7 @@ describe('instance methods', () => { test('creates an action with action name, action path, --params flag web flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '--web', 'raw'] + command.argv = [name, 'action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '--web', 'raw'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }])) return command.run() .then(() => { @@ -632,7 +632,7 @@ describe('instance methods', () => { test('creates an action with action name, action path, --params flag, annotations and web flag as true', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-a', 'desc', 'Description', '--web', 'true', '--web-secure', 'true'] + command.argv = [name, 'action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-a', 'desc', 'Description', '--web', 'true', '--web-secure', 'true'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }])) return command.run() .then(() => { @@ -665,7 +665,7 @@ describe('instance methods', () => { test('creates an action with action name with --web-secure true', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, '') - command.argv = [name, '/action/actionFile.js', '--web', 'true', '--web-secure', 'true'] + command.argv = [name, 'action/actionFile.js', '--web', 'true', '--web-secure', 'true'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ @@ -690,7 +690,7 @@ describe('instance methods', () => { test('creates an action with action name with --web-secure false', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, '') - command.argv = [name, '/action/actionFile.js', '--web', 'true', '--web-secure', 'false'] + command.argv = [name, 'action/actionFile.js', '--web', 'true', '--web-secure', 'false'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ @@ -715,7 +715,7 @@ describe('instance methods', () => { test('creates an action with action name with --web-secure abcxyz', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, '') - command.argv = [name, '/action/actionFile.js', '--web', 'true', '--web-secure', 'abcxyz'] + command.argv = [name, 'action/actionFile.js', '--web', 'true', '--web-secure', 'abcxyz'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ @@ -740,7 +740,7 @@ describe('instance methods', () => { test('creates an action with --main flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--main', 'maynard'] + command.argv = [name, 'action/actionFile.js', '--main', 'maynard'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ @@ -760,14 +760,14 @@ describe('instance methods', () => { test('creates an action with code of unknown kind', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/fileWithNoExt'] + command.argv = ['hello', 'action/fileWithNoExt'] const error = ['failed to create the action', new Error('Cannot determine kind of action. Please use --kind to specify.')] await expect(rejectWithError(command, error, handleError)).toBeTruthy() }) test('creates an action with code and --sequence', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/actionFile.js', '--sequence', 'a,b,c'] + command.argv = ['hello', 'action/actionFile.js', '--sequence', 'a,b,c'] const error = ['failed to create the action', new Error('Cannot specify sequence and a code artifact at the same time')] await expect(rejectWithError(command, error, handleError)).toBeTruthy() }) @@ -788,7 +788,7 @@ describe('instance methods', () => { test('creates an action with --docker and --kind', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/actionFile.js', '--kind', 'nodejs:8', '--docker', 'some-image'] + command.argv = ['hello', 'action/actionFile.js', '--kind', 'nodejs:8', '--docker', 'some-image'] const error = ['failed to create the action', new Error('Cannot specify a kind and a container image at the same time')] await expect(rejectWithError(command, error, handleError)).toBeTruthy() }) @@ -829,14 +829,14 @@ describe('instance methods', () => { test('errors out on api error', async () => { rtLib.mockRejected(rtAction, new Error('an error')) - command.argv = ['hello', '/action/actionFile.js'] + command.argv = ['hello', 'action/actionFile.js'] const error = ['failed to create the action', new Error('an error')] await expect(rejectWithError(command, error, handleError)).toBeTruthy() }) test('errors on --web-secure with --web false flag', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/fileWithNoExt', '--web-secure', 'true', '--web', 'false'] + command.argv = ['hello', 'action/fileWithNoExt', '--web-secure', 'true', '--web', 'false'] const error = ['failed to create the action', new Error(TheCommand.errorMessages.websecure)] await expect(rejectWithError(command, error, handleError)).toBeTruthy() }) diff --git a/test/commands/runtime/action/update.test.js b/test/commands/runtime/action/update.test.js index 8a5a6c8c..93f90aeb 100644 --- a/test/commands/runtime/action/update.test.js +++ b/test/commands/runtime/action/update.test.js @@ -112,7 +112,7 @@ describe('instance methods', () => { test('updates an action with action name and action path', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js'] + command.argv = [name, 'action/actionFile.js'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ name, action: { name, exec: { code: jsFile, kind: 'nodejs:default' } } }) @@ -123,7 +123,7 @@ describe('instance methods', () => { test('updates an action with action name and action path --json', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--json'] + command.argv = [name, 'action/actionFile.js', '--json'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ name, action: { name, exec: { code: jsFile, kind: 'nodejs:default' } } }) @@ -135,7 +135,7 @@ describe('instance methods', () => { const name = 'hello' const zipFile = Buffer.from('fakezipfile').toString('base64') const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/zipAction.zip', '--kind', 'nodejs:10'] + command.argv = [name, 'action/zipAction.zip', '--kind', 'nodejs:10'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ name, action: { name, exec: { code: zipFile, kind: 'nodejs:10' } } }) @@ -146,7 +146,7 @@ describe('instance methods', () => { test('updates an action with action name, action path and --param flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation(params => params && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() .then(() => { @@ -204,11 +204,11 @@ describe('instance methods', () => { test('updates an action with action name, action path and --param-file flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param-file', '/action/parameters.json'] + command.argv = [name, 'action/actionFile.js', '--param-file', 'action/parameters.json'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => file && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() .then(() => { - expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, '/action/parameters.json') + expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, 'action/parameters.json') expect(cmd).toHaveBeenCalledWith({ action: { exec: { code: jsFile, kind: 'nodejs:default' }, @@ -224,11 +224,11 @@ describe('instance methods', () => { test('updates an action with action name and --param-file flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '--param-file', '/action/parameters.json'] + command.argv = [name, '--param-file', 'action/parameters.json'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => file && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() .then(() => { - expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, '/action/parameters.json') + expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, 'action/parameters.json') expect(cmd).toHaveBeenCalledWith({ action: { name, @@ -243,7 +243,7 @@ describe('instance methods', () => { test('update an action with action name, action path, --param-file and param flag (precedence)', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, '') - command.argv = [name, '/action/actionFile.js', '--param', 'param1', 'fromcmdline1', '--param', 'cmdparam', 'fromcmdline2', '--param-file', '/action/parameters.json'] + command.argv = [name, 'action/actionFile.js', '--param', 'param1', 'fromcmdline1', '--param', 'cmdparam', 'fromcmdline2', '--param-file', 'action/parameters.json'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && file && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() @@ -266,7 +266,7 @@ describe('instance methods', () => { test('updates an action with action name, action path, --params flag and limits', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--logsize', '8', '--memory', '128', '--timeout', '20000'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--logsize', '8', '--memory', '128', '--timeout', '20000'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() .then(() => { @@ -351,7 +351,7 @@ describe('instance methods', () => { test('updates an action with action name, action path, --params flag, limits and kind', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--logsize', '8', '--memory', '128', '--kind', 'nodejs:10'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--logsize', '8', '--memory', '128', '--kind', 'nodejs:10'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && [{ key: 'fakeParam', value: 'aaa' }, { key: 'fakeParam2', value: 'bbb' }]) return command.run() .then(() => { @@ -476,7 +476,7 @@ describe('instance methods', () => { test('update an action with action name and overlapping --env and --param keys', async () => { rtLib.mockRejected(rtAction, '') const name = 'hello' - command.argv = [name, '/action/actionFile.js', '--env', 'a', 'b', '--param', 'a', 'd'] + command.argv = [name, 'action/actionFile.js', '--env', 'a', 'b', '--param', 'a', 'd'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => flags && [{ key: 'same', value: 'kv' }]) rtUtils.createKeyValueArrayFromFlag.mockReturnValue([{ key: 'same', value: 'abc' }]) const error = ['failed to update the action', new Error('Invalid argument(s). Environment variables and function parameters may not overlap')] @@ -486,11 +486,11 @@ describe('instance methods', () => { test('update an action with action name, action path and --env-file flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--env-file', '/action/parameters.json'] + command.argv = [name, 'action/actionFile.js', '--env-file', 'action/parameters.json'] rtUtils.createKeyValueArrayFromFile.mockReturnValue([{ key: 'fakeEnv', value: 'abc' }]) return command.run() .then(() => { - expect(rtUtils.createKeyValueArrayFromFile).toHaveBeenCalledWith('/action/parameters.json') + expect(rtUtils.createKeyValueArrayFromFile).toHaveBeenCalledWith('action/parameters.json') expect(cmd).toHaveBeenCalledWith({ name, action: { @@ -570,7 +570,7 @@ describe('instance methods', () => { test('updates an action with action name, action path, --params flag and annotation flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--annotation', 'desc', 'Description'] + command.argv = [name, 'action/actionFile.js', '--param', 'a', 'b', '--param', 'c', 'd', '--annotation', 'desc', 'Description'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => [{ key: 'fake', value: 'abc' }]) return command.run() .then(() => { @@ -650,12 +650,12 @@ describe('instance methods', () => { test('updates an action with action name, action path, --params flag and annotation-file flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-A', '/action/parameters.json'] + command.argv = [name, 'action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-A', 'action/parameters.json'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }]) || (file && [{ key: 'fakeAnno', value: 'tation' }])) return command.run() .then(() => { expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(['a', 'b', 'c', 'd'], undefined) - expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, '/action/parameters.json') + expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, 'action/parameters.json') expect(cmd).toHaveBeenCalledWith({ name, action: { @@ -681,12 +681,12 @@ describe('instance methods', () => { test('updates an action with action name, --params flag and annotation-file flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '-p', 'a', 'b', '-p', 'c', 'd', '-A', '/action/parameters.json'] + command.argv = [name, '-p', 'a', 'b', '-p', 'c', 'd', '-A', 'action/parameters.json'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }]) || (file && [{ key: 'fakeAnno', value: 'tation' }])) return command.run() .then(() => { expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(['a', 'b', 'c', 'd'], undefined) - expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, '/action/parameters.json') + expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, 'action/parameters.json') expect(cmd).toHaveBeenCalledWith({ name, action: { @@ -708,11 +708,11 @@ describe('instance methods', () => { test('updates an action with action name and annotation-file flag', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '-A', '/action/parameters.json'] + command.argv = [name, '-A', 'action/parameters.json'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }]) || (file && [{ key: 'fakeAnno', value: 'tation' }])) return command.run() .then(() => { - expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, '/action/parameters.json') + expect(rtUtils.getKeyValueArrayFromMergedParameters).toHaveBeenCalledWith(undefined, 'action/parameters.json') expect(cmd).toHaveBeenCalledWith({ name, action: { @@ -730,7 +730,7 @@ describe('instance methods', () => { test('updates an action with action name, action path, --params flag and web flag as raw', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '--web', 'raw'] + command.argv = [name, 'action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '--web', 'raw'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }])) return command.run() .then(() => { @@ -761,7 +761,7 @@ describe('instance methods', () => { test('updates an action with action name, action path, --params flag and web flag as false', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '--web', 'false'] + command.argv = [name, 'action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '--web', 'false'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }])) return command.run() .then(() => { @@ -790,7 +790,7 @@ describe('instance methods', () => { test('updates an action with action name, action path, --params flag, annotations and web flag as true', () => { const name = 'hello' const cmd = rtLib.mockResolved(rtAction, { res: 'fake' }) - command.argv = [name, '/action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-a', 'desc', 'Description', '--web', 'true'] + command.argv = [name, 'action/actionFile.js', '-p', 'a', 'b', '-p', 'c', 'd', '-a', 'desc', 'Description', '--web', 'true'] rtUtils.getKeyValueArrayFromMergedParameters.mockImplementation((flags, file) => (flags && [{ key: 'fake', value: 'abc' }])) return command.run() .then(() => { @@ -835,21 +835,21 @@ describe('instance methods', () => { test('tests for incorrect action path', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/file.js', '--kind', 'nodejs:10'] + command.argv = ['hello', 'action/file.js', '--kind', 'nodejs:10'] const error = ['failed to update the action', new Error('Provide a valid path for ACTION')] expect(await rejectWithError(command, error, handleError)).toBeTruthy() }) test('tests for incorrect action zip path', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/file.zip', '--kind', 'nodejs:10'] + command.argv = ['hello', 'action/file.zip', '--kind', 'nodejs:10'] const error = ['failed to update the action', new Error('Provide a valid path for ACTION')] expect(await rejectWithError(command, error, handleError)).toBeTruthy() }) test('error out if a zip file is deployed without the --kind flag', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/zipAction.zip'] + command.argv = ['hello', 'action/zipAction.zip'] const error = ['failed to update the action', new Error('Invalid argument(s). Creating an action from a zip/binary artifact requires specifying the action kind explicitly')] expect(await rejectWithError(command, error, handleError)).toBeTruthy() }) @@ -870,21 +870,21 @@ describe('instance methods', () => { test('tests for incorrect update with file artifact and --sequence', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/actionFile.js', '--sequence', 'a,b,c'] + command.argv = ['hello', 'action/actionFile.js', '--sequence', 'a,b,c'] const error = ['failed to update the action', new Error('Cannot specify sequence and a code artifact at the same time')] expect(await rejectWithError(command, error, handleError)).toBeTruthy() }) test('tests for incorrect update with file artifact and --sequence and --main', async () => { rtLib.mockRejected(rtAction, '') - command.argv = ['hello', '/action/actionFile.js', '--main', 'maynard', '--sequence', 'a,b,c'] + command.argv = ['hello', 'action/actionFile.js', '--main', 'maynard', '--sequence', 'a,b,c'] const error = ['failed to update the action', new Error('Cannot specify sequence and a code artifact at the same time')] expect(await rejectWithError(command, error, handleError)).toBeTruthy() }) test('errors out on api error', async () => { rtLib.mockRejected(rtAction, new Error('an error')) - command.argv = ['hello', '/action/actionFile.js'] + command.argv = ['hello', 'action/actionFile.js'] const error = ['failed to update the action', new Error('an error')] expect(await rejectWithError(command, error, handleError)).toBeTruthy() }) diff --git a/test/commands/runtime/property/set.test.js b/test/commands/runtime/property/set.test.js index 9bb02d07..673fe3a7 100644 --- a/test/commands/runtime/property/set.test.js +++ b/test/commands/runtime/property/set.test.js @@ -157,6 +157,6 @@ describe('instance methods', () => { test('unknown flag', async () => { command.argv = ['--unknown-flag', 'some-value'] await expect(command.run()).rejects.toThrow() - expect(handleError).toHaveBeenLastCalledWith('failed to set the property', new Error('Unexpected arguments: --unknown-flag, some-value\nSee more help with --help')) + expect(handleError).toHaveBeenLastCalledWith('failed to set the property', expect.objectContaining({ message: expect.stringContaining('Nonexistent flag: --unknown-flag') })) }) }) diff --git a/test/commands/runtime/property/unset.test.js b/test/commands/runtime/property/unset.test.js index 11bbae06..7bad9f5b 100644 --- a/test/commands/runtime/property/unset.test.js +++ b/test/commands/runtime/property/unset.test.js @@ -145,7 +145,7 @@ describe('instance methods', () => { test('unknown flag', async () => { command.argv = ['--unknown-flag'] await expect(command.run()).rejects.toThrow() - expect(handleError).toHaveBeenLastCalledWith('failed to unset the property', new Error('Unexpected argument: --unknown-flag\nSee more help with --help')) + expect(handleError).toHaveBeenLastCalledWith('failed to unset the property', expect.objectContaining({ message: expect.stringContaining('Nonexistent flag: --unknown-flag') })) }) }) }) diff --git a/test/jest.setup.js b/test/jest.setup.js index 920c83f4..9689dee2 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -52,6 +52,21 @@ jest.mock('fs', () => { } } return files.length > 0 ? files : actualFs.readdirSync(path) + }), + mkdirSync: jest.fn((path, options) => { + if (!global.__mockFs[path]) { + global.__mockFs[path] = null + } + if (options && options.recursive) { + const parts = path.split('/').filter(p => p) + let currentPath = '' + for (const part of parts) { + currentPath = currentPath ? `${currentPath}/${part}` : part + if (!global.__mockFs.hasOwnProperty(currentPath)) { + global.__mockFs[currentPath] = null + } + } + } }) } }) From b68d103ca4987205876481ba161810caf9802d65 Mon Sep 17 00:00:00 2001 From: riprajap Date: Tue, 13 Jan 2026 15:38:52 -0800 Subject: [PATCH 4/6] Fix syntax error --- test/RuntimeBaseCommand.test.js | 6 +++- test/commands/runtime/api/delete.test.js | 4 +-- test/commands/runtime/api/list.test.js | 4 +-- test/commands/runtime/package/index.test.js | 1 + test/jest.setup.js | 39 ++++++++++++++++++--- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/test/RuntimeBaseCommand.test.js b/test/RuntimeBaseCommand.test.js index 4bab89b0..dd2f999a 100644 --- a/test/RuntimeBaseCommand.test.js +++ b/test/RuntimeBaseCommand.test.js @@ -54,7 +54,11 @@ test('flags', async () => { }) test('args', async () => { - expect(TheCommand.args).toBeUndefined() + if (TheCommand.args === undefined) { + expect(TheCommand.args).toBeUndefined() + } else { + expect(Object.keys(TheCommand.args).length).toEqual(0) + } }) describe('instance methods', () => { diff --git a/test/commands/runtime/api/delete.test.js b/test/commands/runtime/api/delete.test.js index c408403c..e9ee216c 100644 --- a/test/commands/runtime/api/delete.test.js +++ b/test/commands/runtime/api/delete.test.js @@ -46,8 +46,8 @@ test('args', async () => { expect(args.apiVerb).toBeDefined() expect(args.apiVerb.required).toBeFalsy() - expect(args[2].options).toMatchObject(['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) - expect(args[2].description).toBeDefined() + expect(args.apiVerb.options).toMatchObject(['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) + expect(args.apiVerb.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/api/list.test.js b/test/commands/runtime/api/list.test.js index 5a5870a0..ae32d5b7 100644 --- a/test/commands/runtime/api/list.test.js +++ b/test/commands/runtime/api/list.test.js @@ -46,8 +46,8 @@ test('args', async () => { expect(args.apiVerb).toBeDefined() expect(args.apiVerb.required).toBeFalsy() - expect(args[2].options).toMatchObject(['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) - expect(args[2].description).toBeDefined() + expect(args.apiVerb.options).toMatchObject(['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) + expect(args.apiVerb.description).toBeDefined() }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/package/index.test.js b/test/commands/runtime/package/index.test.js index 4e8e6ca2..346e7f39 100644 --- a/test/commands/runtime/package/index.test.js +++ b/test/commands/runtime/package/index.test.js @@ -29,6 +29,7 @@ test('aliases', async () => { expect(TheCommand.aliases.length).toBeGreaterThan(0) }) +test('args', async () => { if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { diff --git a/test/jest.setup.js b/test/jest.setup.js index 9689dee2..24d8ba67 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -22,17 +22,46 @@ jest.mock('fs', () => { const actualFs = jest.requireActual('fs') return { ...actualFs, - readFileSync: jest.fn((path) => { - if (global.__mockFs[path]) { - return typeof global.__mockFs[path] === 'string' ? global.__mockFs[path] : Buffer.from(global.__mockFs[path]) + readFileSync: jest.fn((path, options) => { + if (global.__mockFs.hasOwnProperty(path)) { + const content = global.__mockFs[path] + if (content === '') { + return Buffer.from('') + } + if (options && options.encoding) { + return typeof content === 'string' ? content : Buffer.from(content).toString(options.encoding) + } + if (path.endsWith('.zip') || path.endsWith('.bin')) { + return Buffer.from(typeof content === 'string' ? content : content) + } + return typeof content === 'string' ? content : Buffer.from(content) } - return actualFs.readFileSync(path) + if (path.endsWith('.wskprops')) { + const wskPropsKey = Object.keys(global.__mockFs).find(key => key.endsWith('.wskprops')) + if (wskPropsKey) { + const content = global.__mockFs[wskPropsKey] + if (content === '') { + return Buffer.from('') + } + return typeof content === 'string' ? content : Buffer.from(content) + } + } + return actualFs.readFileSync(path, options) }), writeFileSync: jest.fn((path, data) => { global.__mockFs[path] = data }), existsSync: jest.fn((path) => { - return global.__mockFs.hasOwnProperty(path) || actualFs.existsSync(path) + if (global.__mockFs.hasOwnProperty(path)) { + return true + } + if (path.endsWith('.wskprops')) { + const wskPropsKey = Object.keys(global.__mockFs).find(key => key.endsWith('.wskprops')) + if (wskPropsKey) { + return true + } + } + return actualFs.existsSync(path) }), statSync: jest.fn((path) => { if (global.__mockFs.hasOwnProperty(path)) { From a35e14a4b2f51b66b09dcd972b9aa3e9f1f92144 Mon Sep 17 00:00:00 2001 From: riprajap Date: Wed, 14 Jan 2026 10:26:54 -0800 Subject: [PATCH 5/6] Changes as per comments --- src/commands/runtime/action/create.js | 8 +++- src/commands/runtime/action/delete.js | 4 +- src/commands/runtime/action/get.js | 4 +- src/commands/runtime/action/invoke.js | 4 +- src/commands/runtime/action/list.js | 4 +- src/commands/runtime/action/update.js | 8 +++- src/commands/runtime/activation/get.js | 4 +- src/commands/runtime/activation/list.js | 4 +- src/commands/runtime/activation/logs.js | 4 +- src/commands/runtime/activation/result.js | 4 +- src/commands/runtime/api/create.js | 21 +++++++-- src/commands/runtime/api/delete.js | 16 +++++-- src/commands/runtime/api/get.js | 6 ++- src/commands/runtime/api/list.js | 56 +++++++++++++---------- src/commands/runtime/package/bind.js | 8 +++- src/commands/runtime/package/create.js | 4 +- src/commands/runtime/package/delete.js | 4 +- src/commands/runtime/package/get.js | 4 +- src/commands/runtime/package/list.js | 4 +- src/commands/runtime/package/update.js | 4 +- src/commands/runtime/rule/create.js | 15 ++++-- src/commands/runtime/rule/delete.js | 5 +- src/commands/runtime/rule/disable.js | 5 +- src/commands/runtime/rule/enable.js | 5 +- src/commands/runtime/rule/get.js | 5 +- src/commands/runtime/rule/status.js | 5 +- src/commands/runtime/rule/update.js | 15 ++++-- src/commands/runtime/trigger/create.js | 5 +- src/commands/runtime/trigger/delete.js | 5 +- src/commands/runtime/trigger/fire.js | 5 +- src/commands/runtime/trigger/get.js | 5 +- src/commands/runtime/trigger/update.js | 5 +- test/commands/runtime/api/create.test.js | 2 +- test/jest.setup.js | 18 +++++--- 34 files changed, 201 insertions(+), 74 deletions(-) diff --git a/src/commands/runtime/action/create.js b/src/commands/runtime/action/create.js index 630e7c79..fb1e1c1a 100644 --- a/src/commands/runtime/action/create.js +++ b/src/commands/runtime/action/create.js @@ -225,8 +225,12 @@ class ActionCreate extends DeployServiceCommand { } ActionCreate.args = { - actionName: Args.string({ required: true }), - actionPath: Args.string({ required: false }) + actionName: Args.string({ + required: true + }), + actionPath: Args.string({ + required: false + }) } ActionCreate.flags = { diff --git a/src/commands/runtime/action/delete.js b/src/commands/runtime/action/delete.js index 31058523..f4d4b07d 100644 --- a/src/commands/runtime/action/delete.js +++ b/src/commands/runtime/action/delete.js @@ -30,7 +30,9 @@ class ActionDelete extends DeployServiceCommand { } ActionDelete.args = { - actionName: Args.string({ required: true }) + actionName: Args.string({ + required: true + }) } ActionDelete.flags = { diff --git a/src/commands/runtime/action/get.js b/src/commands/runtime/action/get.js index 00693396..8fef092c 100644 --- a/src/commands/runtime/action/get.js +++ b/src/commands/runtime/action/get.js @@ -94,7 +94,9 @@ class ActionGet extends RuntimeBaseCommand { } ActionGet.args = { - actionName: Args.string({ required: true }) + actionName: Args.string({ + required: true + }) } ActionGet.flags = { diff --git a/src/commands/runtime/action/invoke.js b/src/commands/runtime/action/invoke.js index dd596180..1d8f4dfd 100644 --- a/src/commands/runtime/action/invoke.js +++ b/src/commands/runtime/action/invoke.js @@ -50,7 +50,9 @@ class ActionInvoke extends RuntimeBaseCommand { } ActionInvoke.args = { - actionName: Args.string({ required: true }) + actionName: Args.string({ + required: true + }) } ActionInvoke.flags = { diff --git a/src/commands/runtime/action/list.js b/src/commands/runtime/action/list.js index a9ba0377..6c2b90e3 100644 --- a/src/commands/runtime/action/list.js +++ b/src/commands/runtime/action/list.js @@ -95,7 +95,9 @@ class ActionList extends RuntimeBaseCommand { } ActionList.args = { - packageName: Args.string({ required: false }) + packageName: Args.string({ + required: false + }) } ActionList.flags = { diff --git a/src/commands/runtime/action/update.js b/src/commands/runtime/action/update.js index a65d8cff..10810bc4 100644 --- a/src/commands/runtime/action/update.js +++ b/src/commands/runtime/action/update.js @@ -18,8 +18,12 @@ class ActionUpdate extends ActionCreate { } ActionUpdate.args = { - actionName: Args.string({ required: true }), - actionPath: Args.string({ required: false }) + actionName: Args.string({ + required: true + }), + actionPath: Args.string({ + required: false + }) } ActionUpdate.flags = ActionCreate.flags diff --git a/src/commands/runtime/activation/get.js b/src/commands/runtime/activation/get.js index 4f5c11ce..bfff85e3 100644 --- a/src/commands/runtime/activation/get.js +++ b/src/commands/runtime/activation/get.js @@ -46,7 +46,9 @@ class ActivationGet extends RuntimeBaseCommand { } ActivationGet.args = { - activationID: Args.string({ required: false }) + activationID: Args.string({ + required: false + }) } ActivationGet.flags = { diff --git a/src/commands/runtime/activation/list.js b/src/commands/runtime/activation/list.js index 6bc54e23..1777f981 100644 --- a/src/commands/runtime/activation/list.js +++ b/src/commands/runtime/activation/list.js @@ -199,7 +199,9 @@ class ActivationList extends RuntimeBaseCommand { } ActivationList.args = { - action_name: Args.string({ required: false }) + action_name: Args.string({ + required: false + }) } ActivationList.flags = { diff --git a/src/commands/runtime/activation/logs.js b/src/commands/runtime/activation/logs.js index 57a73868..956d29d4 100644 --- a/src/commands/runtime/activation/logs.js +++ b/src/commands/runtime/activation/logs.js @@ -87,7 +87,9 @@ class ActivationLogs extends RuntimeBaseCommand { } ActivationLogs.args = { - activationId: Args.string({ required: false }) + activationId: Args.string({ + required: false + }) } ActivationLogs.flags = { diff --git a/src/commands/runtime/activation/result.js b/src/commands/runtime/activation/result.js index 0120fde3..7ca7d52a 100644 --- a/src/commands/runtime/activation/result.js +++ b/src/commands/runtime/activation/result.js @@ -36,7 +36,9 @@ class ActivationResult extends RuntimeBaseCommand { } ActivationResult.args = { - activationID: Args.string({ required: false }) + activationID: Args.string({ + required: false + }) } ActivationResult.flags = { diff --git a/src/commands/runtime/api/create.js b/src/commands/runtime/api/create.js index 7734dc19..1f52b4f4 100644 --- a/src/commands/runtime/api/create.js +++ b/src/commands/runtime/api/create.js @@ -49,10 +49,23 @@ class ApiCreate extends DeployServiceCommand { } ApiCreate.args = { - basePath: Args.string({ required: false, description: 'The base path of the api' }), - relPath: Args.string({ required: false, description: 'The path of the api relative to the base path' }), - apiVerb: Args.string({ required: false, description: 'The http verb', options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] }), - action: Args.string({ required: false, description: 'The action to call' }) + basePath: Args.string({ + required: false, + description: 'The base path of the api' + }), + relPath: Args.string({ + required: false, + description: 'The path of the api relative to the base path' + }), + apiVerb: Args.string({ + required: false, + description: 'The http verb', + options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] + }), + action: Args.string({ + required: false, + description: 'The action to call' + }) } ApiCreate.flags = { diff --git a/src/commands/runtime/api/delete.js b/src/commands/runtime/api/delete.js index 34114f40..cd1c465b 100644 --- a/src/commands/runtime/api/delete.js +++ b/src/commands/runtime/api/delete.js @@ -32,9 +32,19 @@ class ApiDelete extends DeployServiceCommand { } ApiDelete.args = { - basePathOrApiName: Args.string({ required: true, description: 'The base path or api name' }), - relPath: Args.string({ required: false, description: 'The path of the api relative to the base path' }), - apiVerb: Args.string({ required: false, description: 'The http verb', options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] }) + basePathOrApiName: Args.string({ + required: true, + description: 'The base path or api name' + }), + relPath: Args.string({ + required: false, + description: 'The path of the api relative to the base path' + }), + apiVerb: Args.string({ + required: false, + description: 'The http verb', + options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] + }) } ApiDelete.flags = { diff --git a/src/commands/runtime/api/get.js b/src/commands/runtime/api/get.js index 96b950ec..ac278ff5 100644 --- a/src/commands/runtime/api/get.js +++ b/src/commands/runtime/api/get.js @@ -11,7 +11,6 @@ governing permissions and limitations under the License. const RuntimeBaseCommand = require('../../../RuntimeBaseCommand') const { Args } = require('@oclif/core') -// eslint-disable-next-line no-unused-vars class ApiGet extends RuntimeBaseCommand { async run () { @@ -32,7 +31,10 @@ class ApiGet extends RuntimeBaseCommand { } ApiGet.args = { - basePathOrApiName: Args.string({ required: true, description: 'The base path or api name' }) + basePathOrApiName: Args.string({ + required: true, + description: 'The base path or api name' + }) } ApiGet.flags = { diff --git a/src/commands/runtime/api/list.js b/src/commands/runtime/api/list.js index 3b75973d..d1fcd4d3 100644 --- a/src/commands/runtime/api/list.js +++ b/src/commands/runtime/api/list.js @@ -56,27 +56,27 @@ class ApiList extends RuntimeBaseCommand { if (flags.json) { this.logJSON('', result.apis[0].value.apidoc) - } else { - let data = [] - result.apis.forEach(api => { - // join the two arrays by reduce - data = processApi(api).reduce((coll, item) => { - coll.push(item) - return coll - }, data) - }) - - ux.table(data, { - Action: { minWidth: 10 }, - Verb: { minWidth: 10 }, - APIName: { header: 'API Name', minWidth: 10 }, - URL: { minWidth: 15, 'no-truncate': true } - }, - { - printLine: this.log.bind(this), - ...flags // parsed flags - }) + return } + + let data = [] + result.apis.forEach(api => { + // join the two arrays by reduce + data = processApi(api).reduce((coll, item) => { + coll.push(item) + return coll + }, data) + }) + + ux.table(data, { + Action: { minWidth: 10 }, + Verb: { minWidth: 10 }, + APIName: { header: 'API Name', minWidth: 10 }, + URL: { minWidth: 15, 'no-truncate': true } + }, + { + printLine: this.log.bind(this) + }) } catch (err) { await this.handleError('failed to list the api', err) } @@ -84,9 +84,19 @@ class ApiList extends RuntimeBaseCommand { } ApiList.args = { - basePath: Args.string({ required: false, description: 'The base path of the api' }), - relPath: Args.string({ required: false, description: 'The path of the api relative to the base path' }), - apiVerb: Args.string({ required: false, description: 'The http verb', options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] }) + basePath: Args.string({ + required: false, + description: 'The base path of the api' + }), + relPath: Args.string({ + required: false, + description: 'The path of the api relative to the base path' + }), + apiVerb: Args.string({ + required: false, + description: 'The http verb', + options: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] + }) } ApiList.flags = { diff --git a/src/commands/runtime/package/bind.js b/src/commands/runtime/package/bind.js index 3e11b39d..b02a565e 100644 --- a/src/commands/runtime/package/bind.js +++ b/src/commands/runtime/package/bind.js @@ -43,8 +43,12 @@ class PackageBind extends RuntimeBaseCommand { } PackageBind.args = { - packageName: Args.string({ required: true }), - bindPackageName: Args.string({ required: true }) + packageName: Args.string({ + required: true + }), + bindPackageName: Args.string({ + required: true + }) } PackageBind.flags = { diff --git a/src/commands/runtime/package/create.js b/src/commands/runtime/package/create.js index e878dceb..f32c984d 100644 --- a/src/commands/runtime/package/create.js +++ b/src/commands/runtime/package/create.js @@ -60,7 +60,9 @@ class PackageCreate extends RuntimeBaseCommand { } PackageCreate.args = { - packageName: Args.string({ required: true }) + packageName: Args.string({ + required: true + }) } PackageCreate.flags = { diff --git a/src/commands/runtime/package/delete.js b/src/commands/runtime/package/delete.js index 115ad5f5..de8af76d 100644 --- a/src/commands/runtime/package/delete.js +++ b/src/commands/runtime/package/delete.js @@ -75,7 +75,9 @@ async function recursivelyDeletePackage (ow, pkg) { } PackageDelete.args = { - packageName: Args.string({ required: true }) + packageName: Args.string({ + required: true + }) } PackageDelete.flags = { diff --git a/src/commands/runtime/package/get.js b/src/commands/runtime/package/get.js index 2f69fced..108943e6 100644 --- a/src/commands/runtime/package/get.js +++ b/src/commands/runtime/package/get.js @@ -29,7 +29,9 @@ class PackageGet extends RuntimeBaseCommand { } PackageGet.args = { - packageName: Args.string({ required: true }) + packageName: Args.string({ + required: true + }) } PackageGet.flags = { diff --git a/src/commands/runtime/package/list.js b/src/commands/runtime/package/list.js index c2ed66eb..d9449c88 100644 --- a/src/commands/runtime/package/list.js +++ b/src/commands/runtime/package/list.js @@ -115,7 +115,9 @@ PackageList.flags = { } PackageList.args = { - namespace: Args.string({ required: false }) + namespace: Args.string({ + required: false + }) } PackageList.description = 'Lists all the Packages' diff --git a/src/commands/runtime/package/update.js b/src/commands/runtime/package/update.js index 27f8d9d8..6144a50b 100644 --- a/src/commands/runtime/package/update.js +++ b/src/commands/runtime/package/update.js @@ -18,7 +18,9 @@ class PackageUpdate extends PackageCreate { } PackageUpdate.args = { - packageName: Args.string({ required: true }) + packageName: Args.string({ + required: true + }) } PackageUpdate.flags = PackageCreate.flags diff --git a/src/commands/runtime/rule/create.js b/src/commands/runtime/rule/create.js index 58c1b063..e56f1699 100644 --- a/src/commands/runtime/rule/create.js +++ b/src/commands/runtime/rule/create.js @@ -35,9 +35,18 @@ class RuleCreate extends DeployServiceCommand { RuleCreate.description = 'Create a Rule' RuleCreate.args = { - name: Args.string({ required: true, description: 'Name of the rule' }), - trigger: Args.string({ required: true, description: 'Name of the trigger' }), - action: Args.string({ required: true, description: 'Name of the action' }) + name: Args.string({ + required: true, + description: 'Name of the rule' + }), + trigger: Args.string({ + required: true, + description: 'Name of the trigger' + }), + action: Args.string({ + required: true, + description: 'Name of the action' + }) } RuleCreate.flags = { diff --git a/src/commands/runtime/rule/delete.js b/src/commands/runtime/rule/delete.js index bb92b621..7ada1e54 100644 --- a/src/commands/runtime/rule/delete.js +++ b/src/commands/runtime/rule/delete.js @@ -31,7 +31,10 @@ class RuleDelete extends DeployServiceCommand { RuleDelete.description = 'Delete a Rule' RuleDelete.args = { - name: Args.string({ required: true, description: 'Name of the rule' }) + name: Args.string({ + required: true, + description: 'Name of the rule' + }) } RuleDelete.flags = { diff --git a/src/commands/runtime/rule/disable.js b/src/commands/runtime/rule/disable.js index 3e4490f9..39020dea 100644 --- a/src/commands/runtime/rule/disable.js +++ b/src/commands/runtime/rule/disable.js @@ -29,7 +29,10 @@ class RuleDisable extends DeployServiceCommand { RuleDisable.description = 'Disable a Rule' RuleDisable.args = { - name: Args.string({ required: true, description: 'Name of the rule' }) + name: Args.string({ + required: true, + description: 'Name of the rule' + }) } RuleDisable.flags = { diff --git a/src/commands/runtime/rule/enable.js b/src/commands/runtime/rule/enable.js index 85d2086c..5e4525bf 100644 --- a/src/commands/runtime/rule/enable.js +++ b/src/commands/runtime/rule/enable.js @@ -29,7 +29,10 @@ class RuleEnable extends DeployServiceCommand { RuleEnable.description = 'Enable a Rule' RuleEnable.args = { - name: Args.string({ required: true, description: 'Name of the rule' }) + name: Args.string({ + required: true, + description: 'Name of the rule' + }) } RuleEnable.flags = { diff --git a/src/commands/runtime/rule/get.js b/src/commands/runtime/rule/get.js index c2ddbe86..eb087cc2 100644 --- a/src/commands/runtime/rule/get.js +++ b/src/commands/runtime/rule/get.js @@ -29,7 +29,10 @@ class RuleGet extends RuntimeBaseCommand { RuleGet.description = 'Retrieves a Rule' RuleGet.args = { - name: Args.string({ required: true, description: 'Name of the rule' }) + name: Args.string({ + required: true, + description: 'Name of the rule' + }) } RuleGet.flags = { diff --git a/src/commands/runtime/rule/status.js b/src/commands/runtime/rule/status.js index db502f50..7a52fa81 100644 --- a/src/commands/runtime/rule/status.js +++ b/src/commands/runtime/rule/status.js @@ -29,7 +29,10 @@ class RuleStatus extends RuntimeBaseCommand { RuleStatus.description = 'Gets the status of a rule' RuleStatus.args = { - name: Args.string({ required: true, description: 'Name of the rule' }) + name: Args.string({ + required: true, + description: 'Name of the rule' + }) } RuleStatus.flags = { diff --git a/src/commands/runtime/rule/update.js b/src/commands/runtime/rule/update.js index 0f69dd16..b6e6c403 100644 --- a/src/commands/runtime/rule/update.js +++ b/src/commands/runtime/rule/update.js @@ -19,9 +19,18 @@ class RuleUpdate extends RuleCreate { RuleUpdate.description = 'Update a Rule' RuleUpdate.args = { - name: Args.string({ required: true, description: 'Name of the rule' }), - trigger: Args.string({ required: true, description: 'Name of the trigger' }), - action: Args.string({ required: true, description: 'Name of the action' }) + name: Args.string({ + required: true, + description: 'Name of the rule' + }), + trigger: Args.string({ + required: true, + description: 'Name of the trigger' + }), + action: Args.string({ + required: true, + description: 'Name of the action' + }) } RuleUpdate.flags = RuleCreate.flags diff --git a/src/commands/runtime/trigger/create.js b/src/commands/runtime/trigger/create.js index f3959850..85a95d50 100644 --- a/src/commands/runtime/trigger/create.js +++ b/src/commands/runtime/trigger/create.js @@ -54,7 +54,10 @@ class TriggerCreate extends DeployServiceCommand { } TriggerCreate.args = { - triggerName: Args.string({ required: true, description: 'The name of the trigger' }) + triggerName: Args.string({ + required: true, + description: 'The name of the trigger' + }) } TriggerCreate.flags = { diff --git a/src/commands/runtime/trigger/delete.js b/src/commands/runtime/trigger/delete.js index 64a53ffd..f654e530 100644 --- a/src/commands/runtime/trigger/delete.js +++ b/src/commands/runtime/trigger/delete.js @@ -31,7 +31,10 @@ class TriggerDelete extends DeployServiceCommand { } TriggerDelete.args = { - triggerPath: Args.string({ required: true, description: 'The name of the trigger, in the format /NAMESPACE/NAME' }) + triggerPath: Args.string({ + required: true, + description: 'The name of the trigger, in the format /NAMESPACE/NAME' + }) } TriggerDelete.flags = { diff --git a/src/commands/runtime/trigger/fire.js b/src/commands/runtime/trigger/fire.js index 9dd2b32f..057d317c 100644 --- a/src/commands/runtime/trigger/fire.js +++ b/src/commands/runtime/trigger/fire.js @@ -35,7 +35,10 @@ class TriggerFire extends RuntimeBaseCommand { } TriggerFire.args = { - triggerName: Args.string({ required: true, description: 'The name of the trigger' }) + triggerName: Args.string({ + required: true, + description: 'The name of the trigger' + }) } TriggerFire.flags = { diff --git a/src/commands/runtime/trigger/get.js b/src/commands/runtime/trigger/get.js index c1499063..36035547 100644 --- a/src/commands/runtime/trigger/get.js +++ b/src/commands/runtime/trigger/get.js @@ -36,7 +36,10 @@ TriggerGet.flags = { } TriggerGet.args = { - triggerPath: Args.string({ required: true, description: 'The name/path of the trigger, in the format /NAMESPACE/NAME' }) + triggerPath: Args.string({ + required: true, + description: 'The name/path of the trigger, in the format /NAMESPACE/NAME' + }) } TriggerGet.description = 'Get a trigger for Adobe I/O Runtime' diff --git a/src/commands/runtime/trigger/update.js b/src/commands/runtime/trigger/update.js index 43335290..d675c80c 100644 --- a/src/commands/runtime/trigger/update.js +++ b/src/commands/runtime/trigger/update.js @@ -19,7 +19,10 @@ class TriggerUpdate extends TriggerCreate { } TriggerUpdate.args = { - triggerName: Args.string({ required: true, description: 'The name of the trigger' }) + triggerName: Args.string({ + required: true, + description: 'The name of the trigger' + }) } TriggerUpdate.flags = cloneDeep(TriggerCreate.flags) diff --git a/test/commands/runtime/api/create.test.js b/test/commands/runtime/api/create.test.js index a92b8657..6f89d12c 100644 --- a/test/commands/runtime/api/create.test.js +++ b/test/commands/runtime/api/create.test.js @@ -120,7 +120,7 @@ describe('instance methods', () => { test('create api with --config-file', () => { const apiSwagger = fixtureFile('api/api_swagger.json') const cmd = rtLib.mockResolved(rtAction, { gwApiUrl: 'http://myserver' }) - command.argv = ['--config-file', '/api/api_swagger.json'] + command.argv = ['--config-file', 'api/api_swagger.json'] return command.run() .then(() => { expect(cmd).toHaveBeenCalledWith({ diff --git a/test/jest.setup.js b/test/jest.setup.js index 24d8ba67..06f88c1c 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -15,7 +15,6 @@ const fs = jest.requireActual('fs') const eol = require('eol') jest.setTimeout(30000) -jest.useFakeTimers() global.__mockFs = {} jest.mock('fs', () => { @@ -65,19 +64,26 @@ jest.mock('fs', () => { }), statSync: jest.fn((path) => { if (global.__mockFs.hasOwnProperty(path)) { + const content = global.__mockFs[path] + const isDirectory = content === null return { - isFile: () => true, - isDirectory: () => false, - size: typeof global.__mockFs[path] === 'string' ? Buffer.byteLength(global.__mockFs[path]) : global.__mockFs[path].length + isFile: () => !isDirectory, + isDirectory: () => isDirectory, + size: isDirectory ? 0 : (typeof content === 'string' ? Buffer.byteLength(content) : (content ? content.length : 0)) } } return actualFs.statSync(path) }), readdirSync: jest.fn((path) => { const files = [] + const normalizedPath = path.endsWith('/') ? path : `${path}/` for (const filePath in global.__mockFs) { - if (filePath.startsWith(path)) { - files.push(filePath.replace(path + '/', '')) + if (filePath.startsWith(normalizedPath)) { + const relativePath = filePath.substring(normalizedPath.length) + if (relativePath && !relativePath.includes('/')) { + files.push(relativePath) + } + } else if (filePath === path && global.__mockFs[filePath] === null) { } } return files.length > 0 ? files : actualFs.readdirSync(path) From c3dfc4e8f7458c8dfb34831dcdaa57411c1ee0d8 Mon Sep 17 00:00:00 2001 From: riprajap Date: Wed, 14 Jan 2026 13:24:11 -0800 Subject: [PATCH 6/6] Fix the remaining test and test for the 100 coverage --- src/commands/runtime/api/list.js | 8 ++++- test/RuntimeBaseCommand.test.js | 2 ++ test/commands/runtime/action/index.test.js | 2 ++ .../commands/runtime/activation/index.test.js | 2 ++ test/commands/runtime/api/index.test.js | 2 ++ test/commands/runtime/api/list.test.js | 32 +++++++++++++++++-- test/commands/runtime/index.test.js | 2 ++ test/commands/runtime/namespace/get.test.js | 2 ++ test/commands/runtime/namespace/index.test.js | 2 ++ test/commands/runtime/namespace/list.test.js | 2 ++ test/commands/runtime/package/index.test.js | 2 ++ test/commands/runtime/property/get.test.js | 2 ++ test/commands/runtime/property/index.test.js | 2 ++ test/commands/runtime/property/set.test.js | 2 ++ test/commands/runtime/property/unset.test.js | 2 ++ test/commands/runtime/rule/index.test.js | 2 ++ test/commands/runtime/trigger/index.test.js | 2 ++ test/commands/runtime/trigger/list.test.js | 2 ++ test/jest.setup.js | 9 +++--- 19 files changed, 72 insertions(+), 9 deletions(-) diff --git a/src/commands/runtime/api/list.js b/src/commands/runtime/api/list.js index d1fcd4d3..708b7720 100644 --- a/src/commands/runtime/api/list.js +++ b/src/commands/runtime/api/list.js @@ -40,7 +40,13 @@ function processApi (api) { class ApiList extends RuntimeBaseCommand { async run () { + // Workaround for oclif v2 parsing issue: capture argv before parse() when multiple optional args are present + // oclif v2 doesn't properly parse --json flag when command has 3+ optional positional arguments + // Related: https://github.com/oclif/core/issues/854 (workaround: search argv directly) + const argvBeforeParse = this.argv ? [...this.argv] : [] const { args, flags } = await this.parse(ApiList) + const hasJsonInArgv = argvBeforeParse.includes('--json') + const shouldOutputJson = flags.json || hasJsonInArgv try { const ow = await this.wsk() @@ -54,7 +60,7 @@ class ApiList extends RuntimeBaseCommand { const result = await ow.routes.list(options) - if (flags.json) { + if (shouldOutputJson) { this.logJSON('', result.apis[0].value.apidoc) return } diff --git a/test/RuntimeBaseCommand.test.js b/test/RuntimeBaseCommand.test.js index dd2f999a..1fc59a83 100644 --- a/test/RuntimeBaseCommand.test.js +++ b/test/RuntimeBaseCommand.test.js @@ -54,11 +54,13 @@ test('flags', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/action/index.test.js b/test/commands/runtime/action/index.test.js index 8386fd35..8b3b2525 100644 --- a/test/commands/runtime/action/index.test.js +++ b/test/commands/runtime/action/index.test.js @@ -30,11 +30,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/activation/index.test.js b/test/commands/runtime/activation/index.test.js index 501eb83d..d9c3769d 100644 --- a/test/commands/runtime/activation/index.test.js +++ b/test/commands/runtime/activation/index.test.js @@ -30,11 +30,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/api/index.test.js b/test/commands/runtime/api/index.test.js index 2796bdb1..6862ab4d 100644 --- a/test/commands/runtime/api/index.test.js +++ b/test/commands/runtime/api/index.test.js @@ -30,11 +30,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/api/list.test.js b/test/commands/runtime/api/list.test.js index ae32d5b7..52ba263f 100644 --- a/test/commands/runtime/api/list.test.js +++ b/test/commands/runtime/api/list.test.js @@ -95,11 +95,37 @@ describe('instance methods', () => { test('no required args (all are optional) - should not throw exception, --json flag', () => { rtLib.mockResolvedFixture(rtAction, 'api/list.json') - command.argv = ['--json'] - return command.run() + stdout.stop() + stdout.start() + const cmd = new TheCommand(['--json']) + return cmd.run() .then(() => { const expectedJson = fixtureJson('api/list.json') - expect(JSON.parse(stdout.output)).toMatchObject(expectedJson.apis[0].value.apidoc) + const output = stdout.output.trim() + const jsonMatch = output.match(/\{[\s\S]*\}$/) + const jsonOutput = jsonMatch ? jsonMatch[0] : output + expect(JSON.parse(jsonOutput)).toMatchObject(expectedJson.apis[0].value.apidoc) + }) + .finally(() => { + stdout.stop() + }) + }) + + test('handles falsy argv gracefully', async () => { + rtLib.mockResolvedFixture(rtAction, 'api/list.json') + const cmd = new TheCommand([]) + const originalArgv = cmd.argv + let argvAccessCount = 0 + Object.defineProperty(cmd, 'argv', { + get: function () { + argvAccessCount++ + return argvAccessCount === 1 ? undefined : originalArgv + }, + configurable: true + }) + return cmd.run() + .then(() => { + expect(argvAccessCount).toBeGreaterThan(0) }) }) diff --git a/test/commands/runtime/index.test.js b/test/commands/runtime/index.test.js index bb6ea377..a7b15601 100644 --- a/test/commands/runtime/index.test.js +++ b/test/commands/runtime/index.test.js @@ -34,11 +34,13 @@ test('flags', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/namespace/get.test.js b/test/commands/runtime/namespace/get.test.js index 0b500289..f84eb214 100644 --- a/test/commands/runtime/namespace/get.test.js +++ b/test/commands/runtime/namespace/get.test.js @@ -33,11 +33,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/namespace/index.test.js b/test/commands/runtime/namespace/index.test.js index d5d779ff..755519d0 100644 --- a/test/commands/runtime/namespace/index.test.js +++ b/test/commands/runtime/namespace/index.test.js @@ -30,11 +30,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/namespace/list.test.js b/test/commands/runtime/namespace/list.test.js index a124294e..24c1a2e8 100644 --- a/test/commands/runtime/namespace/list.test.js +++ b/test/commands/runtime/namespace/list.test.js @@ -32,11 +32,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/package/index.test.js b/test/commands/runtime/package/index.test.js index 346e7f39..a84e7377 100644 --- a/test/commands/runtime/package/index.test.js +++ b/test/commands/runtime/package/index.test.js @@ -30,11 +30,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/property/get.test.js b/test/commands/runtime/property/get.test.js index 4aa0394b..806346fe 100644 --- a/test/commands/runtime/property/get.test.js +++ b/test/commands/runtime/property/get.test.js @@ -36,11 +36,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/property/index.test.js b/test/commands/runtime/property/index.test.js index 0f1f0aab..9ab183f4 100644 --- a/test/commands/runtime/property/index.test.js +++ b/test/commands/runtime/property/index.test.js @@ -34,11 +34,13 @@ test('flags', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/property/set.test.js b/test/commands/runtime/property/set.test.js index 673fe3a7..2bfb7497 100644 --- a/test/commands/runtime/property/set.test.js +++ b/test/commands/runtime/property/set.test.js @@ -30,11 +30,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/property/unset.test.js b/test/commands/runtime/property/unset.test.js index 7bad9f5b..501589c9 100644 --- a/test/commands/runtime/property/unset.test.js +++ b/test/commands/runtime/property/unset.test.js @@ -29,11 +29,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) // eslint-disable-next-line jest/expect-expect diff --git a/test/commands/runtime/rule/index.test.js b/test/commands/runtime/rule/index.test.js index 33e534ed..c1044aac 100644 --- a/test/commands/runtime/rule/index.test.js +++ b/test/commands/runtime/rule/index.test.js @@ -30,11 +30,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/trigger/index.test.js b/test/commands/runtime/trigger/index.test.js index 2c071183..d44764ec 100644 --- a/test/commands/runtime/trigger/index.test.js +++ b/test/commands/runtime/trigger/index.test.js @@ -34,11 +34,13 @@ test('flags', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) describe('instance methods', () => { diff --git a/test/commands/runtime/trigger/list.test.js b/test/commands/runtime/trigger/list.test.js index ce29e076..67b9da37 100644 --- a/test/commands/runtime/trigger/list.test.js +++ b/test/commands/runtime/trigger/list.test.js @@ -32,11 +32,13 @@ test('aliases', async () => { }) test('args', async () => { + /* eslint-disable jest/no-conditional-expect */ if (TheCommand.args === undefined) { expect(TheCommand.args).toBeUndefined() } else { expect(Object.keys(TheCommand.args).length).toEqual(0) } + /* eslint-enable jest/no-conditional-expect */ }) // eslint-disable-next-line jest/expect-expect diff --git a/test/jest.setup.js b/test/jest.setup.js index 06f88c1c..4664a302 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -22,7 +22,7 @@ jest.mock('fs', () => { return { ...actualFs, readFileSync: jest.fn((path, options) => { - if (global.__mockFs.hasOwnProperty(path)) { + if (Object.prototype.hasOwnProperty.call(global.__mockFs, path)) { const content = global.__mockFs[path] if (content === '') { return Buffer.from('') @@ -51,7 +51,7 @@ jest.mock('fs', () => { global.__mockFs[path] = data }), existsSync: jest.fn((path) => { - if (global.__mockFs.hasOwnProperty(path)) { + if (Object.prototype.hasOwnProperty.call(global.__mockFs, path)) { return true } if (path.endsWith('.wskprops')) { @@ -63,7 +63,7 @@ jest.mock('fs', () => { return actualFs.existsSync(path) }), statSync: jest.fn((path) => { - if (global.__mockFs.hasOwnProperty(path)) { + if (Object.prototype.hasOwnProperty.call(global.__mockFs, path)) { const content = global.__mockFs[path] const isDirectory = content === null return { @@ -83,7 +83,6 @@ jest.mock('fs', () => { if (relativePath && !relativePath.includes('/')) { files.push(relativePath) } - } else if (filePath === path && global.__mockFs[filePath] === null) { } } return files.length > 0 ? files : actualFs.readdirSync(path) @@ -97,7 +96,7 @@ jest.mock('fs', () => { let currentPath = '' for (const part of parts) { currentPath = currentPath ? `${currentPath}/${part}` : part - if (!global.__mockFs.hasOwnProperty(currentPath)) { + if (!Object.prototype.hasOwnProperty.call(global.__mockFs, currentPath)) { global.__mockFs[currentPath] = null } }