fix: do not hardcode siteConfig path (#1150)

* Fix broken build

Do not hardcode path in require to siteConfig

* Just require instead of loadConfig

* Actually use loadConfig

I think the test may be wrong too.

* refactor & nits

* jest mock to fix test

* fix test
This commit is contained in:
Joel Marcey 2018-12-07 10:09:25 -08:00 committed by Endilie Yacop Sucipto
parent 71824a3541
commit c78a8b4262
5 changed files with 19 additions and 11 deletions

View file

@ -10,6 +10,10 @@ const blog = require('../blog');
const metadataUtils = require('../metadataUtils');
const {replaceAssetsLink} = require('../utils.js');
jest.mock(`${process.cwd()}/siteConfig.js`, () => ({baseUrl: '/'}), {
virtual: true,
});
const testFile = path.join(
__dirname,
'__fixtures__',
@ -76,7 +80,7 @@ describe('replaceAssetsLink', () => {
'utf8',
);
const rawContent1 = metadataUtils.extractMetadata(doc1).rawContent;
const content1 = replaceAssetsLink(rawContent1, 'blog');
const content1 = replaceAssetsLink(rawContent1, '/blog');
expect(content1).toMatchSnapshot();
expect(content1).toContain('![image1](/blog/assets/image1.png)');
expect(content1).toContain('![image2](/blog/assets/image2.jpg)');
@ -95,7 +99,7 @@ describe('replaceAssetsLink', () => {
'utf8',
);
const rawContent2 = metadataUtils.extractMetadata(doc2).rawContent;
const content2 = replaceAssetsLink(rawContent2, 'blog');
const content2 = replaceAssetsLink(rawContent2, '/blog');
expect(content2).toMatchSnapshot();
expect(content2).not.toContain('![image1](/blog/assets/image1.png)');
expect(content2).not.toContain('![image2](/blog/assets/image2.jpg)');