Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 6f8676d

Browse files
Ryuno-Kizhukov
authored andcommitted
Add karma, Jasmine, deps and karma.conf.js. Fixes #1291 (#1293)
* Add karma, Jasmine, deps and karma.conf.js. Fixes #1291 * Improved service worker code * npm start script executes gulp watch task. * Written a gulp task to compile templates AOT. Get rid of loading deps in unit tests and a preprocessor. * PhantomJS package is deprecated. Use phantomjs-prebuilt instead. * Adjust `npm run test`.
1 parent 043c76b commit 6f8676d

12 files changed

+478
-2
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
.idea
33
.publish
44
*.sublime-workspace
5+
*.*~
6+
*.swp
57

68
# Node.js package manager
79
node_modules
@@ -12,4 +14,5 @@ releases
1214
webogram*.zip
1315
app/js/templates.js
1416
app/css
15-
cldr
17+
cldr
18+
coverage/

gulpfile.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var st = require('st')
88
var del = require('del')
99
var runSequence = require('run-sequence')
1010
var swPrecache = require('sw-precache')
11+
var Server = require('karma').Server
1112

1213

1314
// The generated file is being created at src
@@ -21,6 +22,7 @@ gulp.task('templates', function () {
2122
}))
2223
.pipe(gulp.dest('app/js'))
2324
})
25+
2426
gulp.task('clean-templates', function () {
2527
return del(['app/js/templates.js'])
2628
})
@@ -275,6 +277,35 @@ gulp.task('bump', ['bump-version-manifests', 'bump-version-config'], function ()
275277
gulp.start('bump-version-comments')
276278
})
277279

