From 06cfe3cf47a2694b785e5477094d1e55a1b6a8a9 Mon Sep 17 00:00:00 2001
From: Mykhailo Miroshnikov <mmiroshnikov@ebay.com>
Date: Wed, 31 Dec 2014 16:02:27 +0200
Subject: [PATCH] MAGETWO-31592: Javascript Unit Test Framework Update

 - Move spec config builder to spec_runner module
 - Separate test suites into integration and unit
---
 Gruntfile.js   | 44 ++++++++++----------------------------------
 spec_runner.js | 39 +++++++++++++++++++++++++++++++++++----
 2 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index 7355989ff90..f3e457f6377 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -5,7 +5,8 @@
 module.exports = function (grunt) {
     '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
     require('time-grunt')(grunt);
@@ -148,34 +149,13 @@ module.exports = function (grunt) {
                 template: require('grunt-template-jasmine-requirejs'),
                 ignoreEmpty: true
             },
-            'backend-unit-testsuite':           specConfigFor('unit', 'adminhtml', 8000),
-            'backend-integration-testsuite':    specConfigFor('integration', 'adminhtml', 8000),
-            'frontend-unit-testsuite':          specConfigFor('unit', 'frontend', 3000),
-            'frontend-integration-testsuite':   specConfigFor('integration', 'frontend', 3000)
+            'backend-unit-testsuite':           specRunner.build('unit', 'adminhtml', 8000),
+            'backend-integration-testsuite':    specRunner.build('integration', 'adminhtml', 8000),
+            'frontend-unit-testsuite':          specRunner.build('unit', '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
     grunt.registerTask('cleanup', [
         'clean:var',
@@ -209,19 +189,15 @@ module.exports = function (grunt) {
         'specRunner:frontend'
     ]);
 
-    grunt.registerTask('testsuite-unit', [
+    grunt.registerTask('spec-unit', [
+        'spec-runners',
         'jasmine:backend-unit-testsuite',
         'jasmine:frontend-unit-testsuite'
     ]);
 
-    grunt.registerTask('testsuite-integration', [
+    grunt.registerTask('spec-integration', [
+        'spec-runners',
         'jasmine:backend-integration-testsuite',
         'jasmine:frontend-integration-testsuite'
     ]);
-
-    grunt.registerTask('spec', [
-        'spec-runners',
-        'testsuite-unit',
-        'testsuite-integration'
-    ]);
 };
diff --git a/spec_runner.js b/spec_runner.js
index faa920a556b..95b01354ebe 100644
--- a/spec_runner.js
+++ b/spec_runner.js
@@ -4,7 +4,12 @@
 
 /* global __dirname: true */
 
-module.exports = function (grunt) {
+/**
+ * Initializes 'specRunner' grunt task.
+ *
+ * @param  {Object} grunt
+ */
+module.exports.init = function (grunt) {
     'use strict';
 
     var connect     = require('connect'),
@@ -49,9 +54,9 @@ module.exports = function (grunt) {
             middleware: null
         });
 
-        area        = options.areaDir;
-        share       = options.shareDir;
-        theme       = options.theme;
+        area    = options.areaDir;
+        share   = options.shareDir;
+        theme   = options.theme;
 
         if (options.enableLogs) {
             app.use(logger('dev'));
@@ -155,3 +160,29 @@ module.exports = function (grunt) {
         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/'
+                ]
+            }
+        }
+    };
+};
-- 
GitLab