* Represents a test hook in the testing framework * @class * @property {Object} suite - The test suite this hook belongs to * @property {Object} test - The test object associated with this hook * @property {Object} runnable - The current test being executed * @property {Object} ctx - The contex
| 12 | * @property {Error|null} err - The error that occurred during hook execution, if any |
| 13 | */ |
| 14 | class Hook { |
| 15 | /** |
| 16 | * Creates a new Hook instance |
| 17 | * @param {Object} context - The context object containing suite and test information |
| 18 | * @param {Object} context.suite - The test suite |
| 19 | * @param {Object} context.test - The test object |
| 20 | * @param {Object} context.ctx - The context object |
| 21 | * @param {Error} error - The error object if hook execution failed |
| 22 | */ |
| 23 | constructor(context, error) { |
| 24 | this.suite = context.suite |
| 25 | this.test = context.test |
| 26 | this.runnable = context?.ctx?.test |
| 27 | this.ctx = context.ctx |
| 28 | this.err = error |
| 29 | } |
| 30 | |
| 31 | get hookName() { |
| 32 | return this.constructor.name.replace('Hook', '') |
| 33 | } |
| 34 | |
| 35 | simplify() { |
| 36 | return { |
| 37 | hookName: this.hookName, |
| 38 | title: this.title, |
| 39 | // test: this.test ? serializeTest(this.test) : null, |
| 40 | // suite: this.suite ? serializeSuite(this.suite) : null, |
| 41 | error: this.err ? serializeError(this.err) : null, |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | toString() { |
| 46 | return this.hookName |
| 47 | } |
| 48 | |
| 49 | toCode() { |
| 50 | return this.toString() + '()' |
| 51 | } |
| 52 | |
| 53 | retry(n) { |
| 54 | this.suite.opts[`retry${this.hookName}`] = n |
| 55 | } |
| 56 | |
| 57 | get title() { |
| 58 | return this.ctx?.test?.title || this.name |
| 59 | } |
| 60 | |
| 61 | get name() { |
| 62 | return this.constructor.name |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | class BeforeHook extends Hook {} |
| 67 |
nothing calls this directly
no outgoing calls
no test coverage detected