280+
// Single run of karma
281+
gulp.task('karma-single', function (done) {
282+
new Server({
283+
configFile: __dirname + '/karma.conf.js',
284+
singleRun: true
285+
}, done).start();
286+
});
287+
288+
// Continuous testing with karma by watching for changes
289+
gulp.task('karma-tdd', function (done) {
290+
new Server({
291+
configFile: __dirname + '/karma.conf.js',
292+
}, done).start();
293+
});
294+
295+
gulp.task('test', function (callback) {
296+
runSequence(
297+
['templates', 'karma-single'],
298+
callback
299+
)
300+
});
301+
302+
gulp.task('tdd', function (callback) {
303+
runSequence(
304+
['templates', 'karma-tdd'],
305+
callback
306+
)
307+
});
308+
278309
gulp.task('build', ['clean'], function (callback) {
279310
runSequence(
280311
['less', 'templates'],

karma.conf.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Karma configuration
2+
// Generated on Thu Dec 15 2016 21:12:39 GMT+0100 (CET)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: 'app',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['jasmine'],
14+
15+
16+
// list of files / patterns to load in the browser
17+
// Load files to access global variables
18+
files: [
19+
{pattern: 'js/lib/polyfill.js', watched: false},
20+
{pattern: 'vendor/jquery/jquery.min.js', watched: false},
21+
{pattern: 'js/lib/config.js', watched: false},
22+
{pattern: 'vendor/jquery.nanoscroller/nanoscroller.js', watched: false},
23+
{pattern: 'vendor/angular/angular.js', watched: false},
24+
{pattern: 'vendor/angular/angular-mocks.js', watched: false},
25+
{pattern: 'vendor/angular/angular-route.js', watched: false},
26+
{pattern: 'vendor/angular/angular-animate.js', watched: false},
27+
{pattern: 'vendor/angular/angular-sanitize.js', watched: false},
28+
{pattern: 'vendor/angular/angular-touch.js', watched: false},
29+
{pattern: 'vendor/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.js', watched: false},
30+
{pattern: 'vendor/angular-media-player/angular-media-player.js', watched: false},
31+
{pattern: 'vendor/jsbn/jsbn_combined.js', watched: false},
32+
{pattern: 'vendor/cryptoJS/crypto.js', watched: false},
33+
{pattern: 'vendor/rusha/rusha.js', watched: false},
34+
{pattern: 'vendor/zlib/gunzip.min.js', watched: false},
35+
{pattern: 'vendor/closure/long.js', watched: false},
36+
{pattern: 'vendor/leemon_bigint/bigint.js', watched: false},
37+
{pattern: 'vendor/libwebpjs/libwebp-0.2.0.js', watched: false},
38+
{pattern: 'vendor/angularjs-toaster/toaster.js', watched: false},
39+
{pattern: 'vendor/clipboard/clipboard.js', watched: false},
40+
{pattern: 'js/lib/utils.js', watched: false},
41+
{pattern: 'js/lib/bin_utils.js', watched: false},
42+
{pattern: 'js/lib/tl_utils.js', watched: false},
43+
{pattern: 'js/lib/ng_utils.js', watched: false},
44+
{pattern: 'js/lib/i18n.js', watched: false},
45+
{pattern: 'js/lib/mtproto.js', watched: false},
46+
{pattern: 'js/lib/mtproto_wrapper.js', watched: false},
47+
'js/templates.js', // Generated by `gulp templates`
48+
'js/services.js',
49+
'js/filters.js',
50+
'js/controllers.js',
51+
'js/directives.js',
52+
'../test/unit/*.js'
53+
],
54+
55+
56+
// list of files to exclude
57+
exclude: [
58+
'js/background.js'
59+
],
60+
61+
62+
// preprocess matching files before serving them to the browser
63+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
64+
preprocessors: {
65+
'js/*.js': ['coverage'],
66+
},
67+
68+
69+
// test results reporter to use
70+
// possible values: 'dots', 'progress'
71+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
72+
reporters: ['progress', 'coverage'],
73+
74+
75+
coverageReporter: {
76+
type: 'text',
77+
dir: 'coverage/'
78+
},
79+
80+
81+
// web server port
82+
port: 9876,
83+
84+
85+
// enable / disable colors in the output (reporters and logs)
86+
colors: true,
87+
88+
89+
// level of logging
90+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
91+
logLevel: config.LOG_INFO,
92+
93+
94+
// enable / disable watching file and executing tests whenever any file changes
95+
autoWatch: true,
96+
97+
98+
// start these browsers
99+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
100+
browsers: ['PhantomJS'],
101+
102+
103+
// Continuous Integration mode
104+
// if true, Karma captures browsers, runs the tests and exits
105+
singleRun: false,
106+
107+
// Concurrency level
108+
// how many browser should be started simultaneous
109+
concurrency: Infinity,
110+
})
111+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"show": true
2020
},
2121
"scripts": {
22-
"start": "node server.js"
22+
"start": "gulp watch",
23+
"test": "gulp test"
2324
},
2425
"repository": {
2526
"type": "git",
@@ -65,6 +66,12 @@
6566
"gulp-util": "^3.0.7",
6667
"gulp-zip": "^0.1.2",
6768
"http": "0.0.0",
69+
"jasmine-core": "^2.5.2",
70+
"karma": "^1.3.0",
71+
"karma-coverage": "^1.1.1",
72+
"karma-jasmine": "^1.1.0",
73+
"karma-phantomjs-launcher": "^1.0.2",
74+
"phantomjs-prebuilt": "^2.1.14",
6875
"run-sequence": "^1.0.2",
6976
"st": "^0.5.2",
7077
"sw-precache": "^3.2.0"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
describe('AppLangSelectController', function () {
2+
var $controller, $scope;
3+
4+
beforeEach(module('ui.bootstrap'));
5+
beforeEach(module('myApp.services'));
6+
beforeEach(module('myApp.controllers'));
7+
8+
beforeEach(function () {
9+
inject(function (_$controller_, _$rootScope_, _, Storage, ErrorService, AppRuntimeManager) {
10+
$controller = _$controller_;
11+
$scope = _$rootScope_.$new()
12+
$controller('AppLangSelectController', {
13+
$scope: $scope,
14+
_: _,
15+
Storage: Storage,
16+
ErrorService: ErrorService,
17+
AppRuntimeManager: AppRuntimeManager
18+
});
19+
});
20+
});
21+
22+
it('holds the supportedLocales', function () {
23+
expect($scope.supportedLocales).toBeDefined();
24+
});
25+
26+
it('holds langNames', function () {
27+
expect($scope.langNames).toBeDefined();
28+
});
29+
30+
it('holds the current locale', function () {
31+
expect($scope.curLocale).toBeDefined();
32+
});
33+
34+
it('has a locale form', function () {
35+
expect($scope.form).toBeDefined();
36+
expect($scope.form.locale).toBeDefined();
37+
});
38+
39+
it('allows to select a locale', function () {
40+
expect($scope.localeSelect).toBeDefined();
41+
});
42+
43+
describe('when the user switches the locale', function () {
44+
describe('and confirms the dialogue', function () {
45+
xit('reloads the app', function (done) {
46+
done();
47+
});
48+
});
49+
});
50+
});

test/unit/AppWelcomeControllerSpec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
describe('AppWelcomeController', function () {
2+
var $controller, $rootScope, $scope, $location, MtApiManager, ErrorService,
3+
ChangelogNotifyService, LayoutSwitchService;
4+
5+
beforeEach(module('myApp.controllers'));
6+
7+
beforeEach(function () {
8+
ChangelogNotifyService = {
9+
checkUpdate: function () {}
10+
};
11+
12+
LayoutSwitchService = {
13+
start: function () {}
14+
};
15+
16+
MtpApiManager = {
17+
getUserID: function () {
18+
return {
19+
then: function () {}
20+
};
21+
}
22+
};
23+
24+
module(function ($provide) {
25+
$provide.value('MtpApiManager', MtpApiManager);
26+
});
27+
28+
inject(function (_$controller_, _$rootScope_, _$location_) {
29+
$controller = _$controller_;
30+
$rootScope = _$rootScope_;
31+
$location = _$location_;
32+
33+
$scope = $rootScope.$new();
34+
$controller('AppWelcomeController', {
35+
$scope: $scope,
36+
$location: $location,
37+
MtpApiManager: MtpApiManager,
38+
ErrorService: ErrorService,
39+
ChangelogNotifyService: ChangelogNotifyService,
40+
LayoutSwitchService: LayoutSwitchService
41+
});
42+
});
43+
});
44+
45+
// https://stackoverflow.com/a/36460924
46+
it('executes a dummy spec', function (done) {
47+
expect(true).toBe(true);
48+
done();
49+
});
50+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
describe('PhonebookContactsService', function () {
2+
var PhonebookContactsService;
3+
4+
beforeEach(module('ui.bootstrap'));
5+
beforeEach(module('myApp.services'));
6+
7+
beforeEach(inject(function (_PhonebookContactsService_) {
8+
PhonebookContactsService = _PhonebookContactsService_;
9+
}));
10+
11+
describe('Public API:', function () {
12+
it('checks availability', function () {
13+
expect(PhonebookContactsService.isAvailable).toBeDefined();
14+
});
15+
16+
it('open the phonebook for import', function () {
17+
expect(PhonebookContactsService.openPhonebookImport).toBeDefined();
18+
});
19+
20+
it('get phonebook contacts', function () {
21+
expect(PhonebookContactsService.getPhonebookContacts).toBeDefined();
22+
});
23+
24+
describe('usage', function () {
25+
describe('of isAvailable()', function () {
26+
it('returns false in most cases', function (done) {
27+
expect(PhonebookContactsService.isAvailable()).toBe(false);
28+
done();
29+
});
30+
});
31+
32+
describe('of openPhonebookImport()', function () {
33+
beforeEach(function() {
34+
$modal = {
35+
open: jasmine.createSpy('open')
36+
};
37+
});
38+
39+
xit('opens a modal', function () {
40+
PhonebookContactsService.openPhonebookImport();
41+
expect($modal.open).toHaveBeenCalled();
42+
});
43+
});
44+
45+
describe('of getPhonebookContacts()', function () {
46+
xit('will get rejected in most cases', function (done) {
47+
promise = PhonebookContactsService.getPhonebookContacts();
48+
promise.finally(function () {
49+
expect(promise.isFullfilled()).toBe(true);
50+
done();
51+
});
52+
});
53+
});
54+
});
55+
});
56+
});

test/unit/chatTitleFilterSpec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
describe('chatTitle filter', function () {
2+
var $filter, _, chatTitleFilter;
3+
4+
beforeEach(module('myApp.filters'));
5+
6+
beforeEach(inject(function (_$filter_, ___) {
7+
$filter = _$filter_;
8+
_ = ___;
9+
}));
10+
11+
beforeEach(function () {
12+
chatTitleFilter = $filter('chatTitle');
13+
});
14+
15+
it('displays chat title deleted', function () {
16+
var expected = _('chat_title_deleted');
17+
var actual = chatTitleFilter(null);
18+
19+
expect(actual).toEqual(expected);
20+
});
21+
22+
it('displays the chat title', function () {
23+
var chat = {
24+
title: 'Telegraph is hot!'
25+
};
26+
var expected = chat.title;
27+
var actual = chatTitleFilter(chat);
28+
29+
expect(actual).toEqual(expected);
30+
});
31+
});

0 commit comments

Comments
 (0)