Skip to content

Commit

Permalink
fix(theme): fix serving and exporting local themes (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuluWarrior committed Jun 19, 2021
1 parent a13e63b commit 16eae28
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const themeServer =
const fs = require('fs');
const request = require('superagent');
const chalk = require('chalk');
const renderHtml = require('./render-html');
const renderHtml = require('./render-html').default;

const denormalizeTheme = (value) => {
return value.match(/jsonresume-theme-(.*)/)[1];
Expand Down
10 changes: 6 additions & 4 deletions lib/render-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export default async ({ resume, themePath }) => {
const cwd = process.cwd();
let path;
if (themePath[0] === '.') {
path = tryResolve(path.join(cwd, themePath), { paths: [cwd] });
throw new Error(
`Theme ${themePath} could not be resolved relative to ${cwd}`,
);
path = tryResolve(require('path').join(cwd, themePath), { paths: [cwd] });
if (!path) {
throw new Error(
`Theme ${themePath} could not be resolved relative to ${cwd}`,
);
}
}
if (!path) {
path = tryResolve(themePath, { paths: [cwd] });
Expand Down
22 changes: 17 additions & 5 deletions lib/render-html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ describe('renderHTML', () => {
const originalRequireResolve = require.resolve;
const mockThemePath = 'mock/path/to/jsonresume-theme-even';
require.resolve = (...args) => {
if (args[0] === 'jsonresume-theme-even') {
return mockThemePath;
}
if (args[0] === 'jsonresume-theme-even') {
return mockThemePath;
}
Expand All @@ -25,13 +22,13 @@ describe('renderHTML', () => {
},
};

it('should reject when theme is not availlable', async () => {
it('should reject when theme is not available', async () => {
await expect(
renderHTML({ resume, themePath: 'unknown' }),
).rejects.toBeTruthy();
});

describe('should render html when theme is availlable', () => {
describe('should render html when theme is available', () => {
it('with long theme name', async () => {
expect(
await renderHTML({ resume, themePath: 'jsonresume-theme-even' }),
Expand All @@ -43,5 +40,20 @@ describe('renderHTML', () => {
'<!doctype html>',
);
});

it('should reject theme with invalid path', async () => {
await expect(
renderHTML({ resume, themePath: './unknown' }),
).rejects.toBeTruthy();
});

it('with local theme path', async () => {
expect(
await renderHTML({
resume,
themePath: './node_modules/jsonresume-theme-even',
}),
).toStartWith('<!doctype html>');
});
});
});

0 comments on commit 16eae28

Please sign in to comment.