CodeceptJS
CodeceptJS copied to clipboard
hooks
-
I add hook to file codecept.conf.js as: exports.config = { hooks: ['./someHook.ts'],
-
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
[email protected] 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 (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.
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],
}
Confirmed with CodeceptJS 3.3.0 when setting https://github.com/codeceptjs/CodeceptJS/issues/661#issuecomment-602970615 @MumblesNZ thanks for workaround.