Skip to content

Commit db1030e

Browse files
committed
Other: Coverage for encoder compat. / protocolerror
1 parent 948a4ca commit db1030e

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<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>
2-
<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>
2+
<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>
33

44
**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/)).
55

@@ -346,7 +346,7 @@ Documentation
346346
* [Frequently asked questions](https://github.com/dcodeIO/protobuf.js/wiki) on our wiki
347347

348348
#### Community
349-
* [Questions and answers](http://stackoverflow.com/search?q=protobuf.js) on StackOverflow
349+
* [Questions and answers](http://stackoverflow.com/search?tab=newest&q=protobuf.js) on StackOverflow
350350

351351
Command line
352352
------------

src/encoder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ function encoder(mtype) {
4949

5050
// "when a message is serialized its known fields should be written sequentially by field number"
5151
var fields = /* initializes */ mtype.fieldsArray;
52+
/* istanbul ignore else */
5253
if (encoder.compat)
5354
fields = fields.slice().sort(compareFieldsById);
5455

5556
for (var i = 0; i < fields.length; ++i) {
5657
var field = fields[i].resolve(),
57-
index = encoder.compat ? mtype._fieldsArray.indexOf(field) : i;
58+
index = encoder.compat ? mtype._fieldsArray.indexOf(field) : /* istanbul ignore next */ i;
5859
if (field.partOf) // see below for oneofs
5960
continue;
6061
var type = field.resolvedType instanceof Enum ? "uint32" : field.type,

tests/other_protocolerror.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ tape.test("a protocol error", function(test) {
2727
test.fail("should be thrown if a message is missing required fields");
2828
} catch (e) {
2929
test.ok(e instanceof ProtocolError, "should be thrown if a message is missing required fields");
30+
test.ok(e.message, "should have an error message");
31+
test.ok(e.stack, "should have a stack trace");
3032
test.equal(e.name, "ProtocolError", "should have the correct name");
3133
test.same(e.instance, {
3234
foo: 2

0 commit comments

Comments
 (0)