Search code examples
cypresscypress-cucumber-preprocessor

Pushing aws-eventbridge events with Cypress 13


For a test I need to push an event into aws-eventbridge I had the following code which was working on Cypress 12.7

on steps.ts:

Given("the user has an event", async () => {
    const payload = indexerPayload([{}]); // this just returns an static object with default values
    cy.task("seedTx", payload).then((r) => {
        cy.log(JSON.stringify(r, null, 2));
    });
    cy.wait(5000);
});

on cypress.config.ts

  on(
    "task",{
      'seedTx': (mockIndexerPayload) => {
        return insertTxEvents([mockIndexerPayload]);
      }
    }
  );

on eventBridge.ts I have

export const insertTxEvents = async (txs: object[]) => {

  const client = new EventBridgeClient({region: 'eu-west-1'});
  const entries = txs.map((tx) => {
    return { 
      Time: new Date("TIMESTAMP"),
      Source: "TEST",
      Resources: [],
      DetailType: "EVENT_DETAIL",
      Detail: JSON.stringify(tx, null, 2),
      EventBusName: "my-bus",
      TraceHeader: "Tests",
    };
  });
  const input = {
    Entries: entries
  };
  const command = new PutEventsCommand(input);
  return client.send(command);
};

this was working fine until I tried to update to Cypress 13, now I get no warnings on the IDE but when this step runs I get:

cucumber preprocessor detected that you returned a native promise from a function handler, this is not supported. using async / await is generally speaking not supported when using cypress, period, preprocessor or not.

Can anyone help? Would rather not be stuck in cypress 12.

I've tried a bunch of wrapping around this but I cannot make this error go away


Solution

  • Remove the async keyword from the function parameter of Given(..).