We need to attach metadata (such as ticket IDs) to each test in Mocha. The ctx property allows us to store this data, but it is not serialized by default, making it unavailable in remote or reporting scenarios.
While investigating this, we found that a potential fix could be as simple as adding the ctx property to the serialized test object in toJSON, as shown below:
📌 File: packages\client\src\serialization.ts
if (value instanceof Test) {
// Polyfill missing methods
Object.assign(result, {
ctx: value.ctx,
});
}
beforeEach(function () {
if (this.currentTest?.ctx) {
this.currentTest.ctx = {
jira: 'ticket id',
};
}
});
This fix appears straightforward, but we're unsure if it's the best approach or if there are any unintended side effects.
Would this be an acceptable solution within mocha-remote, or is there a better way to achieve this? Any guidance or alternative suggestions would be greatly appreciated.
We need to attach metadata (such as ticket IDs) to each test in Mocha. The ctx property allows us to store this data, but it is not serialized by default, making it unavailable in remote or reporting scenarios.
While investigating this, we found that a potential fix could be as simple as adding the ctx property to the serialized test object in toJSON, as shown below:
📌 File: packages\client\src\serialization.ts
This fix appears straightforward, but we're unsure if it's the best approach or if there are any unintended side effects.
Would this be an acceptable solution within mocha-remote, or is there a better way to achieve this? Any guidance or alternative suggestions would be greatly appreciated.