Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/noriste/cypress-protobuf

Encode a fixture with Protocol Buffers
https://github.com/noriste/cypress-protobuf

cypress protobuf

Last synced: 2 months ago
JSON representation

Encode a fixture with Protocol Buffers

Awesome Lists containing this project

README

        

# Cypress Protocol Buffers
Encode a fixture with Protocol Buffers

[![Build Status](https://travis-ci.com/NoriSte/cypress-protobuf.svg?branch=master)](https://travis-ci.com/NoriSte/cypress-protobuf)
[![Build Status](https://img.shields.io/badge/build%20cron-weekly-44cc11.svg)](https://travis-ci.com/NoriSte/cypress-protobuf)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)

Cypress Protobuf

Use this plugin to encode a [Cypress](https://www.cypress.io) fixture with [Protocol Buffers](https://developers.google.com/protocol-buffers/).

# Installation
```bash
npm i -D cypress-protobuf
# or
yarn add -D cypress-protobuf
```

then open your `cypress/plugins/index.js` file and register a new task
```javascript
module.exports = on => {
on("task", {
protobufEncode: require("cypress-protobuf"),
});
};
```

# How to use it
To encode with Protocol Buffers a fixture
```javascript
cy.fixture("FIXTURE_NAME.json+")
.then(json => {
cy.task("protobufEncode", {
fixtureBody: json, // the fixture body
message: "MESSAGE_NAME", // the protobuf message to use
protoFilePath: "./public/example.proto", // the path (starting from your project directory) to the .profo file
})
.then(encodedJson => {
// 🎉 `encodedJson` contains the encoded fixture
cy.route({
headers: {
"content-type": "application/octet-stream"
},
response: encodedJson,
url: 'API_URL'
}).as("FIXTURE_NAME");
});
});
```

and in your test you will wait for the request as usual
```javascript
cy.wait("@YOUR_FIXTURE_NAME");
```

Take a look at the [example test](cypress/integration/cypress-protobuf.test.js) source code.

# Tips
- the plugin saves the last `protoFilePath` so you can avoid to pass it every time. You can even set it at the beginning of your test suite
```javascript
before(() => {
cy.task("protobufEncode", {
protoFilePath: "./public/escrow/ui.proto"
});
});
```

## Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

Stefano Magni
Stefano Magni

💻 ⚠️

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!