Generating sample test
diff --git a/xos/core/xoslib/ngXosLib/README.md b/xos/core/xoslib/ngXosLib/README.md
index f1d5018..d1f508b 100644
--- a/xos/core/xoslib/ngXosLib/README.md
+++ b/xos/core/xoslib/ngXosLib/README.md
@@ -80,6 +80,11 @@
The `npm start` command is watching your dependencies and will automatically inject it in your `index.html`.
+#### Test
+
+The generator set up a test environment with a default test.
+To run it execute: `npm test`
+
## TODO
- Use Angular $resource instead of $http
diff --git a/xos/core/xoslib/ngXosLib/generator-xos/app/index.js b/xos/core/xoslib/ngXosLib/generator-xos/app/index.js
index 182f6cd..009550a 100755
--- a/xos/core/xoslib/ngXosLib/generator-xos/app/index.js
+++ b/xos/core/xoslib/ngXosLib/generator-xos/app/index.js
@@ -72,6 +72,20 @@
{name:config.name, fileName: this._fistCharToUpper(config.name)}
);
this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
+ },
+ karma: function(){
+ this.fs.copy(
+ this.templatePath('karma.conf.js'),
+ this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
+ );
+ },
+ spec: function(){
+ const userName = user.git.name().split(' ');
+ this.fs.copyTpl(
+ this.templatePath('spec/sample.test.js'),
+ this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
+ { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
+ );
}
},
install: function(){
diff --git a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/bower.json b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/bower.json
index 101436c..7ecd065 100644
--- a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/bower.json
+++ b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/bower.json
@@ -17,6 +17,8 @@
"dependencies": {
},
"devDependencies": {
+ "jquery": "~2.1.4",
+ "angular-mocks": "~1.4.7",
"angular": "~1.4.7",
"angular-route": "~1.4.7",
"angular-cookies": "~1.4.7",
diff --git a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/karma.conf.js b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/karma.conf.js
new file mode 100644
index 0000000..83d3f63
--- /dev/null
+++ b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/karma.conf.js
@@ -0,0 +1,88 @@
+// Karma configuration
+// Generated on Tue Oct 06 2015 09:27:10 GMT+0000 (UTC)
+
+/* eslint indent: [2,2], quotes: [2, "single"]*/
+
+/*eslint-disable*/
+var wiredep = require('wiredep');
+var path = require('path');
+
+var bowerComponents = wiredep( {devDependencies: true} )[ 'js' ].map(function( file ){
+ return path.relative(process.cwd(), file);
+});
+
+module.exports = function(config) {
+/*eslint-enable*/
+ config.set({
+
+ // base path that will be used to resolve all patterns (eg. files, exclude)
+ basePath: '',
+
+
+ // frameworks to use
+ // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
+ frameworks: ['jasmine'],
+
+
+ // list of files / patterns to load in the browser
+ files: bowerComponents.concat([
+ '../../static/js/xosApi.js',
+ '../../static/js/vendor/ngXosHelpers.js',
+ 'src/js/**/*.js',
+ 'spec/**/*.mock.js',
+ 'spec/**/*.test.js',
+ 'src/**/*.html'
+ ]),
+
+
+ // list of files to exclude
+ exclude: [
+ ],
+
+
+ // preprocess matching files before serving them to the browser
+ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
+ preprocessors: {
+ 'src/js/**/*.js': ['babel'],
+ 'spec/**/*.test.js': ['babel'],
+ 'src/**/*.html': ['ng-html2js']
+ },
+
+ ngHtml2JsPreprocessor: {
+ stripPrefix: 'src/', //strip the src path from template url (http://stackoverflow.com/questions/22869668/karma-unexpected-request-when-testing-angular-directive-even-with-ng-html2js)
+ moduleName: 'templates' // define the template module name
+ },
+
+ // test results reporter to use
+ // possible values: 'dots', 'progress'
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
+ reporters: ['mocha'],
+
+
+ // web server port
+ port: 9876,
+
+
+ // enable / disable colors in the output (reporters and logs)
+ colors: true,
+
+
+ // level of logging
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
+ logLevel: config.LOG_INFO,
+
+
+ // enable / disable watching file and executing tests whenever any file changes
+ autoWatch: true,
+
+
+ // start these browsers
+ // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
+ browsers: ['PhantomJS'],
+
+
+ // Continuous Integration mode
+ // if true, Karma captures browsers, runs the tests and exits
+ singleRun: false
+ });
+};
diff --git a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/package.json b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/package.json
index dfb4088..95a95e0 100644
--- a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/package.json
+++ b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/package.json
@@ -6,7 +6,8 @@
"prestart": "npm install && bower install",
"start": "gulp serve",
"prebuild": "npm install && bower install",
- "build": "gulp"
+ "build": "gulp",
+ "test": "karma start"
},
"keywords": [
"XOS",
diff --git a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/spec/sample.test.js b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/spec/sample.test.js
new file mode 100644
index 0000000..10a74ad
--- /dev/null
+++ b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/spec/sample.test.js
@@ -0,0 +1,37 @@
+'use strict';
+
+describe('The User List', () => {
+
+ var scope, element, isolatedScope, httpBackend;
+
+ beforeEach(module('xos.<%= name %>'));
+ beforeEach(module('templates'));
+
+ beforeEach(inject(function($httpBackend, $compile, $rootScope){
+
+ httpBackend = $httpBackend;
+ // Setting up mock request
+ $httpBackend.expectGET('/xos/users/?no_hyperlinks=1').respond([
+ {
+ email: '<%= user.email %>',
+ firstname: '<%= user.firstname %>',
+ lastname: '<%= user.lastname %>'
+ }
+ ]);
+
+ scope = $rootScope.$new();
+ element = angular.element('<users-list></users-list>');
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should load 1 users', () => {
+ httpBackend.flush();
+ expect(isolatedScope.users.length).toBe(1);
+ expect(isolatedScope.users[0].email).toEqual('<%= user.email %>');
+ expect(isolatedScope.users[0].firstname).toEqual('<%= user.firstname %>');
+ expect(isolatedScope.users[0].lastname).toEqual('<%= user.lastname %>');
+ });
+
+});
\ No newline at end of file