Extracts test helpers from tests.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 21 Jun 2015 09:28:46 +0000 (10:28 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 21 Jun 2015 09:28:46 +0000 (10:28 +0100)
test/selectors/advanced-test.js
test/selectors/simple-test.js
test/test-helper.js [new file with mode: 0644]

index d1f8ed9..c26463b 100644 (file)
@@ -1,28 +1,5 @@
 var vows = require('vows');
-var assert = require('assert');
-var CleanCSS = require('../../lib/clean');
-
-function optimizerContext(group, specs, options) {
-  var context = {};
-  options = options || {};
-  options.shorthandCompacting = true;
-  options.restructuring = true;
-
-  function optimized(target) {
-    return function (source) {
-      assert.equal(new CleanCSS(options).minify(source).styles, target);
-    };
-  }
-
-  for (var name in specs) {
-    context[group + ' - ' + name] = {
-      topic: specs[name][0],
-      optimized: optimized(specs[name][1])
-    };
-  }
-
-  return context;
-}
+var optimizerContext = require('../test-helper').optimizerContext;
 
 vows.describe('advanced optimizer')
   .addBatch(
index ee399fd..a601d71 100644 (file)
@@ -1,69 +1,9 @@
 var vows = require('vows');
-var assert = require('assert');
 
-var tokenize = require('../../lib/tokenizer/tokenize');
-var SimpleOptimizer = require('../../lib/selectors/simple');
-var Compatibility = require('../../lib/utils/compatibility');
-var addOptimizationMetadata = require('../../lib/selectors/optimization-metadata');
+var selectorContext = require('../test-helper').selectorContext;
+var propertyContext = require('../test-helper').propertyContext;
 
-function selectorContext(group, specs, options) {
-  var context = {};
-  options = options || {};
-  options.compatibility = new Compatibility(options.compatibility).toOptions();
-
-  function optimized(selectors) {
-    return function (source) {
-      var tokens = tokenize(source, { options: {} });
-      new SimpleOptimizer(options).optimize(tokens);
-
-      assert.deepEqual(tokens[0] ? tokens[0][1] : null, selectors);
-    };
-  }
-
-  for (var name in specs) {
-    context['selector - ' + group + ' - ' + name] = {
-      topic: specs[name][0],
-      optimized: optimized(specs[name][1])
-    };
-  }
-
-  return context;
-}
-
-function propertyContext(group, specs, options) {
-  var context = {};
-  options = options || {};
-  options.compatibility = new Compatibility(options.compatibility).toOptions();
-
-  function optimized(selectors) {
-    return function (source) {
-      var tokens = tokenize(source, { options: {} });
-      addOptimizationMetadata(tokens);
-      new SimpleOptimizer(options).optimize(tokens);
-
-      var value = tokens[0] ?
-        tokens[0][2].map(function (property) {
-          return typeof property == 'string' ?
-            property :
-            property.map(function (t) { return t[0]; });
-        }) :
-        null;
-
-      assert.deepEqual(value, selectors);
-    };
-  }
-
-  for (var name in specs) {
-    context['property - ' + group + ' - ' + name] = {
-      topic: specs[name][0],
-      optimized: optimized(specs[name][1])
-    };
-  }
-
-  return context;
-}
-
-vows.describe(SimpleOptimizer)
+vows.describe('simple optimizations')
   .addBatch(
     selectorContext('default', {
       'optimized': [
diff --git a/test/test-helper.js b/test/test-helper.js
new file mode 100644 (file)
index 0000000..0f3376b
--- /dev/null
@@ -0,0 +1,92 @@
+var assert = require('assert');
+
+var CleanCSS = require('../lib/clean');
+var tokenize = require('../lib/tokenizer/tokenize');
+var SimpleOptimizer = require('../lib/selectors/simple');
+var Compatibility = require('../lib/utils/compatibility');
+var addOptimizationMetadata = require('../lib/selectors/optimization-metadata');
+
+function optimizerContext(group, specs, options) {
+  var context = {};
+  options = options || {};
+  options.shorthandCompacting = true;
+  options.restructuring = true;
+
+  function optimized(target) {
+    return function (source) {
+      assert.equal(new CleanCSS(options).minify(source).styles, target);
+    };
+  }
+
+  for (var name in specs) {
+    context[group + ' - ' + name] = {
+      topic: specs[name][0],
+      optimized: optimized(specs[name][1])
+    };
+  }
+
+  return context;
+}
+
+function selectorContext(group, specs, options) {
+  var context = {};
+  options = options || {};
+  options.compatibility = new Compatibility(options.compatibility).toOptions();
+
+  function optimized(selectors) {
+    return function (source) {
+      var tokens = tokenize(source, { options: {} });
+      new SimpleOptimizer(options).optimize(tokens);
+
+      assert.deepEqual(tokens[0] ? tokens[0][1] : null, selectors);
+    };
+  }
+
+  for (var name in specs) {
+    context['selector - ' + group + ' - ' + name] = {
+      topic: specs[name][0],
+      optimized: optimized(specs[name][1])
+    };
+  }
+
+  return context;
+}
+
+function propertyContext(group, specs, options) {
+  var context = {};
+  options = options || {};
+  options.compatibility = new Compatibility(options.compatibility).toOptions();
+
+  function optimized(selectors) {
+    return function (source) {
+      var tokens = tokenize(source, { options: {} });
+      addOptimizationMetadata(tokens);
+      new SimpleOptimizer(options).optimize(tokens);
+
+      var value = tokens[0] ?
+        tokens[0][2].map(function (property) {
+          return typeof property == 'string' ?
+            property :
+            property.map(function (t) { return t[0]; });
+        }) :
+        null;
+
+      assert.deepEqual(value, selectors);
+    };
+  }
+
+  for (var name in specs) {
+    context['property - ' + group + ' - ' + name] = {
+      topic: specs[name][0],
+      optimized: optimized(specs[name][1])
+    };
+  }
+
+  return context;
+}
+
+module.exports = {
+  optimizerContext: optimizerContext,
+  selectorContext: selectorContext,
+  propertyContext: propertyContext
+};