From e9bc9585fa7f545c936d474fd633bddf6e8cfe3d Mon Sep 17 00:00:00 2001 From: Wolfram Schneider Date: Wed, 21 Aug 2013 17:28:07 +0200 Subject: [PATCH] refactor out common functions to spec/mkws_utils.js --- test/spec/mkws-index-full.spec.js | 27 +++------------------------ test/spec/mkws_utils.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 test/spec/mkws_utils.js diff --git a/test/spec/mkws-index-full.spec.js b/test/spec/mkws-index-full.spec.js index 3650e98..ff90579 100644 --- a/test/spec/mkws-index-full.spec.js +++ b/test/spec/mkws-index-full.spec.js @@ -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 index 0000000..7b6eaaf --- /dev/null +++ b/test/spec/mkws_utils.js @@ -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 +}; + + + -- 1.7.10.4