Skip to content

Commit 856a0e2

Browse files
committed
feature(angular): upgrade to angular 1.5 and use native .component API
- rework component pattern into native component API - add eslint - enhance build testing targets - run lint, mocha & karma by default - enhance documentation
1 parent 5c96fb5 commit 856a0e2

30 files changed

+180
-176
lines changed

.eslintrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "eslint-config-defaults",
3+
"env": {
4+
"es6": true,
5+
"browser": true,
6+
"node": true,
7+
"mocha": true,
8+
"jasmine": true
9+
},
10+
"globals": {
11+
"angular": false
12+
},
13+
"ecmaFeatures": {
14+
"modules": true
15+
}
16+
}

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
# Angular JS ES6 Module Testing Example [![Build Status](https://travis-ci.org/tomastrajan/angular-js-es6-testing-example.svg?branch=master)](https://travis-ci.org/tomastrajan/angular-js-es6-testing-example)
1+
# Angular JS 1.5 - ES6 Module Unit testing and Karma Integration testing seed [![Build Status](https://travis-ci.org/tomastrajan/angular-js-es6-testing-example.svg?branch=master)](https://travis-ci.org/tomastrajan/angular-js-es6-testing-example)
2+
3+
Great seed for enterprise projects with heavy focus on unit and integration testing.
4+
5+
This repository contains two releases:
6+
1. `1.0.0` - for Angular JS 1.4 and lower (uses [Component Pattern for Angular JS](https://medium.com/@tomastrajan/component-paradigm-cf32e94ba78b))
7+
2. `1.5.0` - for Angular JS 1.5 and abowe which supports native `.componet(name, options)` API
8+
9+
## Info
210

311
* original blog post describing [Proper testing of Angular JS 1.X applications with ES6 modules](https://medium.com/@tomastrajan/proper-testing-of-angular-js-applications-with-es6-modules-8cf31113873f)
412
* [demo project](http://tomastrajan.github.io/angular-js-es6-testing-example/) with examples of mocha unit & karma integration tests
@@ -12,7 +20,7 @@
1220

1321
1. Clone repository `git clone https://github.com/tomastrajan/angular-js-es6-testing-example.git`
1422
2. Enter project directory `cd angular-js-es6-testing-example`
15-
3. Install dependencies `npm install`
23+
3. Install dependencies `npm i` or `npm install`
1624

1725
## Scripts
1826

@@ -26,5 +34,19 @@ All scripts are run with `npm run [script]`, for example: `npm run test`.
2634
* `server_build` - serve content from `build` directory
2735
* `server_dist` - serve content from `dist` directory
2836

29-
* `test` - run all unit tests (with Mocha)
37+
* `lint` - lint code (with ESLint)
38+
* `mocha` - run all unit tests (with Mocha)
39+
* `watch` - run and watch all unit tests (with Mocha)
3040
* `karma` - run all integration tests (with Karma / Jasmine)
41+
* `test` - lint code and run all tests (with Mocha and Karma)
42+
43+
* `ci` - for Travis CI
44+
45+
# Tests
46+
47+
For more detailed info about tests check the original [blog post](https://medium.com/@tomastrajan/proper-testing-of-angular-js-applications-with-es6-modules-8cf31113873f).
48+
49+
50+
* `*.test.js` - mocha unit tests
51+
* `*.integration.test.js` - mocha integration tests (manual)
52+
* `*.spec.js` - karma integration tests (spin up Angular JS app context)

karma.conf.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module.exports = function(config) {
77
reporters: ['mocha'],
88

99
logLevel: config.LOG_INFO,
10-
autoWatch: false,
11-
singleRun: true,
10+
autoWatch: true,
11+
singleRun: false,
1212
colors: true,
1313
port: 9876,
1414

@@ -32,6 +32,9 @@ module.exports = function(config) {
3232
jQuery: 'jquery'
3333
})
3434
]
35+
},
36+
webpackMiddleware: {
37+
noInfo: true
3538
}
3639
});
3740
};

