summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorAlan Pearce2017-07-03 21:39:43 +0200
committerAlan Pearce2017-07-03 21:55:41 +0200
commite7b08b1dfe3f2a2596deb6e2a72bb79805d3708f (patch)
tree027fda29fe96736d4ac641a1dfe0bfe657d3fd33 /test
parenta67e38d1a82c95db5bd24183e81b31438f60dd2c (diff)
downloadhomestead-e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f.tar.lz
homestead-e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f.tar.zst
homestead-e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f.zip
feat: Add code block highlighting
Theme is configurable
Diffstat (limited to 'test')
-rw-r--r--test/app.test.js22
-rw-r--r--test/domain/posts.test.js28
-rw-r--r--test/snapshots/app.test.js.md46
-rw-r--r--test/snapshots/app.test.js.snapbin1236 -> 1550 bytes
-rw-r--r--test/testsite/posts/testfile.md11
5 files changed, 83 insertions, 24 deletions
diff --git a/test/app.test.js b/test/app.test.js
index 2445493..ac0ce2d 100644
--- a/test/app.test.js
+++ b/test/app.test.js
@@ -9,7 +9,9 @@ const mf = require("microformat-node");
 process.chdir(path.resolve(__dirname, "./testsite/"));
 const config = require(path.resolve(__dirname, "../src/modules/config.js"));
 
