From 232ead7ed899ecc48ece0c34989c6524042fbe23 Mon Sep 17 00:00:00 2001 From: ABNER SILVA DE OLIVEIRA Date: Fri, 4 Mar 2016 14:59:01 -0300 Subject: [PATCH] merge and small improvements on webpack.config.js --- src/app/components/navbar/navbar.spec.ts | 22 ++++++++++------------ src/app/components/navbar/navbar.ts | 4 ++-- webpack.config.js | 63 ++++++++++++++++++++++++++++++++++++--------------------------- 3 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/app/components/navbar/navbar.spec.ts b/src/app/components/navbar/navbar.spec.ts index aa1c612..299ef8b 100644 --- a/src/app/components/navbar/navbar.spec.ts +++ b/src/app/components/navbar/navbar.spec.ts @@ -13,34 +13,32 @@ describe("Navbar Component", () => { id: 1, login: "user" }; - + beforeEach(angular.mock.module("templates")); - + // beforeEach(inject((_$rootScope_: ng.IRootScopeService) => { // $rootScope = _$rootScope_; // })); it('should get the loggedIn user', (done: Function) => { - - + let scope = jasmine.createSpyObj("scope", ["$on"]); - + let providers = [ - - + + new Provider('moment', { useValue: {} }), new Provider('$modal', { useValue: {} }), new Provider('AuthService', { useValue: {} }), new Provider('Session', { useValue: { - getCurrentUser: () => { return user} + currentUser: () => { return user; } } }), new Provider('$scope', { useValue: scope }), new Provider('$state', { useValue: {} }), new Provider('AUTH_EVENTS', { useValue: {AUTH_EVENTS} }) ]; - - - + + quickCreateComponent({ providers: providers, template: "", @@ -50,7 +48,7 @@ describe("Navbar Component", () => { expect(navbarInstance).toBeDefined(); expect(navbarInstance["currentUser"]).toEqual(user) done(); - }) + }); }); }); \ No newline at end of file diff --git a/src/app/components/navbar/navbar.ts b/src/app/components/navbar/navbar.ts index fc4eadf..ac17e48 100644 --- a/src/app/components/navbar/navbar.ts +++ b/src/app/components/navbar/navbar.ts @@ -26,7 +26,7 @@ export class Navbar { private AUTH_EVENTS: IAuthEvents ) { - this.currentUser = session.getCurrentUser(); + this.currentUser = session.currentUser(); $scope.$on(AUTH_EVENTS.loginSuccess, function() { if (this.modalInstance) { @@ -38,7 +38,7 @@ export class Navbar { }); $scope.$on(AUTH_EVENTS.logoutSuccess, () => { - this.currentUser = this.session.getCurrentUser(); + this.currentUser = this.session.currentUser(); }); } diff --git a/webpack.config.js b/webpack.config.js index c9785c9..b45ec1d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -68,38 +68,47 @@ if (argv.production) { webpackConfig.module.loaders.push(uglifyLoaderConfig); } + +// if webpack executed with --test argument, this code bellow will add a post-compilation +// code which will run the Tests + Coverage (npm run coverage) var testProcess = null; var child_process = require("child_process"); var count = 0; var stdinPatched = false; + + if (argv.test) { - webpackConfig.plugins.push( - new WebpackOnBuildPlugin(function (stats) { - // webpack in watch mode call this twice for just one compilation - if (!stdinPatched) { - process.stdin.on('data', function (info) { - if (info == '\n') { - if (!testProcess) { - testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); - testProcess.on('exit', function () { testProcess = null }); - } - } - }); - stdinPatched = true; - } - - // so, here we are checking if the process is still running before trigger another test execution - if (testProcess == null) { - console.log("Starting tests execution..."); - testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); - - testProcess.on('exit', function () { testProcess = null }); - } else { - console.log("Test still running... Sorry webpack!! :)"); - } - - }) - ); + function spawnChildProcessTest() { + if (!testProcess) { + testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); + testProcess.on('exit', function () { testProcess = null }); + } + } + // configure the webPackOnBuildPlugin with our post-compilation function as argument + var onBuildPluginConfigured = new WebpackOnBuildPlugin(function (stats) { + + // here we are patching the stdin to allow trigger tests when pressing 'Enter' + // on terminal + if (!stdinPatched) { + process.stdin.on('data', function (info) { + if (info == '\n') { + spawnChildProcessTest(); + } + }); + stdinPatched = true; + } + + // webpack in watch mode call this twice for just one compilation + // so, here we are checking if the process is still running before trigger another test execution + if (testProcess == null) { + console.log("Starting tests execution..."); + spawnChildProcessTest(); + } else { + console.log("Test still running... Sorry webpack!! :)"); + } + + }); + webpackConfig.plugins.push(onBuildPluginConfigured); } module.exports = webpackConfig; -- libgit2 0.21.2