refactor out common functions to spec/mkws_utils.js
authorWolfram Schneider <wosch@indexdata.dk>
Wed, 21 Aug 2013 15:28:07 +0000 (17:28 +0200)
committerWolfram Schneider <wosch@indexdata.dk>
Wed, 21 Aug 2013 15:28:07 +0000 (17:28 +0200)
test/spec/mkws-index-full.spec.js
test/spec/mkws_utils.js [new file with mode: 0644]

index 3650e98..ff90579 100644 (file)
@@ -6,28 +6,7 @@
 
 
 var fs = require("fs");
-
-/*
- * combine arrays, return a flat list
- * [["a","b"], ["c"], "d"] => ["a", "b", "c", "d"]
- *
- */
-function flat_list (list) {
-  var data = [];
-
-  for(var i = 0; i < list.length; i++) {
-      if (typeof list[i] == 'object') {
-        for(var j = 0; j < list[i].length; j++) {
-          data.push(list[i][j]);
-        }
-
-      } else {
-        data.push(list[i]);
-      }
-  }
-
-  return data;
-}
+var utils = require("./mkws_utils.js");
 
 /*
  * simple test with string matching of the HTML page
@@ -36,7 +15,7 @@ function flat_list (list) {
 
 function html_check (file, tags_array, ignore_doctype) {
   var html = fs.readFileSync(file, "utf-8");
-  var tags = flat_list(tags_array);
+  var tags = utils.flat_list(tags_array);
 
   describe("index-full.html string test for " + file, function() {
     it("html test", function() {
@@ -74,7 +53,7 @@ function html_check (file, tags_array, ignore_doctype) {
 
 function jsdom_check (file, tags_array, ignore_doctype) {
   var html = fs.readFileSync(file, "utf-8");
-  var tags = flat_list(tags_array);
+  var tags = utils.flat_list(tags_array);
 
   describe("index-full.html jsdom + jquery for " + file, function() {
     var window = require('jsdom').jsdom(html, null, {
diff --git a/test/spec/mkws_utils.js b/test/spec/mkws_utils.js
new file mode 100644 (file)
index 0000000..7b6eaaf
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * combine arrays, return a flat list
+ * [["a","b"], ["c"], "d"] => ["a", "b", "c", "d"]
+ *
+ */
+var flat_list = function (list) {
+  var data = [];
+
+  for(var i = 0; i < list.length; i++) {
+      if (typeof list[i] == 'object') {
+        for(var j = 0; j < list[i].length; j++) {
+          data.push(list[i][j]);
+        }
+
+      } else {
+        data.push(list[i]);
+      }
+  }
+
+  return data;
+};
+
+var tags = { 
+       required: ["mkwsSearch", "mkwsResults"],
+       optional: ["mkwsSwitch", "mkwsLang", "mkwsTargets"],
+       optional2: ["mkwsMOTD", "mkwsStat", "footer"]
+};
+
+module.exports = {
+       flat_list: flat_list,
+       tags: tags
+};
+
+
+