Skip to content

Commit

Permalink
fix: add tests for provided data
Browse files Browse the repository at this point in the history
  • Loading branch information
learosema committed Oct 2, 2024
1 parent 0c7a63b commit b7e9c9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transforms/template-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function handleTemplateFile(config, data, inputFile) {

const page = {
fileSlug: parsed.name,
filePathStem: path.join(parsed.dir, parsed.name),
filePathStem: path.join('/', parsed.dir, parsed.name),
inputPath: inputFile,
outputPath: absOutputFile,
outputFileExtension: plugin.outputFileExtension || 'html',
Expand Down
34 changes: 34 additions & 0 deletions tests/transforms/template-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,38 @@ describe('handleTemplateFile function', () => {
});
});

it('should populate data provided by sissi in the template', async () => {
const config = new SissiConfig();
config.addExtension(md);
const vFS = new Map();

const PAGE_TEST = [
'page.url: {{ page.url }}',
'page.filePathStem: {{ page.filePathStem }}',
'page.outputPath: {{ page.outputPath }}',
'page.outputFileExtension: {{ page.outputFileExtension }}',
].join('\n');

const PAGE_TEST_EXPECTED = [
'page.url: /index.html',
'page.filePathStem: /index',
'page.outputPath: public' + path.sep + 'index.html',
'page.outputFileExtension: html',
].join('\n');

vFS.set('index.html', PAGE_TEST);

config.resolve = (...paths) => {
const resource = path.normalize(path.join(...paths));
if (vFS.has(resource)) {
return vFS.get(resource);
}
}

const result = await handleTemplateFile(config, {}, 'index.html');
assert.equal(result.content, PAGE_TEST_EXPECTED);
});



});

0 comments on commit b7e9c9c

Please sign in to comment.