Skip to content

Instantly share code, notes, and snippets.

@NoriSte
Created June 25, 2021 06:52
Show Gist options
  • Save NoriSte/4f178aa0a05433fe6d79b80c5134abee to your computer and use it in GitHub Desktop.
Save NoriSte/4f178aa0a05433fe6d79b80c5134abee to your computer and use it in GitHub Desktop.

Cypress Protobuf example

I was asked to provide an example of a Cypress test using Protobuf.

// cypress/plugins/index.js
module.exports = on => {
on("task", {
protobufEncode: require("cypress-protobuf"),
});
};
// custom Cypress command code
export function customRoute() {
return cy.fixture("fixture.json").then(json => {
cy.task("protobufEncode", {
fixtureBody: json,
message: "Status"
}).then(result => {
cy.route({
headers: {
// set content-type headers
"content-type": "application/octet-stream"
},
method: "GET",
response: result,
status: 200,
url: `**api/status`
}).as("customRoute");
});
});
}
Cypress.Commands.add("customRoute", customRoute);
// test's code
before(() => {
cy.task("protobufEncode", {
protoFilePath: "./public/ui.proto"
});
});
describe("Bar", () => {
it("Foo", () => {
cy.customRoute();
cy.wait("@customRoute");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment