diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000000..8c58c8efc9 --- /dev/null +++ b/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "app/bower_components" +} \ No newline at end of file diff --git a/.jshintrc b/.jshintrc index da4080429a..6f00218e37 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,6 +1,13 @@ { "globalstrict": true, "globals": { - "angular": false + "angular": false, + "describe": false, + "it": false, + "expect": false, + "beforeEach": false, + "afterEach": false, + "module": false, + "inject": false } } \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a368e661a0..cce5c682a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - 0.10 + - "0.10" before_script: - export DISPLAY=:99.0 @@ -10,5 +10,5 @@ before_script: - sleep 1 # give server time to start script: - - node_modules/.bin/karma start test/karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox - - node_modules/.bin/protractor test/protractor-conf.js --browser=firefox + - node_modules/.bin/karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox + - node_modules/.bin/protractor e2e-tests/protractor.conf.js --browser=firefox diff --git a/README.md b/README.md index 73475bd9ef..e7aece1083 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ The seed app doesn't do much, just shows how to wire two controllers and views t To get you started you can simply clone the angular-seed repository and install the dependencies: +### Prerequisites + +You need git to clone the angular-seed repository. You can get git from +[http://git-scm.com/](http://git-scm.com/). + +We also use a number of node.js tools to initialize and test angular-seed. You must have node.js and +its package manager (npm) installed. You can get them from [http://nodejs.org/](http://nodejs.org/). + ### Clone angular-seed Clone the angular-seed repository using [git][git]: @@ -23,6 +31,14 @@ git clone https://github.com/angular/angular-seed.git cd angular-seed ``` +If you just want to start a new project without the angular-seed commit history then you can do: + +```bash +git clone --depth=1 https://github.com/angular/angular-seed.git +``` + +The `depth=1` tells git to only pull down one commit worth of historical data. + ### Install Dependencies We have two kinds of dependencies in this project: tools and angular framework code. The tools help @@ -41,7 +57,11 @@ Behind the scenes this will also call `bower install`. You should find that you folders in your project. * `node_modules` - contains the npm packages for the tools we need -* `bower_components` - contains the angular framework files +* `app/bower_components` - contains the angular framework files + +*Note that the `bower_components` folder would normally be installed in the root folder but +angular-seed changes this location through the `.bowerrc` file. Putting it in the app folder makes +it easier to serve the files by a webserver.* ### Run the Application @@ -58,33 +78,33 @@ Now browse to the app at `http://localhost:8000/app/index.html`. ## Directory Layout - app/ --> all of the files to be used in production - css/ --> css files - app.css --> default stylesheet - img/ --> image files - index.html --> app layout file (the main html template file of the app) - index-async.html --> just like index.html, but loads js files asynchronously - js/ --> javascript files - app.js --> application - controllers.js --> application controllers - directives.js --> application directives - filters.js --> custom angular filters - services.js --> custom angular services - partials/ --> angular view partials (partial html templates) - partial1.html - partial2.html - - test/ --> test config and source files - protractor-conf.js --> config file for running e2e tests with Protractor - e2e/ --> end-to-end specs - scenarios.js - karma.conf.js --> config file for running unit tests with Karma - unit/ --> unit level specs/tests - controllersSpec.js --> specs for controllers - directivessSpec.js --> specs for directives - filtersSpec.js --> specs for filters - servicesSpec.js --> specs for services - +``` +app/ --> all of the source files for the application + app.css --> default stylesheet + components/ --> all app specific modules + version/ --> version related components + version.js --> version module declaration and basic "version" value service + version_test.js --> "version" value service tests + version-directive.js --> custom directive that returns the current app version + version-directive_test.js --> version directive tests + interpolate-filter.js --> custom interpolation filter + interpolate-filter_test.js --> interpolate filter tests + view1/ --> the view1 view template and logic + view1.html --> the partial template + view1.js --> the controller logic + view1_test.js --> tests of the controller + view2/ --> the view2 view template and logic + view2.html --> the partial template + view2.js --> the controller logic + view2_test.js --> tests of the controller + app.js --> main application module + index.html --> app layout file (the main html template file of the app) + index-async.html --> just like index.html, but loads js files asynchronously +karma.conf.js --> config file for running unit tests with Karma +e2e-tests/ --> end-to-end tests + protractor-conf.js --> Protractor config file + scenarios.js --> end-to-end scenarios to be run by Protractor +``` ## Testing @@ -96,8 +116,8 @@ The angular-seed app comes preconfigured with unit tests. These are written in [Jasmine][jasmine], which we run with the [Karma Test Runner][karma]. We provide a Karma configuration file to run them. -* the configuration is found at `test/karma.conf.js` -* the unit tests are found in `test/unit/`. +* the configuration is found at `karma.conf.js` +* the unit tests are found next to the code they are testing and are named as `..._test.js`. The easiest way to run the unit tests is to use the supplied npm script: @@ -107,7 +127,7 @@ npm test This script will start the Karma test runner to execute the unit tests. Moreover, Karma will sit and watch the source and test files for changes and then re-run the tests whenever any of them change. -This is the recommended strategy; if you unit tests are being run every time you save a file then +This is the recommended strategy; if your unit tests are being run every time you save a file then you receive instant feedback on any changes that break the expected code functionality. You can also ask Karma to do a single run of the tests and then exit. This is useful if you want to @@ -125,8 +145,8 @@ The angular-seed app comes with end-to-end tests, again written in [Jasmine][jas are run with the [Protractor][protractor] End-to-End test runner. It uses native events and has special features for Angular applications. -* the configuration is found at `test/protractor-conf.js` -* the end-to-end tests are found in `test/e2e/` +* the configuration is found at `e2e-tests/protractor-conf.js` +* the end-to-end tests are found in `e2e-tests/scenarios.js` Protractor simulates interaction with our web app and verifies that the application responds correctly. Therefore, our web server needs to be serving up the application, so that Protractor @@ -213,11 +233,11 @@ install the tool globally: sudo npm install -g http-server ``` -Then you can start your own development web server to server static files, from a folder, by +Then you can start your own development web server to serve static files from a folder by running: ``` -http-server +http-server -a localhost -p 8000 ``` Alternatively, you can choose to configure your own webserver, such as apache or nginx. Just @@ -226,12 +246,12 @@ configure your server to serve the files under the `app/` directory. ### Running the App in Production -This really depends on how complex is your app and the overall infrastructure of your system, but +This really depends on how complex your app is and the overall infrastructure of your system, but the general rule is that all you need in production are all the files under the `app/` directory. Everything else should be omitted. Angular apps are really just a bunch of static html, css and js files that just need to be hosted -somewhere, where they can be accessed by browsers. +somewhere they can be accessed by browsers. If your Angular app is talking to the backend server via xhr or other means, you need to figure out what is the best way to host the static files to comply with the same origin policy if @@ -271,7 +291,7 @@ For more information on AngularJS please check out http://angularjs.org/ [npm]: https://www.npmjs.org/ [node]: http://nodejs.org [protractor]: https://github.com/angular/protractor -[jasmine]: http://pivotal.github.com/jasmine/ +[jasmine]: http://jasmine.github.io [karma]: http://karma-runner.github.io [travis]: https://travis-ci.org/ -[http-server]: https://github.com/nodeapps/http-server \ No newline at end of file +[http-server]: https://github.com/nodeapps/http-server diff --git a/app/css/app.css b/app/app.css similarity index 100% rename from app/css/app.css rename to app/app.css diff --git a/app/app.js b/app/app.js new file mode 100644 index 0000000000..21eccdb8ea --- /dev/null +++ b/app/app.js @@ -0,0 +1,12 @@ +'use strict'; + +// Declare app level module which depends on views, and components +angular.module('myApp', [ + 'ngRoute', + 'myApp.view1', + 'myApp.view2', + 'myApp.version' +]). +config(['$routeProvider', function($routeProvider) { + $routeProvider.otherwise({redirectTo: '/view1'}); +}]); diff --git a/app/components/version/interpolate-filter.js b/app/components/version/interpolate-filter.js new file mode 100644 index 0000000000..03bb1987df --- /dev/null +++ b/app/components/version/interpolate-filter.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('myApp.version.interpolate-filter', []) + +.filter('interpolate', ['version', function(version) { + return function(text) { + return String(text).replace(/\%VERSION\%/mg, version); + }; +}]); diff --git a/test/unit/filtersSpec.js b/app/components/version/interpolate-filter_test.js similarity index 65% rename from test/unit/filtersSpec.js rename to app/components/version/interpolate-filter_test.js index 19af3293a1..ff56c529eb 100644 --- a/test/unit/filtersSpec.js +++ b/app/components/version/interpolate-filter_test.js @@ -1,17 +1,13 @@ 'use strict'; -/* jasmine specs for filters go here */ +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); -describe('filter', function() { - beforeEach(module('myApp.filters')); - - - describe('interpolate', function() { + describe('interpolate filter', function() { beforeEach(module(function($provide) { $provide.value('version', 'TEST_VER'); })); - it('should replace VERSION', inject(function(interpolateFilter) { expect(interpolateFilter('before %VERSION% after')).toEqual('before TEST_VER after'); })); diff --git a/app/components/version/version-directive.js b/app/components/version/version-directive.js new file mode 100644 index 0000000000..74088f8add --- /dev/null +++ b/app/components/version/version-directive.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('myApp.version.version-directive', []) + +.directive('appVersion', ['version', function(version) { + return function(scope, elm, attrs) { + elm.text(version); + }; +}]); diff --git a/test/unit/directivesSpec.js b/app/components/version/version-directive_test.js similarity index 68% rename from test/unit/directivesSpec.js rename to app/components/version/version-directive_test.js index 6061842969..4a59e1193a 100644 --- a/test/unit/directivesSpec.js +++ b/app/components/version/version-directive_test.js @@ -1,11 +1,9 @@ 'use strict'; -/* jasmine specs for directives go here */ +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); -describe('directives', function() { - beforeEach(module('myApp.directives')); - - describe('app-version', function() { + describe('app-version directive', function() { it('should print current version', function() { module(function($provide) { $provide.value('version', 'TEST_VER'); diff --git a/app/components/version/version.js b/app/components/version/version.js new file mode 100644 index 0000000000..cb7a10f9db --- /dev/null +++ b/app/components/version/version.js @@ -0,0 +1,8 @@ +'use strict'; + +angular.module('myApp.version', [ + 'myApp.version.interpolate-filter', + 'myApp.version.version-directive' +]) + +.value('version', '0.1'); diff --git a/app/components/version/version_test.js b/app/components/version/version_test.js new file mode 100644 index 0000000000..4ca6880dab --- /dev/null +++ b/app/components/version/version_test.js @@ -0,0 +1,11 @@ +'use strict'; + +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); + + describe('version service', function() { + it('should return current version', inject(function(version) { + expect(version).toEqual('0.1'); + })); + }); +}); diff --git a/app/css/.gitkeep b/app/css/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app/img/.gitkeep b/app/img/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app/index-async.html b/app/index-async.html index 7a30eca089..a559b7168e 100644 --- a/app/index-async.html +++ b/app/index-async.html @@ -2,11 +2,14 @@ + + + My AngularJS App - +