-const app = require("../src/app.js");
+const App = require("../src/app.js");
+let app;
+test.before(async t => (app = await App()));
 
 const parseResponse = res =>
   cheerio.load(res.text, {
@@ -52,7 +54,8 @@ test("homepage", async function(t) {
   t.deepEqual(count, {
     "h-card": 1,
     "h-feed": 1,
-    "h-entry": 1
+    "h-entry": 1,
+    rels: 1
   });
 
   const data = await mf.getAsync(options);
@@ -82,7 +85,8 @@ test("post", async function(t) {
 
   t.deepEqual(count, {
     "h-card": 1,
-    "h-entry": 1
+    "h-entry": 1,
+    rels: 1
   });
 
   const data = await mf.getAsync(options);
@@ -111,7 +115,8 @@ test("tags", async function(t) {
   t.deepEqual(count, {
     "h-card": 1,
     "h-feed": 1,
-    "h-entry": 1
+    "h-entry": 1,
+    rels: 1
   });
 
   const data = await mf.getAsync(options);
@@ -119,5 +124,14 @@ test("tags", async function(t) {
   t.snapshot(data, "should contain relevant microformats data");
 });
 
+test("highlight css", async function(t) {
+  const res = await request(app.listen()).get("/css/code.css");
+
+  t.is(res.statusCode, 200);
+  t.is(res.type, "text/css");
+  t.is(res.charset, "utf-8");
+  t.regex(res.text, /^\.hljs/m);
+});
+
 test(notFound, "/post/non-existent", /Post not found/);
 test(notFound, "/tag/non-existent", /tag non-existent not found/);
diff --git a/test/domain/posts.test.js b/test/domain/posts.test.js
index 8b27698..bb97361 100644
--- a/test/domain/posts.test.js
+++ b/test/domain/posts.test.js
@@ -1,18 +1,22 @@
 const test = require("ava");
 const path = require("path");
 
-const Posts = require("../../src/domain/posts.js")(
-  {
-    folder: path.resolve(__dirname, "../testsite/posts/"),
-    taxonomies: {
-      tag: "tags",
-      category: "categories"
-    }
-  },
-  basename => basename
-);
+const Posts = require("../../src/domain/posts.js");
 
-test("get", t => {
+test.beforeEach(async t => {
+  t.context = await Posts(
+    {
+      folder: path.resolve(__dirname, "../testsite/posts/"),
+      taxonomies: {
+        tag: "tags",
+        category: "categories"
+      }
+    },
+    basename => basename
+  );
+});
+
+test("get", async t => {
   const expected = new Map(
     Object.entries({
       title: "This is a test",
@@ -21,7 +25,7 @@ test("get", t => {
       tags: ["a", "b"]
     })
   );
-  const post = Posts.get(
+  const post = await t.context.get(
     basename => basename,
     path.resolve(__dirname, "../testsite/posts/testfile.md")
   );
diff --git a/test/snapshots/app.test.js.md b/test/snapshots/app.test.js.md
index 99811f9..a595585 100644
--- a/test/snapshots/app.test.js.md
+++ b/test/snapshots/app.test.js.md
@@ -56,8 +56,18 @@ Generated by [AVA](https://ava.li).
           ],
         },
       ],
-      'rel-urls': {},
-      rels: {},
+      'rel-urls': {
+        '/css/code.css': {
+          rels: [
+            'stylesheet',
+          ],
+        },
+      },
+      rels: {
+        stylesheet: [
+          '/css/code.css',
+        ],
+      },
     }
 
 ## post
@@ -86,8 +96,8 @@ Generated by [AVA](https://ava.li).
           properties: {
             content: [
               {
-                html: '<p>Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat velit, scelerisque in dictum non, consectetur a erat nam at lectus urna duis convallis convallis tellus, id interdum velit laoreet!</p>',
-                value: 'Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat velit, scelerisque in dictum non, consectetur a erat nam at lectus urna duis convallis convallis tellus, id interdum velit laoreet!',
+                html: '<p>Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat velit, scelerisque in dictum non, consectetur a erat nam at lectus urna duis convallis convallis tellus, id interdum velit laoreet!</p> <pre><code class="language-sh"> <span class="hljs-meta">#!/usr/bin/env zsh </span> <span class="hljs-built_in">echo</span> this is some shell code <span class="hljs-keyword">if</span> [[ -n <span class="hljs-variable">$test</span> ]] <span class="hljs-keyword">then</span> <span class="hljs-built_in">echo</span> <span class="hljs-built_in">test</span> passed <span class="hljs-keyword">fi</span> </code></pre>',
+                value: 'Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat velit, scelerisque in dictum non, consectetur a erat nam at lectus urna duis convallis convallis tellus, id interdum velit laoreet! #!/usr/bin/env zsh echo this is some shell code if [[ -n $test ]] then echo test passed fi',
               },
             ],
             name: [
@@ -102,8 +112,18 @@ Generated by [AVA](https://ava.li).
           ],
         },
       ],
-      'rel-urls': {},
-      rels: {},
+      'rel-urls': {
+        '/css/code.css': {
+          rels: [
+            'stylesheet',
+          ],
+        },
+      },
+      rels: {
+        stylesheet: [
+          '/css/code.css',
+        ],
+      },
     }
 
 ## tags
@@ -158,6 +178,16 @@ Generated by [AVA](https://ava.li).
           ],
         },
       ],
-      'rel-urls': {},
-      rels: {},
+      'rel-urls': {
+        '/css/code.css': {
+          rels: [
+            'stylesheet',
+          ],
+        },
+      },
+      rels: {
+        stylesheet: [
+          '/css/code.css',
+        ],
+      },
     }
diff --git a/test/snapshots/app.test.js.snap b/test/snapshots/app.test.js.snap
index bbc5c61..e356c77 100644
--- a/test/snapshots/app.test.js.snap
+++ b/test/snapshots/app.test.js.snap
Binary files differdiff --git a/test/testsite/posts/testfile.md b/test/testsite/posts/testfile.md
index 84d8ed1..d6a4292 100644
--- a/test/testsite/posts/testfile.md
+++ b/test/testsite/posts/testfile.md
@@ -7,3 +7,14 @@ Tags = ["a", "b"]
 Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat
 velit, scelerisque in dictum non, consectetur a erat nam at lectus
 urna duis convallis convallis tellus, id interdum velit laoreet!
+
+```sh
+#!/usr/bin/env zsh
+
+echo this is some shell code
+
+if [[ -n $test ]]
+then
+    echo test passed
+fi
+```