summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2017-06-30 17:37:20 +0200
committerAlan Pearce2017-06-30 17:37:20 +0200
commit562b0533300ad5ad8cf4695aa7fc2b844b918169 (patch)
tree96ab4a7e838d4e7d8b06fc08eaa351ba58992721
parent136ebe22452c0015770d9f0ac9d94d8941461816 (diff)
downloadhomestead-562b0533300ad5ad8cf4695aa7fc2b844b918169.tar.lz
homestead-562b0533300ad5ad8cf4695aa7fc2b844b918169.tar.zst
homestead-562b0533300ad5ad8cf4695aa7fc2b844b918169.zip
feat: load config from cwd and merge with defaults
-rw-r--r--src/modules/config.js18
-rw-r--r--test/app.test.js50
-rw-r--r--test/domain/posts.test.js34
-rw-r--r--test/testsite/config.toml2
-rw-r--r--test/testsite/posts/testfile.md (renamed from test/data/testfile.md)0
5 files changed, 56 insertions, 48 deletions
diff --git a/src/modules/config.js b/src/modules/config.js
index 461945d..72d1b1a 100644
--- a/src/modules/config.js
+++ b/src/modules/config.js
@@ -1,10 +1,14 @@
-'use strict'
+"use strict";
 
-const TOML = require('toml')
-const config = require('configly')
+const path = require("path");
+const TOML = require("toml");
+const config = require("configly");
 
-module.exports = config({
-  parsers: {
-    toml: TOML.parse
+module.exports = config(
+  ["./config", path.resolve(__dirname, "../../config/")],
+  {
+    parsers: {
+      toml: TOML.parse
+    }
   }
-})
+);
diff --git a/test/app.test.js b/test/app.test.js
index a054366..9b0403c 100644
--- a/test/app.test.js
+++ b/test/app.test.js
@@ -1,49 +1,49 @@
-const test = require('ava')
-const path = require('path')
-const request = require('supertest')
+const test = require("ava");
+const path = require("path");
+const request = require("supertest");
 
-const config = require('../src/modules/config.js')
-config.posts.folder = path.resolve(__dirname, './data/')
+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");
 
-test('homepage', t => {
+test("homepage", t => {
   return request(app.listen())
-    .get('/')
+    .get("/")
     .expect(200)
     .expect(/<title>Test Site<\/title>/)
     .expect(/<h1>Test Site<\/h1>/)
     .expect(/This is a test/)
-    .then(() => t.pass())
-})
+    .then(() => t.pass());
+});
 
-test('post', t => {
+test("post", t => {
   return request(app.listen())
-    .get('/post/testfile')
+    .get("/post/testfile")
     .expect(200)
     .expect(/<h1>Lorem ipsum<\/h1>/)
-    .then(() => t.pass())
-})
+    .then(() => t.pass());
+});
 
-test('post not found', t => {
+test("post not found", t => {
   return request(app.listen())
-    .get('/post/non-existant')
+    .get("/post/non-existant")
     .expect(404)
     .expect(/Post not found/)
-    .then(() => t.pass())
-})
+    .then(() => t.pass());
+});
 
-test('tags', t => {
+test("tags", t => {
   return request(app.listen())
-    .get('/tag/a')
+    .get("/tag/a")
     .expect(200)
     .expect(/This is a test/)
-    .then(() => t.pass())
-})
+    .then(() => t.pass());
+});
 
-test('tags not found', t =>
+test("tags not found", t =>
   request(app.listen())
-    .get('/tag/non-existant')
+    .get("/tag/non-existant")
     .expect(404)
     .expect(/tag non-existant not found/)
-    .then(() => t.pass()))
+    .then(() => t.pass()));
diff --git a/test/domain/posts.test.js b/test/domain/posts.test.js
index 8866f40..c433ce5 100644
--- a/test/domain/posts.test.js
+++ b/test/domain/posts.test.js
@@ -1,23 +1,25 @@
-const test = require('ava')
-const path = require('path')
+const test = require("ava");
+const path = require("path");
 
-const Posts = require('../../src/domain/posts.js')({
-  folder: path.resolve('../data', __dirname),
+const Posts = require("../../src/domain/posts.js")({
+  folder: path.resolve(__dirname, "../testsite/posts/"),
   taxonomies: {
-    tag: 'tags',
-    category: 'categories'
+    tag: "tags",
+    category: "categories"
   }
-})
+});
 
-test('get', t => {
+test("get", t => {
   const expected = new Map(
     Object.entries({
-      title: 'This is a test',
-      description: 'Test file',
-      tags: ['a', 'b']
+      title: "This is a test",
+      description: "Test file",
+      tags: ["a", "b"]
     })
-  )
-  const post = Posts.get(path.resolve(__dirname, '../data/testfile.md'))
-  t.deepEqual(post.data, expected)
-  t.is(post.basename, 'testfile', 'must include basename')
-})
+  );
+  const post = Posts.get(
+    path.resolve(__dirname, "../testsite/posts/testfile.md")
+  );
+  t.deepEqual(post.data, expected);
+  t.is(post.basename, "testfile", "must include basename");
+});
diff --git a/test/testsite/config.toml b/test/testsite/config.toml
new file mode 100644
index 0000000..1fbbb82
--- /dev/null
+++ b/test/testsite/config.toml
@@ -0,0 +1,2 @@
+[posts]
+folder = "./posts"
\ No newline at end of file
diff --git a/test/data/testfile.md b/test/testsite/posts/testfile.md
index bafc456..bafc456 100644
--- a/test/data/testfile.md
+++ b/test/testsite/posts/testfile.md