diff --git a/packages/core/lib/register.js b/packages/core/lib/register.js index 9514bc017..0a55ce5ff 100644 --- a/packages/core/lib/register.js +++ b/packages/core/lib/register.js @@ -3,9 +3,7 @@ import registry from "@nikitajs/core/registry"; // Action registration const actions = { - "": { - handler: function () {}, - }, + "": {}, assert: "@nikitajs/core/actions/assert", call: "@nikitajs/core/actions/call", execute: { diff --git a/packages/core/lib/session.js b/packages/core/lib/session.js index 92f7bb9ff..32ced50aa 100644 --- a/packages/core/lib/session.js +++ b/packages/core/lib/session.js @@ -178,7 +178,7 @@ const session = function(args, options = {}) { hooks: action.hooks.on_action, // || action.hooks.["nikita:action"] handler: function(action) { // Execution of an action handler - return action.handler.call(action.context, action); + return action.handler?.call(action.context, action); } }); // Ensure child actions are executed even after parent execution diff --git a/packages/core/test/actions/call.coffee b/packages/core/test/actions/call.coffee index 1816e48aa..de842a62a 100644 --- a/packages/core/test/actions/call.coffee +++ b/packages/core/test/actions/call.coffee @@ -21,6 +21,25 @@ describe 'actions.call', -> registry.unregister 'my_function' describe 'external module', -> + + they 'doesnt support plain declaration', ({ssh}) -> + # The problem has found a solution to support `metadata.module` + # Setting `metadata.module` conflict with the already defined value + # setup by `registry#load`. + # When argument is not defined (eg not a string, mapped to the handler), + # mapping the metadata.module create a infinite loop + # where `nikita.call` is importing itself + nikita + $ssh: ssh + $tmpdir: true + , ({metadata: {tmpdir}}) -> + result = await nikita.call + $: + metadata: + module: "#{tmpdir}/my_module.js" + config: + my_key: 'my value' + result.should.not.containEql my_key: 'my value' they 'defined as a function', ({ssh}) -> nikita