Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/spec/core/data-include-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,43 @@ describe("Core — Data Include", () => {
).toBeTrue();
});

it("resolves a nested data-include's relative URL against the top-level document, not the including file's own URL", async () => {
// Fixtures live under tests/spec/core/nested-include/:
// outer.html <- the document under test
// foo/bar.html <- fetched via outer.html's data-include="foo/bar.html"
// includes/data.json <- resolving "includes/data.json" against outer.html
// foo/includes/data.json <- resolving "includes/data.json" against foo/bar.html
//
// foo/bar.html itself has data-include="includes/data.json". This test
// asserts which of the two data.json files actually gets fetched, i.e.
// whether nested includes resolve relative URLs against the document
// that started the include chain, or against the file that declared
// the nested data-include.
const nestedIncludeUrl = "/tests/spec/core/nested-include/outer.html";
const ops = {
config: makeBasicConfig(),
body: makeDefaultBody(),
};
const doc = await makeRSDoc(ops, nestedIncludeUrl);

const outerTarget = doc.querySelector("#nested-target");
expect(outerTarget).toBeTruthy();
expect(outerTarget.querySelector("p").textContent).toBe("bar content");

const innerTarget = doc.querySelector("#inner-target");
expect(innerTarget).toBeTruthy();
// Current behavior: the nested data-include is resolved relative to
// outer.html (the top-level document), *not* relative to foo/bar.html
// (the file that declared it) — even though foo/bar.html was itself
// fetched from a "foo/" subdirectory.
expect(innerTarget.textContent).toContain(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the current behavior is a bug, then I should make this assertion a not and remove the not from the nest assertion.

"top-level document (outer.html)"
);
expect(innerTarget.textContent).not.toContain(
"included file's own directory"
);
});
Comment on lines +161 to +171

it("includes text when data-include-format is 'text'", async () => {
const ops = {
config: makeBasicConfig(),
Expand Down
15 changes: 15 additions & 0 deletions tests/spec/core/nested-include/foo/bar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p>bar content</p>
<!--
This nested include uses a URL relative to "includes/data.json". The
question this fixture answers: is that URL resolved relative to *this*
file's location (tests/spec/core/nested-include/foo/bar.html), which
would yield tests/spec/core/nested-include/foo/includes/data.json, or
relative to the top-level document that started the include chain
(tests/spec/core/nested-include/outer.html), which would yield
tests/spec/core/nested-include/includes/data.json?
Comment on lines +3 to +9
-->
<div
id="inner-target"
data-include="includes/data.json"
data-include-format="text"
></div>
1 change: 1 addition & 0 deletions tests/spec/core/nested-include/foo/includes/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "resolvedRelativeTo": "included file's own directory (foo/bar.html)" }
1 change: 1 addition & 0 deletions tests/spec/core/nested-include/includes/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "resolvedRelativeTo": "top-level document (outer.html)" }
29 changes: 29 additions & 0 deletions tests/spec/core/nested-include/outer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Nested Include Outer Spec</title>
<script class="remove">
var respecConfig = {
specStatus: "ED",
shortName: "nested-include-outer",
};
</script>
</head>
<body>
<section id="abstract">
<p>Basic doc</p>
</section>
<section id="sotd">
<p>CUSTOM PARAGRAPH</p>
</section>
<section id="nested-includes">
<!--
This outer include is relative to this document's own URL
(tests/spec/core/nested-include/outer.html), so it resolves to
tests/spec/core/nested-include/foo/bar.html
-->
<div id="nested-target" data-include="foo/bar.html"></div>
</section>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/spec/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const additionalFiles = [
included: false,
},
{
pattern: "tests/spec/**/*-spec.js",
pattern: process.env.SPEC_FILE_PATTERN || "tests/spec/**/*-spec.js",
type: "module",
included: false,
},
Expand Down