Permalink
Browse files

Other: Coverage for encoder compat. / protocolerror

  • Loading branch information...
dcodeIO committed Mar 10, 2017
1 parent 948a4ca commit db1030ed257f9699a0bcf3bad0bbe8acccf5d766
Showing with 6 additions and 3 deletions.
  1. +2 −2 README.md
  2. +2 −1 src/encoder.js
  3. +2 −0 tests/other_protocolerror.js
@@ -1,5 +1,5 @@
<h1><p align="center"><img alt="protobuf.js" src="https://github.com/dcodeIO/protobuf.js/raw/master/pbjs.png" width="120" height="104" /></p></h1>
<p align="center"><a href="https://travis-ci.org/dcodeIO/protobuf.js"><img src="https://travis-ci.org/dcodeIO/protobuf.js.svg?branch=master" alt=""></a> <a href="https://codeclimate.com/github/dcodeIO/protobuf.js/coverage"><img src="https://codeclimate.com/github/dcodeIO/protobuf.js/badges/coverage.svg" /></a> <a href="https://codeclimate.com/github/dcodeIO/protobuf.js"><img src="https://codeclimate.com/github/dcodeIO/protobuf.js/badges/gpa.svg" /></a> <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg" alt=""></a> <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg" alt=""></a> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=Open%20Source%20Software%20Donation&item_number=dcodeIO%2Fprotobuf.js"><img alt="donate ❤" src="https://img.shields.io/badge/donate-❤-ff2244.svg"></a></p>
<p align="center"><a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg" alt=""></a> <a href="https://travis-ci.org/dcodeIO/protobuf.js"><img src="https://travis-ci.org/dcodeIO/protobuf.js.svg?branch=master" alt=""></a> <a href="https://codeclimate.com/github/dcodeIO/protobuf.js/coverage"><img src="https://codeclimate.com/github/dcodeIO/protobuf.js/badges/coverage.svg" /></a> <a href="https://codeclimate.com/github/dcodeIO/protobuf.js"><img src="https://codeclimate.com/github/dcodeIO/protobuf.js/badges/gpa.svg" /></a> <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg" alt=""></a> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=Open%20Source%20Software%20Donation&item_number=dcodeIO%2Fprotobuf.js"><img alt="donate ❤" src="https://img.shields.io/badge/donate-❤-ff2244.svg"></a></p>
**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/)).
@@ -346,7 +346,7 @@ Documentation
* [Frequently asked questions](https://github.com/dcodeIO/protobuf.js/wiki) on our wiki
#### Community
* [Questions and answers](http://stackoverflow.com/search?q=protobuf.js) on StackOverflow
* [Questions and answers](http://stackoverflow.com/search?tab=newest&q=protobuf.js) on StackOverflow
Command line
------------
@@ -49,12 +49,13 @@ function encoder(mtype) {
// "when a message is serialized its known fields should be written sequentially by field number"
var fields = /* initializes */ mtype.fieldsArray;
/* istanbul ignore else */
if (encoder.compat)
fields = fields.slice().sort(compareFieldsById);
for (var i = 0; i < fields.length; ++i) {
var field = fields[i].resolve(),
index = encoder.compat ? mtype._fieldsArray.indexOf(field) : i;
index = encoder.compat ? mtype._fieldsArray.indexOf(field) : /* istanbul ignore next */ i;
if (field.partOf) // see below for oneofs
continue;
var type = field.resolvedType instanceof Enum ? "uint32" : field.type,
@@ -27,6 +27,8 @@ tape.test("a protocol error", function(test) {
test.fail("should be thrown if a message is missing required fields");
} catch (e) {
test.ok(e instanceof ProtocolError, "should be thrown if a message is missing required fields");
test.ok(e.message, "should have an error message");
test.ok(e.stack, "should have a stack trace");
test.equal(e.name, "ProtocolError", "should have the correct name");
test.same(e.instance, {
foo: 2

0 comments on commit db1030e

Please sign in to comment.