mirror of https://github.com/grpc/grpc-web.git
				
				
				
			Test both text and binary mode
This commit is contained in:
		
							parent
							
								
									17fbe35265
								
							
						
					
					
						commit
						621dd26180
					
				| 
						 | 
				
			
			@ -92,15 +92,27 @@ pid2=$(docker run -d --network=host -p 7074:7074 grpcweb/node-interop-server)
 | 
			
		|||
 | 
			
		||||
cd test/interop && \
 | 
			
		||||
  npm install && \
 | 
			
		||||
  npm link grpc-web && \
 | 
			
		||||
  protoc -I=../.. src/proto/grpc/testing/test.proto \
 | 
			
		||||
  npm link grpc-web
 | 
			
		||||
 | 
			
		||||
# Test grpc-web-text mode
 | 
			
		||||
protoc -I=../.. src/proto/grpc/testing/test.proto \
 | 
			
		||||
  src/proto/grpc/testing/empty.proto \
 | 
			
		||||
  src/proto/grpc/testing/messages.proto \
 | 
			
		||||
  --plugin=protoc-gen-grpc-web=$(pwd)/../../javascript/net/grpc/web/protoc-gen-grpc-web \
 | 
			
		||||
  --js_out=import_style=commonjs:. \
 | 
			
		||||
  --grpc-web_out=import_style=commonjs,mode=grpcwebtext:. && \
 | 
			
		||||
  npm test && \
 | 
			
		||||
  cd ../..
 | 
			
		||||
  npm test
 | 
			
		||||
 | 
			
		||||
# Test grpc-web mode (binary)
 | 
			
		||||
protoc -I=../.. src/proto/grpc/testing/test.proto \
 | 
			
		||||
  src/proto/grpc/testing/empty.proto \
 | 
			
		||||
  src/proto/grpc/testing/messages.proto \
 | 
			
		||||
  --plugin=protoc-gen-grpc-web=$(pwd)/../../javascript/net/grpc/web/protoc-gen-grpc-web \
 | 
			
		||||
  --js_out=import_style=commonjs:. \
 | 
			
		||||
  --grpc-web_out=import_style=commonjs,mode=grpcweb:. && \
 | 
			
		||||
  npm test -- --mode=binary
 | 
			
		||||
 | 
			
		||||
cd ../..
 | 
			
		||||
 | 
			
		||||
# Clean up
 | 
			
		||||
docker rm -f $pid1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -165,33 +165,45 @@ function doUnimplementedMethod(done) {
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
var testCases = {
 | 
			
		||||
  'empty_unary': doEmptyUnary,
 | 
			
		||||
  'large_unary': doLargeUnary,
 | 
			
		||||
  'server_streaming': doServerStreaming,
 | 
			
		||||
  'custom_metadata': doCustomMetadata,
 | 
			
		||||
  'status_code_and_message': doStatusCodeAndMessage,
 | 
			
		||||
  'unimplemented_method': doUnimplementedMethod
 | 
			
		||||
  'empty_unary': {testFunc: doEmptyUnary},
 | 
			
		||||
  'large_unary': {testFunc: doLargeUnary},
 | 
			
		||||
  'server_streaming': {testFunc: doServerStreaming,
 | 
			
		||||
                       skipBinaryMode: true},
 | 
			
		||||
  'custom_metadata': {testFunc: doCustomMetadata},
 | 
			
		||||
  'status_code_and_message': {testFunc: doStatusCodeAndMessage},
 | 
			
		||||
  'unimplemented_method': {testFunc: doUnimplementedMethod}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
if (typeof window === 'undefined') {
 | 
			
		||||
if (typeof window === 'undefined') { // Running from Node
 | 
			
		||||
  console.log('Running from Node...');
 | 
			
		||||
 | 
			
		||||
  // Fill in XHR runtime
 | 
			
		||||
  global.XMLHttpRequest = require("xhr2");
 | 
			
		||||
 | 
			
		||||
  var parseArgs = require('minimist');
 | 
			
		||||
  var argv = parseArgs(process.argv, {
 | 
			
		||||
    string: ['mode']
 | 
			
		||||
  });
 | 
			
		||||
  if (argv.mode == 'binary') {
 | 
			
		||||
    console.log('Testing grpc-web mode (binary)...');
 | 
			
		||||
  } else {
 | 
			
		||||
    console.log('Testing grpc-web-text mode...');
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  describe('grpc-web interop tests', function() {
 | 
			
		||||
    Object.keys(testCases).forEach((testCase) => {
 | 
			
		||||
      it('should pass '+testCase, testCases[testCase]);
 | 
			
		||||
      if (argv.mode == 'binary' && testCases[testCase].skipBinaryMode) return;
 | 
			
		||||
      it('should pass '+testCase, testCases[testCase].testFunc);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
} else {
 | 
			
		||||
  console.log('Running from browser...');
 | 
			
		||||
 | 
			
		||||
  Object.keys(testCases).forEach((testCase) => {
 | 
			
		||||
    var test = testCases[testCase];
 | 
			
		||||
    var testFunc = testCases[testCase].testFunc;
 | 
			
		||||
 | 
			
		||||
    var doneCalled = false;
 | 
			
		||||
    test((err) => {
 | 
			
		||||
    testFunc((err) => {
 | 
			
		||||
      if (err) {
 | 
			
		||||
        throw err;
 | 
			
		||||
      } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -4,13 +4,14 @@
 | 
			
		|||
  "description": "gRPC-Web Interop Test Client",
 | 
			
		||||
  "license": "Apache-2.0",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "test": "mocha -b --timeout 500 client.js"
 | 
			
		||||
    "test": "mocha -b --timeout 500 interop_client.js"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "google-protobuf": "~3.11.4",
 | 
			
		||||
    "grpc-web": "~1.0.0"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "minimist": "~1.2.5",
 | 
			
		||||
    "mocha": "~7.1.1",
 | 
			
		||||
    "webpack": "~4.43.0",
 | 
			
		||||
    "webpack-cli": "~3.3.11",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
module.exports = {
 | 
			
		||||
  mode: "production",
 | 
			
		||||
  entry: "./client.js",
 | 
			
		||||
  entry: "./interop_client.js",
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue