Skip to content

Commit

Permalink
fix(core): support null handler
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jun 13, 2024
1 parent 24628ac commit 8ccb7e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 1 addition & 3 deletions packages/core/lib/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions packages/core/test/actions/call.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ccb7e3

Please sign in to comment.