mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { resolveAssetPath } from '../../../../src/util/PathUtil';
|
|
import { readTemplate } from '../../../../src/util/templates/TemplateEngine';
|
|
import { mockFs } from '../../../util/Util';
|
|
|
|
jest.mock('fs');
|
|
|
|
describe('readTemplate', (): void => {
|
|
const templateFile = 'template.xyz';
|
|
const templatePath = 'other';
|
|
|
|
beforeEach(async(): Promise<void> => {
|
|
const { data } = mockFs(resolveAssetPath(''));
|
|
Object.assign(data, {
|
|
'template.xyz': '{{template}}',
|
|
other: {
|
|
'template.xyz': '{{other}}',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('returns the empty string when no template is provided.', async(): Promise<void> => {
|
|
await expect(readTemplate()).resolves.toBe('');
|
|
});
|
|
|
|
it('accepts a filename.', async(): Promise<void> => {
|
|
await expect(readTemplate(templateFile)).resolves.toBe('{{template}}');
|
|
});
|
|
|
|
it('accepts options with a string template.', async(): Promise<void> => {
|
|
await expect(readTemplate({ templateString: 'abc' })).resolves.toBe('abc');
|
|
});
|
|
|
|
it('accepts options with a filename.', async(): Promise<void> => {
|
|
await expect(readTemplate({ templateFile })).resolves.toBe('{{template}}');
|
|
});
|
|
|
|
it('accepts options with a filename and a path.', async(): Promise<void> => {
|
|
await expect(readTemplate({ templateFile, templatePath })).resolves.toBe('{{other}}');
|
|
});
|
|
});
|