While the preprocessor does not implement a native setWorldConstructor, you can replicate its behavior by using a beforeEach hook in your Cypress support file.
By defining a state object and using Object.assign(this, world) inside a beforeEach function, you can attach custom methods and variables to the Cucumber world context, making them available to all step definitions via this.
// cypress/support/e2e.ts
beforeEach(function () {
const world = {
variable: 0,
setTo(number) {
this.variable = number;
},
incrementBy(number) {
this.variable += number;
}
};
Object.assign(this, world);
});