Skip to content

Commit 1e9c25d

Browse files
author
Mykhailo Miroshnikov
committed
MAGETWO-31592: Javascript Unit Test Framework Update
- Change jasmine task configuration - Add shared requirejs config file - Add adminhtml and frontend area's requirejs config files in both integration and unit testsuites - Add shim.js to compensate lack of Function.prototype.bind in PhantomJS environment - Various small code improvements
1 parent 27035d1 commit 1e9c25d

File tree

12 files changed

+93
-67
lines changed

12 files changed

+93
-67
lines changed

Gruntfile.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ module.exports = function (grunt) {
99

1010
// Required plugins
1111
// _____________________________________________
12-
var specRunner = require('./dev/tests/js/framework/spec_runner');
13-
specRunner.init(grunt);
12+
var specRunner = require('./dev/tests/js/framework/spec_runner')(grunt);
1413

1514
require('./dev/tools/grunt/tasks/mage-minify')(grunt);
1615

@@ -489,10 +488,10 @@ module.exports = function (grunt) {
489488
template: require('grunt-template-jasmine-requirejs'),
490489
ignoreEmpty: true
491490
},
492-
'backend-unit': specRunner.build('unit', 'adminhtml', 8000),
493-
'backend-integration': specRunner.build('integration', 'adminhtml', 8000),
494-
'frontend-unit': specRunner.build('unit', 'frontend', 3000),
495-
'frontend-integration': specRunner.build('integration', 'frontend', 3000)
491+
'backend-unit': specRunner.configure('unit', 'adminhtml', 8000),
492+
'backend-integration': specRunner.configure('integration', 'adminhtml', 8000),
493+
'frontend-unit': specRunner.configure('unit', 'frontend', 3000),
494+
'frontend-integration': specRunner.configure('integration', 'frontend', 3000)
496495
}
497496
});
498497

dev/tests/js/framework/spec_runner.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,33 @@
22
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
33
*/
44

5-
/* global __dirname: true */
6-
75
/**
8-
* Initializes 'specRunner' grunt task.
6+
* Creates jasmine configuration object
97
*
10-
* @param {Object} grunt
8+
* @param {String} type - type of tests
9+
* @param {String} dir - area dir
10+
* @param {Number} port - port to run on
11+
* @return {Object}
1112
*/
12-
module.exports.init = function (grunt) {
13+
function buildConfig(type, dir, port) {
14+
'use strict';
15+
16+
return {
17+
src: '<%= path.spec %>/shim.js',
18+
options: {
19+
host: 'http://localhost:' + port,
20+
specs: '<%= path.spec %>/' + type + '/**/' + dir + '/**/*Spec.js',
21+
templateOptions: {
22+
requireConfigFile: [
23+
'<%= path.spec %>/require.config.js',
24+
'<%= path.spec %>/' + type + '/config/' + dir + '.js'
25+
]
26+
}
27+
}
28+
};
29+
}
30+
31+
module.exports = function (grunt) {
1332
'use strict';
1433

1534
var connect = require('connect'),
@@ -167,27 +186,6 @@ module.exports.init = function (grunt) {
167186
function canModify(url) {
168187
return url.match(/^\/(\.grunt)|(dev\/tests)|(dev\\tests)|(_SpecRunner\.html)/) === null;
169188
}
170-
};
171189

172-
/**
173-
* Creates jasmine configuration object
174-
*
175-
* @param {String} type - type of tests
176-
* @param {String} dir - area dir
177-
* @param {Number} port - port to run on
178-
* @return {Object}
179-
*/
180-
module.exports.build = function (type, dir, port) {
181-
'use strict';
182-
183-
return {
184-
src: '<%= path.spec %>/env.js',
185-
options: {
186-
host: 'http://localhost:' + port,
187-
specs: '<%= path.spec %>/' + type + '/**/' + dir + '/**/*Spec.js',
188-
templateOptions: {
189-
requireConfigFile: '<%= path.spec %>/' + type + '/config.js'
190-
}
191-
}
192-
};
190+
return { configure: buildConfig };
193191
};

dev/tests/js/spec/integration/Magento/PageCache/frontend/js/pageCacheSpec.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,6 @@ define([
1616
], function ($) {
1717
'use strict';
1818

19-
if (!Function.prototype.bind) {
20-
/**
21-
* @param {Object} bind
22-
* @returns {Function}
23-
*/
24-
Function.prototype.bind = function (bind) {
25-
var self = this;
26-
27-
/**
28-
* @returns {Function}
29-
*/
30-
return function () {
31-
var args = Array.prototype.slice.call(arguments);
32-
33-
return self.apply(bind || null, args);
34-
};
35-
};
36-
}
37-
3819
describe('Testing html-comments-parser $.fn.comments behavior', function () {
3920
var element,
4021
iframe,

dev/tests/js/spec/integration/Magento/Ui/adminhtml/datepickerSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ define([
1919

2020
$(document.body).append(element);
2121

22-
ko.applyBindingsToNode(element, { datepicker: observable });
22+
ko.applyBindingsToNode(element[0], { datepicker: observable });
2323
});
2424

2525
afterEach(function () {
26-
$(element).remove();
26+
element.remove();
2727
});
2828

2929
it('writes picked date\'s value to assigned observable', function () {
@@ -33,7 +33,7 @@ define([
3333
dateFormat,
3434
result;
3535

36-
dateFormat = $(element).datepicker('option', 'dateFormat');
36+
dateFormat = element.datepicker('option', 'dateFormat');
3737
todayDate = moment().format(dateFormat);
3838

3939
openBtn = $('img.ui-datepicker-trigger');

dev/tests/js/spec/integration/config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
require.config({
7+
paths: {
8+
'jquery/ui': 'jquery/jquery-ui-1.9.2'
9+
}
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
require.config({
7+
paths: {
8+
'jquery/ui': 'jquery/jquery-ui'
9+
}
10+
})

dev/tests/js/spec/require.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
require.config({
7+
paths: {
8+
'ko': 'ko/ko',
9+
'domReady': 'requirejs/domReady'
10+
},
11+
shim: {
12+
'jquery/ui': ['jquery']
13+
}
14+
});

dev/tests/js/spec/shim.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
Function.prototype.bind=(function(){}).bind||function(b){if(typeof this!=="function"){throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");}function c(){}var a=[].slice,f=a.call(arguments,1),e=this,d=function(){return e.apply(this instanceof c?this:b||window,f.concat(a.call(arguments)));};c.prototype=this.prototype;d.prototype=new c();return d;};

dev/tests/js/spec/unit/config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)