Skip to content

Commit 6f4f6e7

Browse files
authored
scanIncludes: make includes relative to spec directory (#145)
1 parent 6c6a5a5 commit 6f4f6e7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/scan-includes.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = async function scanIncludes(repositoryUrl, rootSpec, specType,
7777
* the fetch worked, and then recursively scans any includes found in the
7878
* response.
7979
*/
80-
async function scanOneFile(path) {
80+
async function scanOneFile(path, specDir) {
8181
if (everFetched.has(path)) return;
8282
everFetched.add(path);
8383

@@ -99,11 +99,13 @@ module.exports = async function scanIncludes(repositoryUrl, rootSpec, specType,
9999
// Intentionally serial since Node's treatment of connection pooling is
100100
// hard to figure out from the documentation:
101101
for (const match of body.matchAll(includeRE)) {
102-
await scanOneFile(match[1].trim());
102+
await scanOneFile(specDir + match[1].trim(), specDir);
103103
}
104104
}
105105
console.log(`scanIncludes: Recursively scanning ${rootSpec} in ${repositoryUrl} for includes.`)
106-
await scanOneFile(rootSpec);
106+
// Includes are relative to the root spec file.
107+
const specDir = rootSpec.substring(0, rootSpec.lastIndexOf('/') + 1);
108+
await scanOneFile(rootSpec, specDir);
107109

108110
recursiveIncludes.delete(rootSpec);
109111
console.log(`scanIncludes: Found includes: ${JSON.stringify([...recursiveIncludes])}`)

test/scan-includes.js

+15
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,19 @@ suite('scanIncludes', function () {
8484
"single.html",
8585
]);
8686
});
87+
test('Separate spec directory with includes', async function() {
88+
assert.deepStrictEqual(await scanIncludes("https://github.example/repo/", "spec/index.bs", "bikeshed", fakeFetch({
89+
"https://github.example/repo/spec/index.bs": { body: "path: helper.inc" },
90+
"https://github.example/repo/spec/helper.inc": { body: "path: helper2.inc" },
91+
"https://github.example/repo/spec/helper2.inc": { body: "path: subdir/helper3.inc" },
92+
"https://github.example/repo/spec/subdir/helper3.inc": { body: "path: subdir/helper4.inc" },
93+
"https://github.example/repo/spec/subdir/helper4.inc": { body: "" },
94+
})),
95+
[
96+
"spec/helper.inc",
97+
"spec/helper2.inc",
98+
"spec/subdir/helper3.inc",
99+
"spec/subdir/helper4.inc",
100+
]);
101+
});
87102
});

0 commit comments

Comments
 (0)