Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hooks #3076

Closed
rebajz opened this issue Oct 12, 2021 · 2 comments
Closed

hooks #3076

rebajz opened this issue Oct 12, 2021 · 2 comments

Comments

@rebajz
Copy link

rebajz commented Oct 12, 2021

  1. I add hook to file codecept.conf.js as:
    exports.config = {
    hooks: ['./someHook.ts'],

  2. from https://codecept.io/hooks/#custom-hooks I copy your example

const event = require('codeceptjs').event;

module.exports = function() {

event.dispatcher.on(event.test.before, function (test) {

console.log('--- I am before test --');

});
}

to new file ./someHook.ts

after run codeceptjs i see this:

PS C:_git\sandbox> npm run run:tests

typescript-boilerplate@1.0.0 run:tests
codeceptjs run

CodeceptJS v3.1.3
Using test root "C:_git\sandbox"
(node:3740) UnhandledPromiseRejectionWarning: Error: CodeceptJS 3 allows bootstrap/teardown hooks only as async functions. More info: https://bit.ly/codecept3Up
at module.exports (C:_git\sandbox\node_modules\codeceptjs\lib\hooks.js:7:11)
at C:_git\sandbox\node_modules\codeceptjs\lib\codecept.js:101:39
at Array.forEach ()
at Codecept.runHooks (C:_git\sandbox\node_modules\codeceptjs\lib\codecept.js:101:23)
at Codecept.init (C:_git\sandbox\node_modules\codeceptjs\lib\codecept.js:57:10)
at module.exports (C:_git\sandbox\node_modules\codeceptjs\lib\command\run.js:24:14)
at Command. (C:_git\sandbox\node_modules\codeceptjs\bin\codecept.js:9:11)
at Command.listener (C:_git\sandbox\node_modules\commander\index.js:315:8)
at Command.emit (events.js:400:28)
at Command.parseArgs (C:_git\sandbox\node_modules\commander\index.js:651:12)
(Use node --trace-warnings ... to show where the warning was created)
(node:3740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To te
rminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3740) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Please upgrade your documentation page, with working example.

@MumblesNZ
Copy link
Contributor

As a workaround, we got the hooks to work by importing the modules explicitly, as the hooks array are expecting functions not module references.

i.e. in your codecept.js config file:

const myHook = require('pathToMyHook/myHook.js');
.....
exports.config = {
   ....
   hooks: [myHook],
}

@mirao
Copy link
Contributor

mirao commented Apr 2, 2022

Confirmed with CodeceptJS 3.3.0 when setting #661 (comment)
@MumblesNZ thanks for workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants