Permalink
Browse files

* added vows helper for test creation

  • Loading branch information...
1 parent 47030d8 commit e0c854a996a85558fa70a6ac51ecff2e5b9e9c4b Julien Polo committed Dec 2, 2010
Showing with 93 additions and 10 deletions.
  1. +16 −7 lib/assert/extension.js
  2. +4 −1 lib/lint/index.js
  3. +71 −0 lib/lint/vows.js
  4. +1 −1 package.json
  5. +1 −1 test/assert/extension_test.js
View
@@ -1,21 +1,30 @@
var assert = require('assert');
+var fs = require('fs');
var lint = require('../lint/parser');
if (! assert.validateLint) {
assert.validateLint = function (actual, message) {
- var result = lint.isValid(actual);
-
- if (!result) {
- assert.fail(result, true, message || "LINT returned validation result {actual}", "===", assert.validateLint);
+ var parser, errorCount;
+
+ parser = new lint.Parser();
+ errorCount = parser.update(actual).getReport().length;
+
+ if (errorCount > 0) {
+ assert.fail(errorCount, 0, message || "LINT validation returned {actual} error(s)", "===", assert.validateLint);
}
};
}
if (! assert.validateLintFile) {
assert.validateLintFile = function (actual, message) {
- var result = lint.isValidFileSync(actual);
- if (!result) {
- assert.fail(result, true, message || "LINT returned validation result {actual}", "===", assert.validateLintFile);
+ var parser, errorCount, data;
+
+ data = fs.readFileSync(actual);
+ parser = new lint.Parser();
+ errorCount = parser.update(data).getReport().length;
+
+ if (errorCount > 0) {
+ assert.fail(errorCount, 0, message || "LINT validation returned {actual} error(s)", "===", assert.validateLintFile);
}
};
}
View
@@ -9,7 +9,10 @@ var launcher = require('./launcher');
//Apply assert patch
require('../assert/extension');
-
+/**
+ * Exports
+ */
+exports.vows = require('./vows');
exports.Formatter = formatter.Formatter;
exports.Launcher = launcher.Launcher;
exports.Parser = parser.Parser;
View
@@ -0,0 +1,71 @@
+/**
+ * Imports
+ */
+var vows = require('vows');
+var assert = require('assert');
+var fs = require('fs');
+
+require('../assert/extension');
+
+/*******************************************************************************
+ * LINT / Vows helpers
+ *
+ * Usage:
+ * <pre>
+ * require('lint').createTest()
+ *
+ * </pre>
+ ******************************************************************************/
+/**
+ * Return a new Batch object for vows
+ *
+ * @param {Array} files
+ * @param {Object} options passed to the JSLINT parser
+ * @return {Object}
+ */
+function createBatch(files, options) {
+ options = options || {};
+ files = Array.isArray(files) ? files : [files];
+ var batch = {}, fileCount = files.length, fileModule, createSection;
+
+ //Section generator
+ createSection = function (filePath) {
+ return function (topic) {
+ assert.validateLintFile(filePath);
+ };
+ };
+
+ //Create for all files
+ while (fileCount > 0) {
+ fileCount -= 1;
+ filePath = files[fileCount];
+ filePath = fs.realpathSync(filePath);
+ batch[filePath] = createSection(filePath);
+ }
+
+ return {
+ 'JSLINT results' : batch
+ };
+}
+
+/**
+ * Create a default test Object. If files is specified then it creates a batch
+ * with files and options and add it to the test object
+ *
+ * @param {Array} files
+ * @param {Object} options
+ * @return
+ */
+function createTest(files, options) {
+ var test = vows.describe('JSLINT test');
+ if (files) {
+ test.addBatch(createBatch(files, options));
+ }
+ return test;
+}
+
+/**
+ * Exports
+ */
+exports.createBatch = createBatch;
+exports.createTest = createTest;
View
@@ -1,7 +1,7 @@
{
"name": "lint",
"description": "This package provide lint validation library + node-lint command line tool allows you to check for problems using JSLint. You can specify your own --config file to use alternate JSLint options and your own --formatter file if you want to customize the generated output.",
- "version": "0.1.8",
+ "version": "0.1.9",
"homepage": "https://github.com/as-jpolo/node-lint",
"author": "tav <tav@espians.com> (http://tav.espians.com)",
"contributors": [
@@ -40,7 +40,7 @@ var AssertExtensionTest = vows.describe('assert module').addBatch({
},
'should throw an error if file does not contains valid javascript' : function (topic) {
var fixtureFile = path.join(FIXTURE_PATH, 'invalid_test.js');
-
+
assert.doesNotThrow(function () {
fs.realpathSync(fixtureFile);
});

0 comments on commit e0c854a

Please sign in to comment.