Skip to content

Commit

Permalink
test: rebuild tests for current runtime (protobufjs#1476)
Browse files Browse the repository at this point in the history
* Rebuild gentest sources

* Incorporate gentests into make

Also reorder tasks so type linting is done against newly generated code vs. old.

* fix: add newline to package.json

Co-authored-by: Alexander Fenster <fenster@google.com>
Co-authored-by: Alexander Fenster <github@fenster.name>
  • Loading branch information
3 people authored Sep 18, 2020
1 parent 9893e35 commit d871d97
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 70 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"prof": "node bench/prof",
"test": "npm run test:sources && npm run test:types",
"test:sources": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
"test:types": "tsc tests/comp_typescript.ts --lib es2015 --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc tests/data/test.js.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/rpc.ts --lib es2015 --noEmit --strictNullChecks",
"make": "npm run lint && npm run build && npm test"
"test:types": "tsc tests/comp_typescript.ts --lib es2015 --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc tests/data/test.js.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/*.ts --lib es2015 --noEmit --strictNullChecks",
"make": "npm run lint:sources && npm run build && npm run lint:types && node ./scripts/gentests.js && npm test"
},
"dependencies": {
"@protobufjs/aspromise": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion scripts/gentests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var fs = require("fs"),
out = [ basename ].concat(flags).join("-") + ".js";
pbjs.main([
"--target", "static-module",
"--wrap", "commonjs",
"--wrap", flags.includes('es6') ? 'es6' : "commonjs",
"--root", "test_" + path.basename(basename, ".js"),
file
].concat(flags.map(function(flag) {
Expand Down
1 change: 1 addition & 0 deletions tests/comp_typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
exports.__esModule = true;
exports.AwesomeMessage = exports.AwesomeSubMessage = exports.AwesomeEnum = exports.Hello = void 0;
var __1 = require("..");
// Reflection
var root = __1.Root.fromJSON({
Expand Down
24 changes: 19 additions & 5 deletions tests/data/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ $root.Message = (function() {
Message.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Message(), key;
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Message(), key, value;
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
Expand Down Expand Up @@ -248,12 +248,26 @@ $root.Message = (function() {
message.enumRepeated.push(reader.int32());
break;
case 9:
reader.skip().pos++;
if (message.int64Map === $util.emptyObject)
message.int64Map = {};
key = reader.string();
reader.pos++;
message.int64Map[key] = reader.int64();
var end2 = reader.uint32() + reader.pos;
key = "";
value = 0;
while (reader.pos < end2) {
var tag2 = reader.uint32();
switch (tag2 >>> 3) {
case 1:
key = reader.string();
break;
case 2:
value = reader.int64();
break;
default:
reader.skipType(tag2 & 7);
break;
}
}
message.int64Map[key] = value;
break;
default:
reader.skipType(tag & 7);
Expand Down
90 changes: 73 additions & 17 deletions tests/data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ $root.Package = (function() {
Package.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Package(), key;
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Package(), key, value;
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
Expand Down Expand Up @@ -325,36 +325,92 @@ $root.Package = (function() {
message.main = reader.string();
break;
case 11:
reader.skip().pos++;
if (message.bin === $util.emptyObject)
message.bin = {};
key = reader.string();
reader.pos++;
message.bin[key] = reader.string();
var end2 = reader.uint32() + reader.pos;
key = "";
value = "";
while (reader.pos < end2) {
var tag2 = reader.uint32();
switch (tag2 >>> 3) {
case 1:
key = reader.string();
break;
case 2:
value = reader.string();
break;
default:
reader.skipType(tag2 & 7);
break;
}
}
message.bin[key] = value;
break;
case 12:
reader.skip().pos++;
if (message.scripts === $util.emptyObject)
message.scripts = {};
key = reader.string();
reader.pos++;
message.scripts[key] = reader.string();
var end2 = reader.uint32() + reader.pos;
key = "";
value = "";
while (reader.pos < end2) {
var tag2 = reader.uint32();
switch (tag2 >>> 3) {
case 1:
key = reader.string();
break;
case 2:
value = reader.string();
break;
default:
reader.skipType(tag2 & 7);
break;
}
}
message.scripts[key] = value;
break;
case 13:
reader.skip().pos++;
if (message.dependencies === $util.emptyObject)
message.dependencies = {};
key = reader.string();
reader.pos++;
message.dependencies[key] = reader.string();
var end2 = reader.uint32() + reader.pos;
key = "";
value = "";
while (reader.pos < end2) {
var tag2 = reader.uint32();
switch (tag2 >>> 3) {
case 1:
key = reader.string();
break;
case 2:
value = reader.string();
break;
default:
reader.skipType(tag2 & 7);
break;
}
}
message.dependencies[key] = value;
break;
case 15:
reader.skip().pos++;
if (message.devDependencies === $util.emptyObject)
message.devDependencies = {};
key = reader.string();
reader.pos++;
message.devDependencies[key] = reader.string();
var end2 = reader.uint32() + reader.pos;
key = "";
value = "";
while (reader.pos < end2) {
var tag2 = reader.uint32();
switch (tag2 >>> 3) {
case 1:
key = reader.string();
break;
case 2:
value = reader.string();
break;
default:
reader.skipType(tag2 & 7);
break;
}
}
message.devDependencies[key] = value;
break;
case 17:
message.types = reader.string();
Expand Down
Loading

0 comments on commit d871d97

Please sign in to comment.