Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions app/templates/_karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ function listFiles() {
path.join(conf.paths.tmp, '/serve/app/**/*.js'),
path.join(conf.paths.tmp, '/**/*.spec.js'),
path.join(conf.paths.tmp, '/**/*.mock.js'),
<% } else if (props.jsPreprocessor.key === 'typescript') { -%>
path.join(conf.paths.tmp, '/serve/app/index.module.js'),
path.join(conf.paths.src, '/**/*.spec.{js,ts}'),
path.join(conf.paths.src, '/**/*.mock.{js,ts}'),
<% } else { -%>
path.join(conf.paths.tmp, '/serve/app/index.module.js'),
path.join(conf.paths.src, '/**/*.spec.js'),
path.join(conf.paths.src, '/**/*.mock.js'),
<% } -%>
path.join(conf.paths.src, '/**/*.html')
]);
Expand Down Expand Up @@ -63,27 +57,8 @@ module.exports = function(config) {
whitelist: [path.join(conf.paths.tmp, '/**/!(*.html|*.spec|*.mock).js')]
<% } -%>
},

reporters: ['progress', 'coverage'],

preprocessors: {
'src/**/*.html': ['ng-html2js'],
<% if (props.jsPreprocessor.key === 'noJsPrepro') { -%>
'src/**/!(*.spec).js': ['coverage']
<% } else { -%>
'.tmp/**/!(*.spec).js': ['coverage']
<% } -%>
},

// optionally, configure the reporter
coverageReporter: {
type : 'html',
dir : 'coverage/'
},
<% } else { -%>
frameworks: ['jasmine'],

reporters: ['progress'],
<% } -%>

<% if(props.jsPreprocessor.key === 'traceur') { -%>
Expand All @@ -98,13 +73,40 @@ module.exports = function(config) {
'karma-phantomjs-launcher',
<% } if (props.jsPreprocessor.key === 'noJsPrepro' || props.jsPreprocessor.key === 'coffee') { -%>
'karma-angular-filesort',
'karma-coverage',
<% } -%>
'karma-coverage',
'karma-jasmine',
'karma-ng-html2js-preprocessor'
]
],

coverageReporter: {
type : 'html',
dir : 'coverage/'
},

reporters: ['progress', 'coverage']
};

var preprocessors = {};
var pathSrcHtml = path.join(conf.paths.src, '/**/*.html');
preprocessors[pathSrcHtml] = ['ng-html2js'];

<% if (props.jsPreprocessor.key === 'noJsPrepro') { -%>
var pathSrcJs = path.join(conf.paths.src, '/**/!(*.spec).js');

preprocessors[pathSrcJs] = ['coverage'];
<% } else if (props.jsPreprocessor.key === 'coffee') { -%>
var pathTmpJs = path.join(conf.paths.tmp, '/**/!(*.spec).js');

preprocessors[pathTmpJs] = ['coverage'];
<% } else { -%>
var pathTmpJs = path.join(conf.paths.tmp, '/serve/app/index.module.js');

preprocessors[pathTmpJs] = ['coverage'];
<% } -%>

configuration.preprocessors = preprocessors;

// This block is needed to execute Chrome on Travis
// If you ever plan to use Chrome and Travis, you can keep it
// If not, you can safely remove it
Expand Down
2 changes: 1 addition & 1 deletion app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
"karma-phantomjs-launcher": "~0.2.0",
<% } if (props.jsPreprocessor.srcExtension === 'js' || props.jsPreprocessor.srcExtension === 'coffee') { -%>
"karma-angular-filesort": "~0.1.0",
"karma-coverage": "~0.4.1",
<% } -%>
"karma-coverage": "~0.4.1",
"karma-ng-html2js-preprocessor": "~0.1.2",
"concat-stream": "~1.5.0",
"require-dir": "~0.3.0",
Expand Down
4 changes: 4 additions & 0 deletions app/templates/gulp/_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ gulp.task('scripts:watch', ['scripts'], function (callback) {
return webpackWrapper(true, false, callback);
});

