Skip to content
Snippets Groups Projects
Commit 06cfe3cf authored by Mykhailo Miroshnikov's avatar Mykhailo Miroshnikov
Browse files

MAGETWO-31592: Javascript Unit Test Framework Update

 - Move spec config builder to spec_runner module
 - Separate test suites into integration and unit
parent ebdd78ed
No related merge requests found
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
module.exports = function (grunt) { module.exports = function (grunt) {
'use strict'; 'use strict';
require('./spec_runner')(grunt); var specRunner = require('./spec_runner');
specRunner.init(grunt);
// Time how long tasks take. Can help when optimizing build times // Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt); require('time-grunt')(grunt);
...@@ -148,34 +149,13 @@ module.exports = function (grunt) { ...@@ -148,34 +149,13 @@ module.exports = function (grunt) {
template: require('grunt-template-jasmine-requirejs'), template: require('grunt-template-jasmine-requirejs'),
ignoreEmpty: true ignoreEmpty: true
}, },
'backend-unit-testsuite': specConfigFor('unit', 'adminhtml', 8000), 'backend-unit-testsuite': specRunner.build('unit', 'adminhtml', 8000),
'backend-integration-testsuite': specConfigFor('integration', 'adminhtml', 8000), 'backend-integration-testsuite': specRunner.build('integration', 'adminhtml', 8000),
'frontend-unit-testsuite': specConfigFor('unit', 'frontend', 3000), 'frontend-unit-testsuite': specRunner.build('unit', 'frontend', 3000),
'frontend-integration-testsuite': specConfigFor('integration', 'frontend', 3000) 'frontend-integration-testsuite': specRunner.build('integration', 'frontend', 3000)
} }
}); });
function specConfigFor(type, dir, port) {
return {
src: '<%= config.path.spec %>/env.js',
options: {
host: 'http://localhost:' + port,
specs: specPathFor(type, dir, 'Spec'),
helpers: specPathFor(type, dir, 'Helper'),
templateOptions: {
requireConfigFile: [
'lib/web/app-config.js',
'<%= config.path.spec %>/' + type + '/config.js/'
]
}
}
}
}
function specPathFor(type, dir, suffix) {
return '<%= config.path.spec %>/' + type + '/**/' + dir + '/**/*' + suffix + '.js';
}
// Clean var & pub folders // Clean var & pub folders
grunt.registerTask('cleanup', [ grunt.registerTask('cleanup', [
'clean:var', 'clean:var',
...@@ -209,19 +189,15 @@ module.exports = function (grunt) { ...@@ -209,19 +189,15 @@ module.exports = function (grunt) {
'specRunner:frontend' 'specRunner:frontend'
]); ]);
grunt.registerTask('testsuite-unit', [ grunt.registerTask('spec-unit', [
'spec-runners',
'jasmine:backend-unit-testsuite', 'jasmine:backend-unit-testsuite',
'jasmine:frontend-unit-testsuite' 'jasmine:frontend-unit-testsuite'
]); ]);
grunt.registerTask('testsuite-integration', [ grunt.registerTask('spec-integration', [
'spec-runners',
'jasmine:backend-integration-testsuite', 'jasmine:backend-integration-testsuite',
'jasmine:frontend-integration-testsuite' 'jasmine:frontend-integration-testsuite'
]); ]);
grunt.registerTask('spec', [
'spec-runners',
'testsuite-unit',
'testsuite-integration'
]);
}; };
...@@ -4,7 +4,12 @@ ...@@ -4,7 +4,12 @@
/* global __dirname: true */ /* global __dirname: true */
module.exports = function (grunt) { /**
* Initializes 'specRunner' grunt task.
*
* @param {Object} grunt
*/
module.exports.init = function (grunt) {
'use strict'; 'use strict';
var connect = require('connect'), var connect = require('connect'),
...@@ -49,9 +54,9 @@ module.exports = function (grunt) { ...@@ -49,9 +54,9 @@ module.exports = function (grunt) {
middleware: null middleware: null
}); });
area = options.areaDir; area = options.areaDir;
share = options.shareDir; share = options.shareDir;
theme = options.theme; theme = options.theme;
if (options.enableLogs) { if (options.enableLogs) {
app.use(logger('dev')); app.use(logger('dev'));
...@@ -155,3 +160,29 @@ module.exports = function (grunt) { ...@@ -155,3 +160,29 @@ module.exports = function (grunt) {
app.listen(options.port); app.listen(options.port);
}); });
}; };
/**
* Creates jasmine configuration object
*
* @param {String} type - type of tests
* @param {String} dir - area dir
* @param {Number} port - port to run on
* @return {Object}
*/
module.exports.build = function (type, dir, port) {
'use strict';
return {
src: '<%= config.path.spec %>/env.js',
options: {
host: 'http://localhost:' + port,
specs: '<%= config.path.spec %>/' + type + '/**/' + dir + '/**/*Spec.js',
templateOptions: {
requireConfigFile: [
'lib/web/app-config.js',
'<%= config.path.spec %>/' + type + '/config.js/'
]
}
}
};
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment