diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-03-26 08:42:14 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-03-26 08:42:14 -0300 |
commit | 4e6f3c16818d9beb200c337d48c8ae2470a322ee (patch) | |
tree | b05bc1f5df177572bdf61eb32d0c34823d010ce1 | |
parent | 5dfdb661c4672bcf432c9bd283a2ffec5a3c1cb3 (diff) |
data steps: linkTemplate snapshot tests
-rw-r--r-- | src/content-function.js | 6 | ||||
-rw-r--r-- | src/content/dependencies/linkTemplate.js | 5 | ||||
-rw-r--r-- | tap-snapshots/test/snapshots/linkTemplate.js.test.cjs | 14 | ||||
-rw-r--r-- | test/snapshots/linkTemplate.js | 28 |
4 files changed, 50 insertions, 3 deletions
diff --git a/src/content-function.js b/src/content-function.js index 0a217800..377eecc9 100644 --- a/src/content-function.js +++ b/src/content-function.js @@ -279,7 +279,9 @@ export function flattenRelationsTree({ } } - recursive(relationsTree); + if (relationsTree) { + recursive(relationsTree); + } return { root, @@ -335,7 +337,7 @@ export function quickEvaluate({ extraDependencies: allExtraDependencies, name, - args, + args = [], }) { const treeInfo = getRelationsTree(allContentDependencies, name, ...args); const flatTreeInfo = flattenRelationsTree(treeInfo); diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js index 94b90652..acac99be 100644 --- a/src/content/dependencies/linkTemplate.js +++ b/src/content/dependencies/linkTemplate.js @@ -26,7 +26,10 @@ export default { } if (appendIndexHTML) { - if (/^(?!https?:\/\/).+\/$/.test(href)) { + if ( + /^(?!https?:\/\/).+\/$/.test(href) && + href.endsWith('/') + ) { href += 'index.html'; } } diff --git a/tap-snapshots/test/snapshots/linkTemplate.js.test.cjs b/tap-snapshots/test/snapshots/linkTemplate.js.test.cjs new file mode 100644 index 00000000..e3c3356b --- /dev/null +++ b/tap-snapshots/test/snapshots/linkTemplate.js.test.cjs @@ -0,0 +1,14 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/snapshots/linkTemplate.js TAP linkTemplate > output 1`] = ` +<a class="dog" id="cat1" href="https://hsmusic.wiki/media/cool%20file.pdf#fooey" style="--primary-color: #123456ff; --dim-color: #12345677">My Cool Link</a> +` + +exports[`test/snapshots/linkTemplate.js TAP linkTemplate > output 2`] = ` +<a href="/c*lzone/myCoolPath/ham/pineapple/tomato/index.html"></a> +` diff --git a/test/snapshots/linkTemplate.js b/test/snapshots/linkTemplate.js new file mode 100644 index 00000000..0dcf5b61 --- /dev/null +++ b/test/snapshots/linkTemplate.js @@ -0,0 +1,28 @@ +import t from 'tap'; + +import {testContentFunctions} from './_support.js'; + +testContentFunctions(t, 'linkTemplate', (t, evaluate) => { + evaluate.snapshot({ + name: 'linkTemplate', + extraDependencies: { + getColors: c => ({primary: c + 'ff', dim: c + '77'}), + }, + }, + v => v + .slot('color', '#123456') + .slot('href', 'https://hsmusic.wiki/media/cool file.pdf') + .slot('hash', 'fooey') + .slot('attributes', {class: 'dog', id: 'cat1'}) + .slot('content', 'My Cool Link')); + + evaluate.snapshot({ + name: 'linkTemplate', + extraDependencies: { + to: (...path) => '/c*lzone/' + path.join('/') + '/', + appendIndexHTML: true, + }, + }, + v => v + .slot('path', ['myCoolPath', 'ham', 'pineapple', 'tomato'])); +}); |