Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a unit test for proto with no package #314

Merged
merged 1 commit into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}