From e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 3 Jul 2017 21:39:43 +0200 Subject: feat: Add code block highlighting Theme is configurable --- test/app.test.js | 22 +++++++++++++++---- test/domain/posts.test.js | 28 +++++++++++++----------- test/snapshots/app.test.js.md | 46 +++++++++++++++++++++++++++++++++------- test/snapshots/app.test.js.snap | Bin 1236 -> 1550 bytes test/testsite/posts/testfile.md | 11 ++++++++++ 5 files changed, 83 insertions(+), 24 deletions(-) (limited to 'test') 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: '

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!

', - 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: '

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 
', + 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 Binary files a/test/snapshots/app.test.js.snap and b/test/snapshots/app.test.js.snap differ diff --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 +``` -- cgit 1.4.1