Add a simple test for the xds package to the test job

This commit is contained in:
Michael Lumish 2020-10-23 14:57:18 -07:00
parent 261c40e51b
commit dc80dc1f17
6 changed files with 118 additions and 5 deletions

View File

@ -18,28 +18,29 @@
import * as gulp from 'gulp';
import * as healthCheck from './packages/grpc-health-check/gulpfile';
import * as jsCore from './packages/grpc-js/gulpfile';
import * as jsXds from './packages/grpc-js-xds/gulpfile';
import * as protobuf from './packages/proto-loader/gulpfile';
import * as internalTest from './test/gulpfile';
const installAll = gulp.series(jsCore.install, healthCheck.install, protobuf.install, internalTest.install);
const installAll = gulp.series(jsCore.install, healthCheck.install, protobuf.install, internalTest.install, jsXds.install);
const lint = gulp.parallel(jsCore.lint);
const build = gulp.series(jsCore.compile, protobuf.compile);
const build = gulp.series(jsCore.compile, protobuf.compile, jsXds.compile);
const setup = gulp.series(installAll);
const setupPureJSInterop = gulp.series(jsCore.install, protobuf.install, internalTest.install);
const clean = gulp.series(jsCore.clean, protobuf.clean);
const clean = gulp.series(jsCore.clean, protobuf.clean, jsXds.clean);
const cleanAll = gulp.series(jsCore.cleanAll, internalTest.cleanAll, protobuf.cleanAll);
const cleanAll = gulp.series(jsCore.cleanAll, internalTest.cleanAll, protobuf.cleanAll, jsXds.cleanAll);
const nativeTestOnly = gulp.parallel(healthCheck.test);
const nativeTest = gulp.series(build, nativeTestOnly);
const testOnly = gulp.parallel(jsCore.test, nativeTestOnly, protobuf.test);
const testOnly = gulp.parallel(jsCore.test, nativeTestOnly, protobuf.test, jsXds.test);
const test = gulp.series(build, testOnly, internalTest.test);

View File

@ -0,0 +1,78 @@
/*
* Copyright 2020 gRPC authors.
*
* 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
*
* http://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.
*
*/
import * as gulp from 'gulp';
import * as mocha from 'gulp-mocha';
import * as path from 'path';
import * as execa from 'execa';
import * as semver from 'semver';
Error.stackTraceLimit = Infinity;
const jsCoreDir = __dirname;
const outDir = path.resolve(jsCoreDir, 'build');
const pkgPath = path.resolve(jsCoreDir, 'package.json');
const supportedVersionRange = require(pkgPath).engines.node;
const versionNotSupported = () => {
console.log(`Skipping grpc-js-xds task for Node ${process.version}`);
return () => { return Promise.resolve(); };
};
const identity = (value: any): any => value;
const checkTask = semver.satisfies(process.version, supportedVersionRange) ?
identity : versionNotSupported;
const execNpmVerb = (verb: string, ...args: string[]) =>
execa('npm', [verb, ...args], {cwd: jsCoreDir, stdio: 'inherit'});
const execNpmCommand = execNpmVerb.bind(null, 'run');
const install = checkTask(() => execNpmVerb('install', '--unsafe-perm'));
/**
* Runs tslint on files in src/, with linting rules defined in tslint.json.
*/
const lint = checkTask(() => execNpmCommand('check'));
const cleanFiles = checkTask(() => execNpmCommand('clean'));
const clean = gulp.series(install, cleanFiles);
const cleanAll = gulp.parallel(clean);
/**
* Transpiles TypeScript files in src/ to JavaScript according to the settings
* found in tsconfig.json.
*/
const compile = checkTask(() => execNpmCommand('compile'));
const runTests = checkTask(() => {
return gulp.src(`${outDir}/test/**/*.js`)
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
require: ['ts-node/register']}));
});
const test = gulp.series(install, runTests);
export {
install,
lint,
clean,
cleanAll,
compile,
test
}

View File

@ -46,5 +46,8 @@
},
"peerDependencies": {
"@grpc/grpc-js": "~1.2.0"
},
"engines": {
"node": ">=10.10.0"
}
}

View File

@ -22,6 +22,9 @@ import * as load_balancer_lrs from './load-balancer-lrs';
import * as load_balancer_priority from './load-balancer-priority';
import * as load_balancer_weighted_target from './load-balancer-weighted-target';
/**
* Register the "xds:" name scheme with the @grpc/grpc-js library.
*/
export function register() {
resolver_xds.setup();
load_balancer_cds.setup();

View File

@ -0,0 +1,27 @@
/*
* Copyright 2020 gRPC authors.
*
* 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
*
* http://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.
*
*/
import * as assert from 'assert';
import { register } from '../src';
/* This is just a basic test to confirm that the package builds and the setup
* code runs. */
describe('register function', () => {
it('Should succeed without errors', () => {
assert.doesNotThrow(register);
});
});

View File

@ -10,6 +10,7 @@
},
"include": [
"src/**/*.ts",
"test/**/*.ts",
"interop/**/*.ts"
]
}