package.json

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,59 @@
99
"dist": "webpack --TARGET=DIST",
1010
"server_build": "node server.js",
1111
"server_dist": "node server.js --TARGET=DIST",
12-
"test": "mocha --compilers js:babel-register ./src/**/*.test.js",
12+
"lint": "eslint src/",
13+
"mocha": "mocha --compilers js:babel-register ./src/**/*.test.js",
14+
"watch": "mocha --compilers js:babel-register -w ./src/**/*.test.js",
1315
"karma": "karma start",
14-
"ci": "npm run test && npm run dist"
16+
"test": "npm run lint && npm run mocha && karma start --single-run",
17+
"ci": "npm run lint && npm run mocha && npm run dist"
1518
},
1619
"author": "[email protected]",
1720
"license": "ISC",
1821
"dependencies": {
19-
"angular": "^1.4.4",
20-
"angular-animate": "^1.4",
21-
"angular-highlightjs": "^0.4.3",
22-
"angular-ui-bootstrap": "^0.13.4",
23-
"angular-ui-router": "^0.2.15",
24-
"bootstrap": "^3.3.5",
25-
"highlight.js": "^8.8.0",
26-
"jquery": "^2.1.4",
27-
"lodash": "^3.10.1"
22+
"angular": "1.5",
23+
"angular-animate": "1.5",
24+
"angular-ui-bootstrap": "0.13.4",
25+
"angular-ui-router": "0.2.15",
26+
"bootstrap": "3.3.5",
27+
"jquery": "2.1.4",
28+
"lodash": "3.10.1"
2829
},
2930
"devDependencies": {
30-
"angular-mocks": "^1.4.7",
31-
"awesome-typescript-loader": "^0.11.3",
32-
"babel-core": "^6.4.0",
33-
"babel-loader": "^6.2.1",
34-
"babel-plugin-transform-runtime": "^6.4.3",
35-
"babel-preset-es2015": "^6.3.13",
36-
"babel-register": "^6.4.3",
37-
"babel-runtime": "^6.3.19",
38-
"chai": "^3.2.0",
39-
"chalk": "^1.1.0",
40-
"clean-webpack-plugin": "^0.1.3",
41-
"connect": "^3.4.0",
42-
"css-loader": "^0.15.6",
43-
"file-loader": "^0.8.4",
44-
"html-loader": "^0.3.0",
45-
"html-webpack-plugin": "^1.6.1",
46-
"jasmine-core": "^2.3.4",
47-
"karma": "^0.13.10",
48-
"karma-chrome-launcher": "^0.2.0",
49-
"karma-jasmine": "^0.3.6",
50-
"karma-mocha-reporter": "^1.1.1",
51-
"karma-webpack": "^1.7.0",
52-
"minimist": "^1.1.3",
53-
"mocha": "^2.2.5",
54-
"ngtemplate-loader": "^1.3.0",
31+
"angular-mocks": "1.5",
32+
"awesome-typescript-loader": "0.11.3",
33+
"babel-core": "6.5",
34+
"babel-loader": "6.2.1",
35+
"babel-plugin-transform-runtime": "6.4.3",
36+
"babel-preset-es2015": "6.3.13",
37+
"babel-register": "6.5",
38+
"babel-runtime": "6.5",
39+
"chai": "3.2.0",
40+
"chalk": "1.1.0",
41+
"clean-webpack-plugin": "0.1.3",
42+
"connect": "3.4.0",
43+
"css-loader": "0.15.6",
44+
"eslint": "1.10.3",
45+
"eslint-config-defaults": "8.0.2",
46+
"file-loader": "0.8.4",
47+
"html-loader": "0.3.0",
48+
"html-webpack-plugin": "1.6.1",
49+
"jasmine-core": "2.3.4",
50+
"karma": "0.13.19",
51+
"karma-chrome-launcher": "0.2.0",
52+
"karma-jasmine": "0.3.6",
53+
"karma-mocha-reporter": "1.1.1",
54+
"karma-webpack": "1.7.0",
55+
"minimist": "1.1.3",
56+
"mocha": "2.2.5",
57+
"ngtemplate-loader": "1.3.0",
5558
"open-browser-webpack-plugin": "0.0.2",
56-
"serve-static": "^1.10.0",
57-
"sinon": "^1.17.1",
58-
"style-loader": "^0.12.3",
59-
"typescript": "^1.5.3",
60-
"url-loader": "^0.5.6",
61-
"webpack": "^1.10.5",
62-
"webpack-dev-server": "^1.10.1"
59+
"serve-static": "1.10.0",
60+
"sinon": "1.17.1",
61+
"style-loader": "0.12.3",
62+
"typescript": "1.5.3",
63+
"url-loader": "0.5.6",
64+
"webpack": "1.10.5",
65+
"webpack-dev-server": "1.10.1"
6366
}
6467
}

src/app/app-component/app-component.directive.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export default class AppComponent {
22

3-
// nothing here yet ...
3+
constructor() {
4+
this.name = 'Tomas';
5+
}
46

5-
}
7+
}

src/app/app-component/app-component.tpl.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
<span class="icon-bar"></span>
99
<span class="icon-bar"></span>
1010
</button>
11-
<a class="navbar-brand" ui-sref="app.feature-a">Angular JS 1.X ES6 modules testing example</a>
11+
<a class="navbar-brand" ui-sref="app.feature-a">Angular JS 1.5 - ES6 Module Unit testing and Karma Integration testing seed</a>
1212
</div>
1313
<div id="navbar" class="collapse navbar-collapse">
1414
<ul class="nav navbar-nav">
1515
<li ui-sref-active="active"><a ui-sref="app.feature-a">Feature A</a></li>
1616
<li ui-sref-active="active"><a ui-sref="app.feature-b">Feature B</a></li>
1717
</ul>
1818
<ul class="nav navbar-nav pull-right">
19-
<li><a href="javascript:void(0)" user-info-component></a></li>
19+
<li><user-info-component name="$ctrl.name"></user-info-component></li>
2020
</ul>
2121
</div><!--/.nav-collapse -->
2222
</div>

src/app/app.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function routing($urlRouterProvider, $stateProvider) {
55
$stateProvider
66
.state('app', {
77
abstract: true,
8-
template: '<div app-component></div>'
8+
template: '<app-component></app-component>'
99
})
1010

1111
}

src/app/app.module.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import angular from 'angular';
22
import uirouter from 'angular-ui-router';
33

44
import { routing } from './app.config.js';
5-
import appComponent from './app-component/app-component.directive';
5+
6+
import AppComponent from './app-component/app-component';
7+
import template from './app-component/app-component.tpl.html';
68

79
export default angular
810
.module('main.app', [uirouter])
911
.config(routing)
10-
.directive('appComponent', appComponent)
12+
.component('appComponent', { controller: AppComponent, template })
1113
.name;

src/common/common.module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import angular from 'angular';
22

3-
import userInfoComponent from './component/user-info-component';
3+
import UserInfoComponent from './component/user-info-component';
44

55
export default angular
66
.module('main.app.common', [])
7-
.directive('userInfoComponent', userInfoComponent)
7+
.component('userInfoComponent', UserInfoComponent)
88
.name;

0 commit comments

Comments
 (0)