diff --git a/tests/spec/core/data-include-spec.js b/tests/spec/core/data-include-spec.js index 5ef34d1bf0..75b0589a8b 100644 --- a/tests/spec/core/data-include-spec.js +++ b/tests/spec/core/data-include-spec.js @@ -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( + "top-level document (outer.html)" + ); + expect(innerTarget.textContent).not.toContain( + "included file's own directory" + ); + }); + it("includes text when data-include-format is 'text'", async () => { const ops = { config: makeBasicConfig(), diff --git a/tests/spec/core/nested-include/foo/bar.html b/tests/spec/core/nested-include/foo/bar.html new file mode 100644 index 0000000000..719ea3b2a3 --- /dev/null +++ b/tests/spec/core/nested-include/foo/bar.html @@ -0,0 +1,15 @@ +
bar content
+ + diff --git a/tests/spec/core/nested-include/foo/includes/data.json b/tests/spec/core/nested-include/foo/includes/data.json new file mode 100644 index 0000000000..06906ef57a --- /dev/null +++ b/tests/spec/core/nested-include/foo/includes/data.json @@ -0,0 +1 @@ +{ "resolvedRelativeTo": "included file's own directory (foo/bar.html)" } diff --git a/tests/spec/core/nested-include/includes/data.json b/tests/spec/core/nested-include/includes/data.json new file mode 100644 index 0000000000..0fca158e34 --- /dev/null +++ b/tests/spec/core/nested-include/includes/data.json @@ -0,0 +1 @@ +{ "resolvedRelativeTo": "top-level document (outer.html)" } diff --git a/tests/spec/core/nested-include/outer.html b/tests/spec/core/nested-include/outer.html new file mode 100644 index 0000000000..6940f3db71 --- /dev/null +++ b/tests/spec/core/nested-include/outer.html @@ -0,0 +1,29 @@ + + + + +Basic doc
+CUSTOM PARAGRAPH
+