change html linter, export as test helper
[squeep-html-template-helper] / test / lib / template-helper.js
index 58985ccd962683f175f29a879a189d708b913335..968a85f75c2f9e9651252099fefbc5eb96dc026d 100644 (file)
@@ -3,14 +3,10 @@
 
 const assert = require('assert');
 const th = require('../../lib/template-helper');
-const lint = require('html-minifier-lint').lint; // eslint-disable-line node/no-unpublished-require
 const stubLogger = require('../stub-logger');
+const LintHtml = require('../lint-html');
 
-function lintHtml(html) {
-  const result = lint(html);
-  stubLogger.debug('validHtml', '', { result, html });
-  assert(!result);
-}
+const lintHtml = new LintHtml(stubLogger);
 
 describe('Template Helper', function () {
   let ctx, options, pagePathLevel;
@@ -18,7 +14,9 @@ describe('Template Helper', function () {
   beforeEach(function () {
     pagePathLevel = 2;
     ctx = {};
-    options = {};
+    options = {
+      pageTitle: 'Test Page',
+    };
   });
 
   describe('initContext', function () {
@@ -266,43 +264,43 @@ describe('Template Helper', function () {
     beforeEach(function () {
       main = [];
     });
-    it('covers', function () {
+    it('covers', async function () {
       const result = th.htmlPage(pagePathLevel, ctx, options, main);
-      lintHtml(result);
+      await lintHtml.lint(result);
       assert(result);
     });
-    it('covers defaults', function () {
+    it('covers defaults', async function () {
       const result = th.htmlPage(pagePathLevel, ctx, options, main);
-      lintHtml(result);
+      await lintHtml.lint(result);
       assert(result);
     });
-    it('covers user', function () {
+    it('covers user', async function () {
       ctx.session = {
         authenticatedProfile: 'https://user.example.com/',
       };
       const result = th.htmlPage(pagePathLevel, ctx, options, main);
-      lintHtml(result);
+      await lintHtml.lint(result);
       assert(result);
     });
-    it('covers user at root path', function () {
+    it('covers user at root path', async function () {
       ctx.session = {
         authenticatedIdentifier: 'user',
       };
       pagePathLevel = 0;
       const result = th.htmlPage(pagePathLevel, ctx, options, main);
-      lintHtml(result);
+      await lintHtml.lint(result);
       assert(result);
     });
-    it('covers logout redirect', function () {
+    it('covers logout redirect', async function () {
       ctx.session = {
         authenticatedIdentifier: 'user',
       };
       ctx.url = 'https://app.example.com/this_page';
       const result = th.htmlPage(pagePathLevel, ctx, options, main);
-      lintHtml(result);
+      await lintHtml.lint(result);
       assert(result);
     });
-    it('covers existing navLinks', function () {
+    it('covers existing navLinks', async function () {
       ctx.session = {
         authenticatedIdentifier: 'user',
       };
@@ -311,7 +309,7 @@ describe('Template Helper', function () {
         href: 'link',
       }];
       const result = th.htmlPage(pagePathLevel, ctx, options);
-      lintHtml(result);
+      await lintHtml.lint(result);
       assert(result);
     });
   }); // htmlPage