Commit 232ead7ed899ecc48ece0c34989c6524042fbe23
1 parent
d6dcf19b
Exists in
master
and in
1 other branch
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 | 13 | id: 1, |
14 | 14 | login: "user" |
15 | 15 | }; |
16 | - | |
16 | + | |
17 | 17 | beforeEach(angular.mock.module("templates")); |
18 | - | |
18 | + | |
19 | 19 | // beforeEach(inject((_$rootScope_: ng.IRootScopeService) => { |
20 | 20 | // $rootScope = _$rootScope_; |
21 | 21 | // })); |
22 | 22 | |
23 | 23 | it('should get the loggedIn user', (done: Function) => { |
24 | - | |
25 | - | |
24 | + | |
26 | 25 | let scope = jasmine.createSpyObj("scope", ["$on"]); |
27 | - | |
26 | + | |
28 | 27 | let providers = [ |
29 | - | |
30 | - | |
28 | + | |
29 | + | |
31 | 30 | new Provider('moment', { useValue: {} }), |
32 | 31 | new Provider('$modal', { useValue: {} }), |
33 | 32 | new Provider('AuthService', { useValue: {} }), |
34 | 33 | new Provider('Session', { useValue: { |
35 | - getCurrentUser: () => { return user} | |
34 | + currentUser: () => { return user; } | |
36 | 35 | } }), |
37 | 36 | new Provider('$scope', { useValue: scope }), |
38 | 37 | new Provider('$state', { useValue: {} }), |
39 | 38 | new Provider('AUTH_EVENTS', { useValue: {AUTH_EVENTS} }) |
40 | 39 | ]; |
41 | - | |
42 | - | |
43 | - | |
40 | + | |
41 | + | |
44 | 42 | quickCreateComponent({ |
45 | 43 | providers: providers, |
46 | 44 | template: "<acme-navbar></acme-navbar>", |
... | ... | @@ -50,7 +48,7 @@ describe("Navbar Component", () => { |
50 | 48 | expect(navbarInstance).toBeDefined(); |
51 | 49 | expect(navbarInstance["currentUser"]).toEqual(user) |
52 | 50 | done(); |
53 | - }) | |
51 | + }); | |
54 | 52 | }); |
55 | 53 | |
56 | 54 | }); |
57 | 55 | \ No newline at end of file | ... | ... |
src/app/components/navbar/navbar.ts
... | ... | @@ -26,7 +26,7 @@ export class Navbar { |
26 | 26 | private AUTH_EVENTS: IAuthEvents |
27 | 27 | ) { |
28 | 28 | |
29 | - this.currentUser = session.getCurrentUser(); | |
29 | + this.currentUser = session.currentUser(); | |
30 | 30 | |
31 | 31 | $scope.$on(AUTH_EVENTS.loginSuccess, function() { |
32 | 32 | if (this.modalInstance) { |
... | ... | @@ -38,7 +38,7 @@ export class Navbar { |
38 | 38 | }); |
39 | 39 | |
40 | 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 | 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 | 74 | var testProcess = null; |
72 | 75 | var child_process = require("child_process"); |
73 | 76 | var count = 0; |
74 | 77 | var stdinPatched = false; |
78 | + | |
79 | + | |
75 | 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 | 114 | module.exports = webpackConfig; | ... | ... |