Commit 232ead7ed899ecc48ece0c34989c6524042fbe23
1 parent
d6dcf19b
Exists in
master
and in
35 other branches
merge and small improvements on webpack.config.js
Showing
3 changed files
with
48 additions
and
41 deletions
Show diff stats
src/app/components/navbar/navbar.spec.ts
| @@ -13,34 +13,32 @@ describe("Navbar Component", () => { | @@ -13,34 +13,32 @@ describe("Navbar Component", () => { | ||
| 13 | id: 1, | 13 | id: 1, |
| 14 | login: "user" | 14 | login: "user" |
| 15 | }; | 15 | }; |
| 16 | - | 16 | + |
| 17 | beforeEach(angular.mock.module("templates")); | 17 | beforeEach(angular.mock.module("templates")); |
| 18 | - | 18 | + |
| 19 | // beforeEach(inject((_$rootScope_: ng.IRootScopeService) => { | 19 | // beforeEach(inject((_$rootScope_: ng.IRootScopeService) => { |
| 20 | // $rootScope = _$rootScope_; | 20 | // $rootScope = _$rootScope_; |
| 21 | // })); | 21 | // })); |
| 22 | 22 | ||
| 23 | it('should get the loggedIn user', (done: Function) => { | 23 | it('should get the loggedIn user', (done: Function) => { |
| 24 | - | ||
| 25 | - | 24 | + |
| 26 | let scope = jasmine.createSpyObj("scope", ["$on"]); | 25 | let scope = jasmine.createSpyObj("scope", ["$on"]); |
| 27 | - | 26 | + |
| 28 | let providers = [ | 27 | let providers = [ |
| 29 | - | ||
| 30 | - | 28 | + |
| 29 | + | ||
| 31 | new Provider('moment', { useValue: {} }), | 30 | new Provider('moment', { useValue: {} }), |
| 32 | new Provider('$modal', { useValue: {} }), | 31 | new Provider('$modal', { useValue: {} }), |
| 33 | new Provider('AuthService', { useValue: {} }), | 32 | new Provider('AuthService', { useValue: {} }), |
| 34 | new Provider('Session', { useValue: { | 33 | new Provider('Session', { useValue: { |
| 35 | - getCurrentUser: () => { return user} | 34 | + currentUser: () => { return user; } |
| 36 | } }), | 35 | } }), |
| 37 | new Provider('$scope', { useValue: scope }), | 36 | new Provider('$scope', { useValue: scope }), |
| 38 | new Provider('$state', { useValue: {} }), | 37 | new Provider('$state', { useValue: {} }), |
| 39 | new Provider('AUTH_EVENTS', { useValue: {AUTH_EVENTS} }) | 38 | new Provider('AUTH_EVENTS', { useValue: {AUTH_EVENTS} }) |
| 40 | ]; | 39 | ]; |
| 41 | - | ||
| 42 | - | ||
| 43 | - | 40 | + |
| 41 | + | ||
| 44 | quickCreateComponent({ | 42 | quickCreateComponent({ |
| 45 | providers: providers, | 43 | providers: providers, |
| 46 | template: "<acme-navbar></acme-navbar>", | 44 | template: "<acme-navbar></acme-navbar>", |
| @@ -50,7 +48,7 @@ describe("Navbar Component", () => { | @@ -50,7 +48,7 @@ describe("Navbar Component", () => { | ||
| 50 | expect(navbarInstance).toBeDefined(); | 48 | expect(navbarInstance).toBeDefined(); |
| 51 | expect(navbarInstance["currentUser"]).toEqual(user) | 49 | expect(navbarInstance["currentUser"]).toEqual(user) |
| 52 | done(); | 50 | done(); |
| 53 | - }) | 51 | + }); |
| 54 | }); | 52 | }); |
| 55 | 53 | ||
| 56 | }); | 54 | }); |
| 57 | \ No newline at end of file | 55 | \ No newline at end of file |
src/app/components/navbar/navbar.ts
| @@ -26,7 +26,7 @@ export class Navbar { | @@ -26,7 +26,7 @@ export class Navbar { | ||
| 26 | private AUTH_EVENTS: IAuthEvents | 26 | private AUTH_EVENTS: IAuthEvents |
| 27 | ) { | 27 | ) { |
| 28 | 28 | ||
| 29 | - this.currentUser = session.getCurrentUser(); | 29 | + this.currentUser = session.currentUser(); |
| 30 | 30 | ||
| 31 | $scope.$on(AUTH_EVENTS.loginSuccess, function() { | 31 | $scope.$on(AUTH_EVENTS.loginSuccess, function() { |
| 32 | if (this.modalInstance) { | 32 | if (this.modalInstance) { |
| @@ -38,7 +38,7 @@ export class Navbar { | @@ -38,7 +38,7 @@ export class Navbar { | ||
| 38 | }); | 38 | }); |
| 39 | 39 | ||
| 40 | $scope.$on(AUTH_EVENTS.logoutSuccess, () => { | 40 | $scope.$on(AUTH_EVENTS.logoutSuccess, () => { |
| 41 | - this.currentUser = this.session.getCurrentUser(); | 41 | + this.currentUser = this.session.currentUser(); |
| 42 | }); | 42 | }); |
| 43 | 43 | ||
| 44 | } | 44 | } |
webpack.config.js
| @@ -68,38 +68,47 @@ if (argv.production) { | @@ -68,38 +68,47 @@ if (argv.production) { | ||
| 68 | webpackConfig.module.loaders.push(uglifyLoaderConfig); | 68 | webpackConfig.module.loaders.push(uglifyLoaderConfig); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | + | ||
| 72 | +// if webpack executed with --test argument, this code bellow will add a post-compilation | ||
| 73 | +// code which will run the Tests + Coverage (npm run coverage) | ||
| 71 | var testProcess = null; | 74 | var testProcess = null; |
| 72 | var child_process = require("child_process"); | 75 | var child_process = require("child_process"); |
| 73 | var count = 0; | 76 | var count = 0; |
| 74 | var stdinPatched = false; | 77 | var stdinPatched = false; |
| 78 | + | ||
| 79 | + | ||
| 75 | if (argv.test) { | 80 | if (argv.test) { |
| 76 | - webpackConfig.plugins.push( | ||
| 77 | - new WebpackOnBuildPlugin(function (stats) { | ||
| 78 | - // webpack in watch mode call this twice for just one compilation | ||
| 79 | - if (!stdinPatched) { | ||
| 80 | - process.stdin.on('data', function (info) { | ||
| 81 | - if (info == '\n') { | ||
| 82 | - if (!testProcess) { | ||
| 83 | - testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); | ||
| 84 | - testProcess.on('exit', function () { testProcess = null }); | ||
| 85 | - } | ||
| 86 | - } | ||
| 87 | - }); | ||
| 88 | - stdinPatched = true; | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - // so, here we are checking if the process is still running before trigger another test execution | ||
| 92 | - if (testProcess == null) { | ||
| 93 | - console.log("Starting tests execution..."); | ||
| 94 | - testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); | ||
| 95 | - | ||
| 96 | - testProcess.on('exit', function () { testProcess = null }); | ||
| 97 | - } else { | ||
| 98 | - console.log("Test still running... Sorry webpack!! :)"); | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | - }) | ||
| 102 | - ); | 81 | + function spawnChildProcessTest() { |
| 82 | + if (!testProcess) { | ||
| 83 | + testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); | ||
| 84 | + testProcess.on('exit', function () { testProcess = null }); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + // configure the webPackOnBuildPlugin with our post-compilation function as argument | ||
| 88 | + var onBuildPluginConfigured = new WebpackOnBuildPlugin(function (stats) { | ||
| 89 | + | ||
| 90 | + // here we are patching the stdin to allow trigger tests when pressing 'Enter' | ||
| 91 | + // on terminal | ||
| 92 | + if (!stdinPatched) { | ||
| 93 | + process.stdin.on('data', function (info) { | ||
| 94 | + if (info == '\n') { | ||
| 95 | + spawnChildProcessTest(); | ||
| 96 | + } | ||
| 97 | + }); | ||
| 98 | + stdinPatched = true; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + // webpack in watch mode call this twice for just one compilation | ||
| 102 | + // so, here we are checking if the process is still running before trigger another test execution | ||
| 103 | + if (testProcess == null) { | ||
| 104 | + console.log("Starting tests execution..."); | ||
| 105 | + spawnChildProcessTest(); | ||
| 106 | + } else { | ||
| 107 | + console.log("Test still running... Sorry webpack!! :)"); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + }); | ||
| 111 | + webpackConfig.plugins.push(onBuildPluginConfigured); | ||
| 103 | } | 112 | } |
| 104 | 113 | ||
| 105 | module.exports = webpackConfig; | 114 | module.exports = webpackConfig; |