<% if (props.jsPreprocessor.key === 'typescript') { -%>
gulp.task('scripts:test', ['tsd:install'], function () {
<% } else { -%>
gulp.task('scripts:test', function () {
<% } -%>
return webpackWrapper(false, true);
});

Expand Down
2 changes: 1 addition & 1 deletion app/templates/src/app/_index.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @ngInject */
export function config($logProvider: ng.ILogProvider, toastrConfig) {
export function config($logProvider: ng.ILogProvider, toastrConfig: any) {
// enable log
$logProvider.debugEnabled(true);
// set options third-party lib
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
describe 'service githubContributor', () ->

beforeEach module '<%- appName %>'

it 'should be registered', inject (githubContributor) ->
expect(githubContributor).not.toEqual null

describe 'apiHost variable', () ->
it 'should exist', inject (githubContributor) ->
expect(githubContributor.apiHost).not.toEqual null

describe 'getContributors function', () ->
it 'should exist', inject (githubContributor) ->
expect(githubContributor.getContributors).not.toEqual null

it 'should return data', inject (githubContributor, $httpBackend) ->
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond 200, [{pprt: 'value'}]
data = undefined
githubContributor.getContributors(1).then (fetchedData) ->
data = fetchedData
$httpBackend.flush()
expect(data).toEqual jasmine.any Array
expect(data.length == 1).toBeTruthy()
expect(data[0]).toEqual jasmine.any Object

it 'should define a limit per page as default value', inject (githubContributor, $httpBackend) ->
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=30').respond 200, new Array(30)
data = undefined
githubContributor.getContributors().then (fetchedData) ->
data = fetchedData
$httpBackend.flush()
expect(data).toEqual jasmine.any Array
expect(data.length == 30).toBeTruthy()

it 'should log a error', inject (githubContributor, $httpBackend, $log) ->
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond 500
githubContributor.getContributors 1
$httpBackend.flush()
expect($log.error.logs).toEqual jasmine.stringMatching 'XHR Failed for'
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
describe('service githubContributor', () => {
beforeEach(angular.mock.module('<%- appName %>'));

it('should be registered', inject(githubContributor => {
expect(githubContributor).not.toEqual(null);
}));

describe('apiHost variable', () => {
it('should exist', inject(githubContributor => {
expect(githubContributor.apiHost).not.toEqual(null);
}));
});

describe('getContributors function', () => {
it('should exist', inject(githubContributor => {
expect(githubContributor.getContributors).not.toEqual(null);
}));

it('should return data', inject((githubContributor, $httpBackend) => {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond(200, [{pprt: 'value'}]);
var data;
githubContributor.getContributors(1).then(function(fetchedData) {
data = fetchedData;
});
$httpBackend.flush();
expect(data).toEqual(jasmine.any(Array));
expect(data.length === 1).toBeTruthy();
expect(data[0]).toEqual(jasmine.any(Object));
}));

it('should define a limit per page as default value', inject((githubContributor, $httpBackend) => {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=30').respond(200, new Array(30));
var data;
githubContributor.getContributors().then(function(fetchedData) {
data = fetchedData;
});
$httpBackend.flush();
expect(data).toEqual(jasmine.any(Array));
expect(data.length === 30).toBeTruthy();
}));

it('should log a error', inject((githubContributor, $httpBackend, $log) => {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond(500);
githubContributor.getContributors(1);
$httpBackend.flush();
expect($log.error.logs).toEqual(jasmine.stringMatching('XHR Failed for'));
}));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { GithubContributor } from './githubContributor.service';

describe('service githubContributor', () => {
beforeEach(angular.mock.module('<%- appName %>'));

it('should be registered', inject((githubContributor: GithubContributor) => {
expect(githubContributor).not.toBeNull();
}));

describe('getContributors function', () => {
it('should return data', inject((githubContributor: GithubContributor, $httpBackend: ng.IHttpBackendService) => {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond(200, [{pprt: 'value'}]);
let data: any[];
githubContributor.getContributors(1).then((fetchedData: any[]) => {
data = fetchedData;
});
$httpBackend.flush();
expect(data.length === 1).toBeTruthy();
expect(data[0]).not.toBeNull();
}));

it('should define a limit per page as default value', inject((githubContributor: GithubContributor, $httpBackend: ng.IHttpBackendService) => {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=30').respond(200, new Array(30));
var data: any[];
githubContributor.getContributors().then((fetchedData: any[]) => {
data = fetchedData;
});
$httpBackend.flush();
expect(data.length === 30).toBeTruthy();
}));

it('should log a error', inject((githubContributor: GithubContributor, $httpBackend: ng.IHttpBackendService, $log: ng.ILogService) => {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond(500);
githubContributor.getContributors(1);
$httpBackend.flush();
expect($log.error.logs).toEqual(jasmine.stringMatching('XHR Failed for'));
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export class GithubContributor {
this.$http = $http;
}

getContributors(limit: number = 30) {
getContributors(limit: number = 30): ng.IPromise<any[]> {
return this.$http.get(this.apiHost + '/contributors?per_page=' + limit)
.then((response: any) => {
.then((response: any): any => {
return response.data;
})
.catch((error: any) => {
.catch((error: any): any => {
this.$log.error('XHR Failed for getContributors.\n', error.data);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
###
@todo Complete the test
This example is not perfect.
The `link` function is not tested.
(malarkey usage, addClass, $watch, $destroy)
###
describe 'directive malarkey', () ->
vm = undefined
element = element

beforeEach module '<%- appName %>'

beforeEach inject ($compile, $rootScope, githubContributor, $q) ->
spyOn(githubContributor, 'getContributors').and.callFake () ->
$q.when [{}, {}, {}, {}, {}, {}]

element = angular.element '<acme-malarkey extra-values="[\'Poney\', \'Monkey\']"></acme-malarkey>'

$compile(element) $rootScope.$new()
$rootScope.$digest()
vm = element.isolateScope().vm

it 'should be compiled', () ->
expect(element.html()).not.toEqual null

it 'should have isolate scope object with instanciate members', () ->
expect(vm).toEqual jasmine.any Object

expect(vm.contributors).toEqual jasmine.any Array
expect(vm.contributors.length).toEqual 6

it 'should log a info', inject ($log) ->
expect($log.info.logs).toEqual jasmine.stringMatching 'Activated Contributors View'
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @todo Complete the test
* This example is not perfect.
* The `link` function is not tested.
* (malarkey usage, addClass, $watch, $destroy)
*/
describe('directive malarkey', function() {
let vm;
let element;

beforeEach(angular.mock.module('<%- appName %>'));

beforeEach(inject(($compile, $rootScope, githubContributor, $q) => {
spyOn(githubContributor, 'getContributors').and.callFake(() => {
return $q.when([{}, {}, {}, {}, {}, {}]);
});

element = angular.element(`
<acme-malarkey extra-values="['Poney', 'Monkey']"></acme-malarkey>
`);

$compile(element)($rootScope.$new());
$rootScope.$digest();
vm = element.isolateScope().vm;
}));

it('should be compiled', () => {
expect(element.html()).not.toEqual(null);
});

it('should have isolate scope object with instanciate members', () => {
expect(vm).toEqual(jasmine.any(Object));

expect(vm.contributors).toEqual(jasmine.any(Array));
expect(vm.contributors.length).toEqual(6);
});

it('should log a info', inject($log => {
expect($log.info.logs).toEqual(jasmine.stringMatching('Activated Contributors View'));
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
$log = _$log_;

spyOn(githubContributor, 'getContributors').and.callFake(function() {
var deferred = $q.defer();
deferred.resolve([{}, {}, {}, {}, {}, {}]);

return deferred.promise;
return $q.when([{}, {}, {}, {}, {}, {}]);
});

el = angular.element('<acme-malarkey extra-values="[\'Poney\', \'Monkey\']"></acme-malarkey>');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { MalarkeyController } from './malarkey.directive';
import { GithubContributor } from '../githubContributor/githubContributor.service';

/**
* @todo Complete the test
* This example is not perfect.
* The `link` function is not tested.
* (malarkey usage, addClass, $watch, $destroy)
*/
describe('directive malarkey', () => {
let element: ng.IAugmentedJQuery;
let malarkeyController: MalarkeyController;

beforeEach(angular.mock.module('<%- appName %>'));

beforeEach(inject(($compile: ng.ICompileService, $rootScope: ng.IRootScopeService, githubContributor: GithubContributor, $q: ng.IQService) => {
spyOn(githubContributor, 'getContributors').and.callFake(() => {
return $q.when([{}, {}, {}, {}, {}, {}]);
});

element = angular.element(`
<acme-malarkey extra-values="['Poney', 'Monkey']"></acme-malarkey>
`);

$compile(element)($rootScope.$new());
$rootScope.$digest();
malarkeyController = (<any> element.isolateScope()).vm;
}));

it('should be compiled', () => {
expect(element.html()).not.toEqual(null);
});

it('should have isolate scope object with instanciate members', () => {
expect(malarkeyController).toEqual(jasmine.any(Object));

expect(malarkeyController.contributors.length).toEqual(6);
});

it('should log a info', inject(($log: ng.ILogService) => {
expect($log.info.logs).toEqual(jasmine.stringMatching('Activated Contributors View'));
}));
});
Loading