Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/noriste/cypress-protobuf
- Owner: NoriSte
- Created: 2019-03-23T16:21:28.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-24T22:39:41.000Z (almost 2 years ago)
- Last Synced: 2024-10-27T10:36:09.635Z (2 months ago)
- Topics: cypress, protobuf
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/cypress-protobuf
- Size: 340 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
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/)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)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!