New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

functional-docs

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

functional-docs - npm Package Compare versions

Comparing version 0.1.0 to 0.1.2

test/files/missingImageDirPrefix.html

116

index.js

@@ -14,9 +14,11 @@ var fs = require('fs'),

var srcFiles, outFiles, ext;
var srcDir, srcFiles, outFiles, ext, stopOnFail, options;
var readFiles = {};
exports.runTests = function(srcDir, options, callback) {
var stopOnFail = options.stopOnFail || false;
exports.runTests = function(src, opts, callback) {
options = opts;
stopOnFail = options.stopOnFail || false;
ext = options.ext || ".html";
srcDir = src;

@@ -31,61 +33,67 @@ console.log("Running tests on " + srcDir);

async.forEach(srcFiles, function(fileName, forEachCB) {
var file = srcDir + "/" + fileName;
if (file.match(new RegExp(ext + "$"))) {
fs.readFile(file, 'utf8', function(err, content) {
if (err) {
if (!fs.lstatSync(file).isDirectory()) {
console.error("Error starting to read file " + file);
console.error(err);
process.exit(1);
}
}
var doc = jsdom.jsdom(content);
readFiles[file] = doc;
async.parallel([
function(cb) {
preTest.checkMissingAltTag(file, doc, function(errors) {
checkForErrors(errors, stopOnFail, cb);
});
},
function(cb) {
preTest.checkBrokenExternalLink(file, doc, function(errors) {
checkForErrors(errors, stopOnFail, cb);
});
},
function(cb) {
postTest.checkMissingImage(file, doc, function(errors) {
checkForErrors(errors, stopOnFail, cb);
});
},
function(cb) {
postTest.checkBrokenLocalLink(file, doc, readFiles, function(errors) {
checkForErrors(errors, stopOnFail, cb);
});
}
], function(err, results) {
forEachCB(null);
});
});
}
}, function (err, results) {
async.forEach(srcFiles, runIndividualTest, function (err) {
console.log("Finished running tests on " + srcDir);
callback(err);
})
})
});
});
};
function checkForErrors(errors, breakOnFail, callback) {
for (var e in errors) {
console.error(errors[e].magenta);
function runIndividualTest(fileName, callback) {
var file = srcDir + "/" + fileName;
if (file.match(new RegExp(ext + "$"))) {
fs.readFile(file, 'utf8', function(err, content) {
if (err) {
if (!fs.lstatSync(file).isDirectory()) {
console.error("Error starting to read file " + file);
console.error(err);
process.exit(1);
}
}
var doc = jsdom.jsdom(content);
readFiles[file] = doc;
async.parallel([
function(cb) {
preTest.checkMissingAltTag(file, doc, options, function(errors) {
checkForErrors(errors, stopOnFail, cb);
});
},
function(cb) {
preTest.checkBrokenExternalLink(file, doc, options, function(errors) {
checkForErrors(errors, stopOnFail, cb);
});
},
function(cb) {
postTest.checkMissingImage(file, doc, options, function(errors) {
checkForErrors(errors, stopOnFail, cb);
});
},
function(cb) {
postTest.checkBrokenLocalLink(file, doc, readFiles, options, function(errors) {
checkForErrors(errors, stopOnFail, cb);
});
}
], function(err, results) {
callback(err);
});
});
}
if (breakOnFail) {
console.error("Halting due to failures".magenta);
process.exit(1);
else {
callback(null);
}
callback(null);
}
function checkForErrors(errors, stopOnFail, cb) {
while (errors.length) {
console.error(errors[errors.length - 1]);
errors.pop();
if (stopOnFail) {
console.error("Halting due to failures".magenta);
process.exit(1);
}
}
cb(null);
}
function loadFiles(dirs, callback) {

@@ -92,0 +100,0 @@ async.forEach(dirs, function(dir, cb) {

{
"name": "functional-docs",
"version": "0.1.0",
"version": "0.1.2",
"author": "Garen Torikian",

@@ -5,0 +5,0 @@ "keywords": ["documentation", "docs", "testing", "html"],

@@ -6,3 +6,3 @@ var fs = require('fs');

exports.checkMissingImage = function(filename, doc, callback) {
exports.checkMissingImage = function(filename, doc, options, callback) {
var errors = [];

@@ -20,2 +20,5 @@ var imgList = doc.getElementsByTagName("img");

try {
if (options.mapPrefix && src.charAt(0) == "/") {
src = "." + src;
}
fs.lstatSync(path.resolve(path.dirname(filename), src));

@@ -32,3 +35,3 @@ } catch (err) {

exports.checkBrokenLocalLink = function(filename, doc, readFiles, callback) {
exports.checkBrokenLocalLink = function(filename, doc, readFiles, options, callback) {
var errors = [];

@@ -35,0 +38,0 @@ var aList = doc.getElementsByTagName("a");

@@ -6,3 +6,3 @@ var util = require("util");

exports.checkMissingAltTag = function(filename, doc, callback) {
exports.checkMissingAltTag = function(filename, doc, options, callback) {
var errors = [];

@@ -24,3 +24,3 @@ var imgList = doc.getElementsByTagName("img");

exports.checkBrokenExternalLink = function(filename, doc, callback) {
exports.checkBrokenExternalLink = function(filename, doc, options, callback) {
var errors = [];

@@ -27,0 +27,0 @@ var aList = doc.getElementsByTagName("a");

@@ -28,5 +28,6 @@ # Introduction

* An array of directories, with files you want to test
* An object specifying various ways to run the tests. Though some of the properties are optional, the paramter itself is not:
* An object specifying various ways to run the tests. Though some of the properties are optional, the parameter itself is not:
* `stopOnFail` indicates if you want the testing to stop once a failure is found; defaults to `false`
* `ext` indicates the extension of the files you want to test; defaults to ".html"
* `mapPrefix`: if images start with a `/`, the test assumes it's at `./`. This is mostly for routing compatability with express.
* A callback function to execute upon completion

@@ -33,0 +34,0 @@

var funcDoc = require('../index.js');
funcDoc.runTests([ './files'], {stopOnFail: false, ext: ".html"}, function(err, results) {
funcDoc.runTests([ './files'], {stopOnFail: false, ext: ".html", mapPrefix: true}, function(err, results) {
//console.log("Nothing.");
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc