From fe95e5487b374e56e35e1ca2e1a9ce161f2ac7e9 Mon Sep 17 00:00:00 2001 From: Dan Schlosser Date: Sun, 17 May 2015 11:05:50 -0400 Subject: [PATCH] Configure testing for Travis-CI. --- .travis.yml | 2 +- src/replace.js | 33 +++++++++++++++++++-------------- test/ReplaceHelper.js | 4 +++- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7badbe..ec43125 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,4 @@ node_js: - "0.11" - "0.10" - "0.8" - - "0.6 \ No newline at end of file + - "0.6" \ No newline at end of file diff --git a/src/replace.js b/src/replace.js index f7dc4ab..1185240 100644 --- a/src/replace.js +++ b/src/replace.js @@ -20,19 +20,6 @@ return annotatedAction1.action.cost - annotatedAction2.action.cost; } - /** - * Parse the array of raw sentence strings into an array of arrays of words. - * - * @param {string[]} rawSentences the sentences to parse - * @returns {string[][]} sentences the - */ - function _parseSentences(rawSentences) { - if (!rawSentences || typeof rawSentences !== "object") { - throw "rawSentences must be an array of strings."; - } - return rawSentences.map(_parseSentence); - } - /** * Parse the raw sentence into an array of words. * @@ -217,6 +204,8 @@ * @param {bool} options.best - true if the sentences should be ordered to * minimize the number of changes performed * default: true + * @param {bool} options._testing - true if testing. sentences will be + * ignored */ function Replace(rawSentences, options) { var self = this; @@ -229,6 +218,7 @@ verbose: (opts.verbose !== undefined) ? opts.verbose : false, random: (opts.random !== undefined) ? opts.random : false, best: (opts.best !== undefined) ? opts.best : true, + _testing: (opts._testing !== undefined) ? opts._testing : false, }; self.wrapper = document.getElementById(self.settings.containerId); _injectStyle(self.settings.namespace, self.settings.speed / 1000, self.wrapper.offsetHeight); @@ -239,10 +229,25 @@ self.visibleClass = " ." + self.settings.namespace + "-visible"; self.wrapperSelector = "#" + self.settings.namespace; self._setupContainer(); - self._setSentences(_parseSentences(rawSentences)); + if (!self.settings._testing) { + self._setSentences(_parseSentences(rawSentences)); + } return this; } + /** + * Parse the array of raw sentence strings into an array of arrays of words. + * + * @param {string[]} rawSentences the sentences to parse + * @returns {string[][]} sentences the + */ + Replace.prototype._parseSentences = function(rawSentences) { + if (!rawSentences || typeof rawSentences !== "object") { + throw "rawSentences must be an array of strings."; + } + return rawSentences.map(_parseSentence); + }; + /** * Find the container for the sentences, empty out any HTML that might be * inside, and then give it the namespace class. It will be the root element diff --git a/test/ReplaceHelper.js b/test/ReplaceHelper.js index 8c05d69..000f0fe 100644 --- a/test/ReplaceHelper.js +++ b/test/ReplaceHelper.js @@ -8,5 +8,7 @@ function getReplaceInstance(id) { div.id = id; document.body.appendChild(div); } - return new window.Replace([]); + return new window.Replace([], { + _testing: true + }); }