mirror of https://github.com/grpc/grpc-web.git
				
				
				
			Refactoring after review feedback
This commit is contained in:
		
							parent
							
								
									367e964889
								
							
						
					
					
						commit
						1f6c7cb813
					
				| 
						 | 
				
			
			@ -179,12 +179,34 @@ describe('grpc-web plugin test, proto with no package', function() {
 | 
			
		|||
    '--js_out=import_style=commonjs:./test/generated ' +
 | 
			
		||||
    '--grpc-web_out=import_style=commonjs,mode=grpcwebtext:./test/generated';
 | 
			
		||||
 | 
			
		||||
  var request;
 | 
			
		||||
  var myClient;
 | 
			
		||||
  var myPromiseClient;
 | 
			
		||||
 | 
			
		||||
  before(function() {
 | 
			
		||||
    ['protoc', 'protoc-gen-grpc-web'].map(prog => {
 | 
			
		||||
      if (!commandExists(prog)) {
 | 
			
		||||
        assert.fail(`${prog} is not installed`);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    removeDirectory(path.resolve(__dirname, GENERATED_CODE_PATH));
 | 
			
		||||
    fs.mkdirSync(path.resolve(__dirname, GENERATED_CODE_PATH));
 | 
			
		||||
 | 
			
		||||
    execSync(genCodeCmd);
 | 
			
		||||
    assert.equal(true, fs.existsSync(genCodePath1));
 | 
			
		||||
    assert.equal(true, fs.existsSync(genCodePath2));
 | 
			
		||||
 | 
			
		||||
    const {HelloRequest} = require(genCodePath1);
 | 
			
		||||
    request = new HelloRequest();
 | 
			
		||||
 | 
			
		||||
    const {GreeterClient} = require(genCodePath2);
 | 
			
		||||
    myClient = new GreeterClient("MyHostname", null, null);
 | 
			
		||||
    assert.equal('function', typeof myClient.sayHello);
 | 
			
		||||
 | 
			
		||||
    const {GreeterPromiseClient} = require(genCodePath2);
 | 
			
		||||
    myPromiseClient = new GreeterPromiseClient("MyHostname", null, null);
 | 
			
		||||
    assert.equal('function', typeof myPromiseClient.sayHello);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  beforeEach(function() {
 | 
			
		||||
| 
						 | 
				
			
			@ -198,54 +220,24 @@ describe('grpc-web plugin test, proto with no package', 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);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('PromiseClient: should exist', function() {
 | 
			
		||||
    execSync(genCodeCmd);
 | 
			
		||||
 | 
			
		||||
    const {HelloRequest} = require(genCodePath1);
 | 
			
		||||
 | 
			
		||||
    const {GreeterPromiseClient} = require(genCodePath2);
 | 
			
		||||
    var myClient = new GreeterPromiseClient("MyHostname", null, null);
 | 
			
		||||
    assert.equal('function', typeof myClient.sayHello);
 | 
			
		||||
 | 
			
		||||
    var p = myClient.sayHello(new HelloRequest(), {});
 | 
			
		||||
    var p = myPromiseClient.sayHello(request, {});
 | 
			
		||||
    assert.equal('function', typeof p.then);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('PromiseClient: response should resolve promise', function() {
 | 
			
		||||
    execSync(genCodeCmd);
 | 
			
		||||
 | 
			
		||||
    const {HelloRequest} = require(genCodePath1);
 | 
			
		||||
 | 
			
		||||
    const {GreeterPromiseClient} = require(genCodePath2);
 | 
			
		||||
    var myClient = new GreeterPromiseClient("MyHostname", null, null);
 | 
			
		||||
    assert.equal('function', typeof myClient.sayHello);
 | 
			
		||||
 | 
			
		||||
    MockXMLHttpRequest.onSend = function(xhr) {
 | 
			
		||||
      xhr.respond(200, {'Content-Type': 'application/grpc-web-text'},
 | 
			
		||||
                  // a single data frame with 'aaa' message, encoded
 | 
			
		||||
                  'AAAAAAUKA2FhYQ==');
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    myClient.sayHello(new HelloRequest(), {})
 | 
			
		||||
    myPromiseClient.sayHello(request, {})
 | 
			
		||||
                   .then((response) => {
 | 
			
		||||
                     assert.equal('aaa', response.getMessage());
 | 
			
		||||
                   });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue