提交 2bbc85c6 编写于 作者: P Piotr Bryk

Merge pull request #33 from kubernetes/fix-unit-and-integration-tests

Fix unit tests and prevent protractor from hanging
...@@ -24,6 +24,12 @@ import path from 'path'; ...@@ -24,6 +24,12 @@ import path from 'path';
import conf from './conf'; import conf from './conf';
/**
* Browser sync instance that serves the application.
*/
export const browserSyncInstance = browserSync.create();
/** /**
* Currently running backend process object. Null if the backend is not running. * Currently running backend process object. Null if the backend is not running.
* *
...@@ -39,11 +45,11 @@ let runningBackendProcess = null; ...@@ -39,11 +45,11 @@ let runningBackendProcess = null;
*/ */
function browserSyncInit(baseDir) { function browserSyncInit(baseDir) {
// Enable custom support for Angular apps, e.g., history management. // Enable custom support for Angular apps, e.g., history management.
browserSync.use(browserSyncSpa({ browserSyncInstance.use(browserSyncSpa({
selector: '[ng-app]', selector: '[ng-app]',
})); }));
browserSync.instance = browserSync.init({ browserSyncInstance.init({
// TODO(bryk): Add proxy to the backend here. // TODO(bryk): Add proxy to the backend here.
startPath: '/', startPath: '/',
server: { server: {
...@@ -57,14 +63,27 @@ function browserSyncInit(baseDir) { ...@@ -57,14 +63,27 @@ function browserSyncInit(baseDir) {
/** /**
* Serves the application in development mode. * Serves the application in development mode.
*/ */
gulp.task('serve', ['spawn-backend', 'watch'], function () { function serveDevelopmentMode() {
browserSyncInit([ browserSyncInit([
conf.paths.serve, conf.paths.serve,
conf.paths.frontendSrc, // For angular templates to work. conf.paths.frontendSrc, // For angular templates to work.
conf.paths.app, // For assets to work. conf.paths.app, // For assets to work.
conf.paths.base, // For bower dependencies to work. conf.paths.base, // For bower dependencies to work.
]); ]);
}); }
/**
* Serves the application in development mode. Watches for changes in the source files to rebuild
* development artifacts.
*/
gulp.task('serve:watch', ['watch'], serveDevelopmentMode);
/**
* Serves the application in development mode.
*/
gulp.task('serve', ['index'], serveDevelopmentMode);
/** /**
...@@ -136,3 +155,4 @@ gulp.task('watch', ['index'], function () { ...@@ -136,3 +155,4 @@ gulp.task('watch', ['index'], function () {
gulp.watch(path.join(conf.paths.frontendSrc, '**/*.js'), ['scripts']); gulp.watch(path.join(conf.paths.frontendSrc, '**/*.js'), ['scripts']);
gulp.watch(path.join(conf.paths.backendSrc, '**/*.go'), ['spawn-backend']); gulp.watch(path.join(conf.paths.backendSrc, '**/*.go'), ['spawn-backend']);
}); });
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
/** /**
* @fileoverview Gulp tasks for processing stylesheets. * @fileoverview Gulp tasks for processing stylesheets.
*/ */
import browserSync from 'browser-sync';
import gulp from 'gulp'; import gulp from 'gulp';
import gulpAutoprefixer from 'gulp-autoprefixer'; import gulpAutoprefixer from 'gulp-autoprefixer';
import gulpMinifyCss from 'gulp-minify-css'; import gulpMinifyCss from 'gulp-minify-css';
...@@ -24,6 +23,7 @@ import gulpSass from 'gulp-sass'; ...@@ -24,6 +23,7 @@ import gulpSass from 'gulp-sass';
import path from 'path'; import path from 'path';
import gulpConcat from 'gulp-concat'; import gulpConcat from 'gulp-concat';
import {browserSyncInstance} from './serve';
import conf from './conf'; import conf from './conf';
...@@ -42,7 +42,7 @@ gulp.task('styles', function () { ...@@ -42,7 +42,7 @@ gulp.task('styles', function () {
.pipe(gulpSourcemaps.write(".")) .pipe(gulpSourcemaps.write("."))
.pipe(gulp.dest(conf.paths.serve)) .pipe(gulp.dest(conf.paths.serve))
// If BrowserSync is running, inform it that styles have changed. // If BrowserSync is running, inform it that styles have changed.
.pipe(browserSync.stream()); .pipe(browserSyncInstance.stream());
}); });
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
/** /**
* @fileoverview Gulp tasks for unit and integration tests. * @fileoverview Gulp tasks for unit and integration tests.
*/ */
import browserSync from 'browser-sync';
import gulp from 'gulp'; import gulp from 'gulp';
import gulpProtractor from 'gulp-protractor'; import gulpProtractor from 'gulp-protractor';
import karma from 'karma'; import karma from 'karma';
import path from 'path'; import path from 'path';
import {browserSyncInstance} from './serve';
import conf from './conf'; import conf from './conf';
...@@ -51,11 +51,17 @@ function runProtractorTests(doneFn) { ...@@ -51,11 +51,17 @@ function runProtractorTests(doneFn) {
configFile: conf.paths.protractorConf, configFile: conf.paths.protractorConf,
})) }))
.on('error', function (err) { .on('error', function (err) {
// Close browser sync server to prevent the process from hanging.
browserSyncInstance.exit();
// Kill backend server, if running.
gulp.start('kill-backend');
doneFn(err); doneFn(err);
}) })
.on('end', function () { .on('end', function () {
// Close browser sync server. // Close browser sync server to prevent the process from hanging.
browserSync.exit(); browserSyncInstance.exit();
// Kill backend server, if running.
gulp.start('kill-backend');
doneFn(); doneFn();
}); });
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
"env": { "env": {
"jasmine": true, "jasmine": true,
}, },
// Define missing global Angular testing environment variables.
"globals": { "globals": {
// Define missing global Angular variables.
"inject": true, "inject": true,
"module": true, "module": true,
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册