From fd9d0bc291cbfca042f818d76541464c170dc130 Mon Sep 17 00:00:00 2001
From: Simon Gaeremynck
Date: Mon, 18 May 2015 17:44:11 +0100
Subject: [PATCH] Added backend tests for TidyHtml
---
tests/backend/specs/api/tidy.js | 63 +++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 tests/backend/specs/api/tidy.js
diff --git a/tests/backend/specs/api/tidy.js b/tests/backend/specs/api/tidy.js
new file mode 100644
index 000000000..47cb49f62
--- /dev/null
+++ b/tests/backend/specs/api/tidy.js
@@ -0,0 +1,63 @@
+var assert = require('assert')
+ fs = require('fs'),
+ path = require('path'),
+ TidyHtml = null,
+ Settings = null;
+
+var npm = require("../../../../src/node_modules/npm/lib/npm.js");
+
+describe('tidyHtml', function() {
+ before(function(done) {
+ npm.load({}, function(err) {
+ assert.ok(!err);
+ TidyHtml = require('../../../../src/node/utils/TidyHtml');
+ Settings = require('../../../../src/node/utils/Settings');
+ return done()
+ });
+ });
+
+ it('Tidies HTML', function(done) {
+ // If the user hasn't configured Tidy, we skip this tests as it's required for this test
+ if (!Settings.tidyHtml) {
+ this.skip();
+ }
+
+ // Try to tidy up a bad HTML file
+ var tmpDir = process.env.TEMP || "/tmp";
+ var tmpFile = path.join(tmpDir, 'tmp_' + (Math.floor(Math.random() * 1000000)) + '.html')
+ fs.writeFileSync(tmpFile, 'a paragraph
List without outer ULtrailing closing p
');
+ TidyHtml.tidy(tmpFile, function(err){
+ assert.ok(!err);
+
+ // Read the file again
+ var cleanedHtml = fs.readFileSync(tmpFile).toString();
+
+ var expectedHtml = [
+ '',
+ '',
+ '',
+ 'a paragraph
',
+ '',
+ '- List without outer UL
',
+ '- trailing closing p
',
+ '
',
+ '',
+ '