Skip to content

Commit

Permalink
Add a unit test for proto with no package
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley-cheung committed Oct 6, 2018
1 parent f92ceda commit b7ac151
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/grpc-web/test/plugin_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,53 @@ describe('grpc-web plugin test, with multiple input files', function() {
assert.equal('function', typeof myClientB.doThat);
});
});


describe('grpc-web plugin test, proto with no package', function() {
const genCodePath1 = path.resolve(
__dirname, GENERATED_CODE_PATH + '/nopackage_pb.js');
const genCodePath2 = path.resolve(
__dirname, GENERATED_CODE_PATH + '/nopackage_grpc_web_pb.js');

const genCodeCmd =
'protoc -I=./test/protos ' +
'./test/protos/nopackage.proto ' +
'--js_out=import_style=commonjs:./test/generated ' +
'--grpc-web_out=import_style=commonjs,mode=grpcwebtext:./test/generated';

before(function() {
['protoc', 'protoc-gen-grpc-web'].map(prog => {
if (!commandExists(prog)) {
assert.fail(`${prog} is not installed`);
}
});
});

beforeEach(function() {
removeDirectory(path.resolve(__dirname, GENERATED_CODE_PATH));
fs.mkdirSync(path.resolve(__dirname, GENERATED_CODE_PATH));
});

afterEach(function() {
removeDirectory(path.resolve(__dirname, GENERATED_CODE_PATH));
});

it('should exist', function() {
execSync(genCodeCmd);
assert.equal(true, fs.existsSync(genCodePath1));
assert.equal(true, fs.existsSync(genCodePath2));
});

it('should import', function() {
execSync(genCodeCmd);

const {HelloRequest} = require(genCodePath1);
var request = new HelloRequest();
request.setName('abc');
assert.equal('abc', request.getName());

const {GreeterClient} = require(genCodePath2);
var myClient = new GreeterClient("MyHostname", null, null);
assert.equal('function', typeof myClient.sayHello);
});
});
27 changes: 27 additions & 0 deletions packages/grpc-web/test/protos/nopackage.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}

message HelloRequest {
string name = 1;
}

message HelloReply {
string message = 1;
}

0 comments on commit b7ac151

Please sign in to comment.