Create a short command to run working tests from a clean repo

This commit is contained in:
murgatroid99 2017-09-13 17:14:40 -07:00
parent 9ac919a4ff
commit 769737b969
9 changed files with 93 additions and 67 deletions

View File

@ -1,5 +1,6 @@
const _gulp = require('gulp');
const help = require('gulp-help');
const exec = require('child_process').exec;
// gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp);
@ -9,19 +10,47 @@ require('./packages/grpc-js-core/gulpfile');
require('./packages/grpc-native-core/gulpfile');
require('./test/gulpfile');
const root = __dirname;
gulp.task('install.all', 'Install dependencies for all subdirectory packages',
['js.core.install', 'native.core.install', 'health-check.install']);
gulp.task('lint', 'Emit linting errors in source and test files',
['js.core.lint', 'native.core.lint']);
gulp.task('link', 'Link local packages together',
['health-check.link', 'internal.test.link']);
gulp.task('build.only', 'Build packages without doing any installation',
['js.core.compile', 'native.core.build']);
gulp.task('build', 'Build packages',
['js.core.compile', 'native.core.build', 'link']);
gulp.task('build', 'Build packages', ['install.all'], () => {
gulp.start('build.only');
});
gulp.task('link.create.only', 'Initialize npm links to packages without rebuilding',
['native.core.link.create']);
gulp.task('link.create', 'Initialize npm links to packages', ['build'], () => {
gulp.start('link.create.only');
});
gulp.task('link.only', 'Link packages together without rebuilding anything',
['health-check.link.add', 'internal.test.link.add']);
gulp.task('link', 'Link local packages together after building',
['build', 'link.create.only'], () => {
gulp.start('link.only');
});
gulp.task('clean', 'Delete generated files', ['js.core.clean']);
gulp.task('native.test.only', 'Run tests of native code without rebuilding anything',
['native.core.test', 'internal.test.test', 'health-check.test']);
gulp.task('native.test', 'Run tests of native code', ['build', 'link'], () => {
gulp.start('native.test.only');
});
gulp.task('test.only', 'Run tests without rebuilding anything',
['js.core.test', 'native.core.test', 'internal.test.test', 'health-check.test']);
['js.core.test', 'native.test.only']);
gulp.task('test', 'Run all tests', ['build', 'link'], () => {
gulp.start('test.only');

View File

@ -8,27 +8,34 @@
"name": "Google Inc."
},
"license": "Apache-2.0",
"devDependencies": {
"dependencies": {
"async": "^2.5.0",
"body-parser": "^1.18.0",
"express": "^4.15.4",
"google-auth-library": "^0.11.0",
"grpc": "^1.6.0",
"gulp": "^3.9.1",
"gulp-help": "^1.6.1",
"lodash": "^4.17.4",
"poisson-process": "^0.2.2"
},
"scripts": {
"install": "cd packages/grpc-js-core && npm install"
"devDependencies": {
"del": "^3.0.0",
"gulp": "^3.9.1",
"gulp-help": "^1.6.1",
"gulp-jshint": "^2.0.4",
"gulp-mocha": "^4.3.1",
"gulp-sourcemaps": "^2.6.1",
"gulp-tslint": "^8.1.1",
"gulp-typescript": "^3.2.2",
"gulp-util": "^3.0.8",
"jshint": "^2.9.5",
"merge2": "^1.1.0",
"mocha": "^3.5.3",
"through2": "^2.0.3",
"tslint": "^5.5.0",
"typescript": "^2.5.1"
},
"contributors": [
{
"name": "Google Inc."
}
],
"dependencies": {
"gulp-mocha": "^4.3.1",
"mocha": "^3.5.3"
}
]
}

View File

@ -6,15 +6,19 @@ const path = require('path');
const gulp = help(_gulp);
const hcCoreDir = __dirname;
const baseDir = path.resolve(hcCoreDir, '..', '..');
const testDir = path.resolve(hcCoreDir, 'test');
const healthCheckDir = __dirname;
const baseDir = path.resolve(healthCheckDir, '..', '..');
const testDir = path.resolve(healthCheckDir, 'test');
gulp.task('health-check.link', 'Link local copy of grpc', (cb) => {
return exec(`cd ${hcCoreDir} && npm link ${baseDir}/packages/grpc-native-core`, cb);
gulp.task('health-check.install', 'Install health check dependencies', (cb) => {
return exec(`cd ${healthCheckDir} && npm install`, cb);
});
gulp.task('health-check.test', 'Run health check tests', ['health-check.link'],
gulp.task('health-check.link.add', 'Link local copy of grpc', ['health-check.install'], (cb) => {
return exec(`cd ${healthCheckDir} && npm link grpc`, cb);
});
gulp.task('health-check.test', 'Run health check tests', ['health-check.install', 'health-check.link.add'],
() => {
return gulp.src(`${testDir}/*.js`).pipe(mocha());
});

View File

@ -13,6 +13,7 @@ const util = require('gulp-util');
const merge2 = require('merge2');
const path = require('path');
const through = require('through2');
const exec = require('child_process').exec;
Error.stackTraceLimit = Infinity;
@ -75,10 +76,14 @@ function makeCompileFn(globs) {
};
}
gulp.task('js.core.install', 'Install native core dependencies', (cb) => {
return exec(`cd ${jsCoreDir} && npm install`, cb);
});
/**
* Runs tslint on files in src/, with linting rules defined in tslint.json.
*/
gulp.task('js.core.lint', 'Emits linting errors found in src/ and test/.', () => {
gulp.task('js.core.lint', 'Emits linting errors found in src/ and test/.', ['js.core.install'], () => {
const program = require('tslint').Linter.createProgram(tsconfigPath);
gulp.src([`${srcDir}/**/*.ts`, `${testDir}/**/*.ts`])
.pipe(tslint({
@ -100,13 +105,13 @@ gulp.task('js.core.clean', 'Deletes transpiled code.', () => {
* Currently, all errors are emitted twice. This is being tracked here:
* https://github.com/ivogabe/gulp-typescript/issues/438
*/
gulp.task('js.core.compile', 'Transpiles src/.',
gulp.task('js.core.compile', 'Transpiles src/.', ['js.core.install'],
makeCompileFn({ transpile: [`${srcDir}/**/*.ts`] }));
/**
* Transpiles TypeScript files in both src/ and test/.
*/
gulp.task('js.core.test.compile', 'After dep tasks, transpiles test/.', ['js.core.compile'],
gulp.task('js.core.test.compile', 'After dep tasks, transpiles test/.', ['js.core.install', 'js.core.compile'],
makeCompileFn({ transpile: [`${testDir}/**/*.ts`], copy: `${testDir}/**/!(*.ts)` }));
/**
@ -122,7 +127,7 @@ gulp.task('js.core.test', 'After dep tasks, runs all tests.',
/**
* Transpiles individual files, specified by the --file flag.
*/
gulp.task('js.core.compile.single', 'Transpiles individual files specified by --file.',
gulp.task('js.core.compile.single', 'Transpiles individual files specified by --file.', ['js.core.install'],
makeCompileFn({
transpile: files.map(f => path.relative('.', f))
})

View File

@ -18,16 +18,7 @@
"@types/mocha": "^2.2.42",
"@types/node": "^8.0.25",
"clang-format": "^1.0.53",
"del": "^3.0.0",
"google-ts-style": "^0.2.0",
"gulp-sourcemaps": "^2.6.1",
"gulp-tslint": "^8.1.1",
"gulp-typescript": "^3.2.2",
"gulp-util": "^3.0.8",
"merge2": "^1.1.0",
"through2": "^2.0.3",
"tslint": "^5.5.0",
"typescript": "^2.5.1"
"google-ts-style": "^0.2.0"
},
"contributors": [
{

View File

@ -16,16 +16,24 @@ const testDir = path.resolve(nativeCoreDir, 'test');
const pkg = require('./package');
const jshintConfig = pkg.jshintConfig;
gulp.task('native.core.lint', 'Emits linting errors', () => {
gulp.task('native.core.install', 'Install native core dependencies', (cb) => {
return exec(`cd ${nativeCoreDir} && npm install`, cb);
});
gulp.task('native.core.link.create', 'Create npm link', ['native.core.install'], (cb) => {
return exec(`cd ${nativeCoreDir} && npm link`, cb);
});
gulp.task('native.core.lint', 'Emits linting errors', ['native.core.install'], () => {
return gulp.src([`${nativeCoreDir}/index.js`, `${srcDir}/*.js`, `${testDir}/*.js`])
.pipe(jshint(pkg.jshintConfig))
.pipe(jshint.reporter('default'));
});
gulp.task('native.core.build', 'Build native package', (cb) => {
gulp.task('native.core.build', 'Build native package', ['native.core.install'], (cb) => {
return exec(`cd ${nativeCoreDir} && ${nativeCoreDir}/node_modules/.bin/node-pre-gyp build`, cb);
});
gulp.task('native.core.test', 'Run all tests', ['native.core.build'], () => {
gulp.task('native.core.test', 'Run all tests', ['native.core.install', 'native.core.build'], () => {
return gulp.src(`${testDir}/*.js`).pipe(mocha());
});

View File

@ -31,7 +31,6 @@
],
"dependencies": {
"arguejs": "^0.2.3",
"gulp-jshint": "^2.0.4",
"lodash": "^4.15.0",
"nan": "^2.0.0",
"node-pre-gyp": "^0.6.35",
@ -46,7 +45,6 @@
"google-protobuf": "^3.0.0",
"istanbul": "^0.4.4",
"jsdoc": "^3.3.2",
"jshint": "^2.5.0",
"minimist": "^1.1.0",
"mocha-jenkins-reporter": "^0.2.3",
"poisson-process": "^0.2.1"

View File

@ -21,8 +21,6 @@
var assert = require('assert');
var _ = require('lodash');
var ProtoBuf = require('protobufjs');
var grpc = require('grpc');
var MathClient = grpc.load(
@ -283,9 +281,7 @@ describe('Echo service', function() {
var server;
var client;
before(function() {
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto');
var echo_service = test_proto.lookup('EchoService');
var Client = grpc.loadObject(echo_service);
var Client = grpc.load(__dirname + '/echo_service.proto').EchoService;
server = new grpc.Server();
server.addService(Client.service, {
echo: function(call, callback) {
@ -413,9 +409,7 @@ describe('Echo metadata', function() {
var server;
var metadata;
before(function() {
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
var test_service = test_proto.lookup('TestService');
var Client = grpc.loadObject(test_service);
var Client = grpc.load(__dirname + '/test_service.proto').TestService;
server = new grpc.Server();
server.addService(Client.service, {
unary: function(call, cb) {
@ -514,8 +508,7 @@ describe('Client malformed response handling', function() {
var client;
var badArg = new Buffer([0xFF]);
before(function() {
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
var test_service = test_proto.lookup('TestService');
var Client = grpc.load(__dirname + '/test_service.proto').TestService;
var malformed_test_service = {
unary: {
path: '/TestService/Unary',
@ -572,7 +565,6 @@ describe('Client malformed response handling', function() {
}
});
var port = server.bind('localhost:0', server_insecure_creds);
var Client = grpc.loadObject(test_service);
client = new Client('localhost:' + port, grpc.credentials.createInsecure());
server.start();
});
@ -621,8 +613,7 @@ describe('Server serialization failure handling', function() {
var client;
var server;
before(function() {
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
var test_service = test_proto.lookup('TestService');
var Client = grpc.load(__dirname + '/test_service.proto').TestService;
var malformed_test_service = {
unary: {
path: '/TestService/Unary',
@ -679,7 +670,6 @@ describe('Server serialization failure handling', function() {
}
});
var port = server.bind('localhost:0', server_insecure_creds);
var Client = grpc.loadObject(test_service);
client = new Client('localhost:' + port, grpc.credentials.createInsecure());
server.start();
});
@ -727,9 +717,7 @@ describe('Other conditions', function() {
var server;
var port;
before(function() {
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
var test_service = test_proto.lookup('TestService');
Client = grpc.loadObject(test_service);
Client = grpc.load(__dirname + '/test_service.proto').TestService;
server = new grpc.Server();
var trailer_metadata = new grpc.Metadata();
trailer_metadata.add('trailer-present', 'yes');
@ -1084,10 +1072,8 @@ describe('Call propagation', function() {
var client;
var server;
before(function() {
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
var test_service = test_proto.lookup('TestService');
Client = grpc.load(__dirname + '/test_service.proto').TestService;
server = new grpc.Server();
Client = grpc.loadObject(test_service);
server.addService(Client.service, {
unary: function(call) {},
clientStream: function(stream) {},
@ -1336,9 +1322,7 @@ describe('Client reconnect', function() {
var client;
var port;
beforeEach(function() {
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto');
var echo_service = test_proto.lookup('EchoService');
Client = grpc.loadObject(echo_service);
Client = grpc.load(__dirname + '/echo_service.proto').EchoService;
server = new grpc.Server();
server.addService(Client.service, {
echo: function(call, callback) {

View File

@ -10,10 +10,10 @@ const gulp = help(_gulp);
const testDir = __dirname;
const apiTestDir = path.resolve(testDir, 'api');
gulp.task('internal.test.link', 'Link local copies of grpc packages', (cb) => {
return exec(`npm link ${testDir}/../packages/grpc-native-core`, cb);
gulp.task('internal.test.link.add', 'Link local copies of grpc packages', (cb) => {
return exec(`npm link grpc`, cb);
});
gulp.task('internal.test.test', 'Run API-level tests', ['internal.test.link'], () => {
gulp.task('internal.test.test', 'Run API-level tests', ['internal.test.link.add'], () => {
return gulp.src(`${apiTestDir}/*.js`).pipe(mocha());
});