test: add test for load config

This commit is contained in:
endiliey 2018-08-10 14:52:02 +08:00
parent 687bf09c96
commit bf94bf96f8
6 changed files with 71 additions and 8 deletions

35
test/load/config.test.js Normal file
View file

@ -0,0 +1,35 @@
import path from 'path';
import loadConfig from '@lib/load/config.js';
describe('loadConfig', () => {
test('website with valid siteConfig', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
const config = loadConfig(siteDir);
expect(config).toEqual({
baseUrl: '/',
organizationName: 'endiliey',
projectName: 'hello',
tagline: 'Hello World',
title: 'Hello'
});
expect(config).not.toEqual({});
});
test('website with incomplete siteConfig', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'bad-site');
expect(() => {
loadConfig(siteDir);
}).toThrowErrorMatchingInlineSnapshot(
`"tagline, organizationName, projectName are missing in siteConfig.js"`
);
});
test('website with no siteConfig', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'nonExisting');
expect(() => {
loadConfig(siteDir);
}).toThrowErrorMatchingInlineSnapshot(
`"title, tagline, organizationName, projectName, baseUrl are missing in siteConfig.js"`
);
});
});