Skip to content
Merged
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
46 changes: 46 additions & 0 deletions scripts/sync-sibling-docs.main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,52 @@ describe("sync-sibling-docs main()", () => {
expect(fs.existsSync(shared)).toBe(true);
});

it("never prunes paths a removed page references outside its directory, by URL, or that are not files", async () => {
const stale = outPath("hotshot", "linux.md");
const outside = path.join(caseDir, "docs", "escape.png");
const sibling = outPath("pluk", "images/pluk.png");
const dir = outPath("hotshot", "images/dir");
// Where the URL refs below would land if localImageRefs stopped skipping
// them: the scheme/host segments become path components under outDir.
const schemeAsPath = outPath("hotshot", "https:/example.com/remote.png");
const protoAsPath = outPath("hotshot", "cdn.example.com/remote.png");
fs.mkdirSync(path.dirname(stale), { recursive: true });
fs.mkdirSync(path.dirname(sibling), { recursive: true });
fs.mkdirSync(dir, { recursive: true });
fs.mkdirSync(path.dirname(schemeAsPath), { recursive: true });
fs.mkdirSync(path.dirname(protoAsPath), { recursive: true });
fs.writeFileSync(outside, "png");
fs.writeFileSync(sibling, "png");
fs.writeFileSync(schemeAsPath, "png");
fs.writeFileSync(protoAsPath, "png");
fs.writeFileSync(
stale,
[
"![up](../../escape.png)",
"![other](../pluk/images/pluk.png)",
"![abs](https://example.com/remote.png)",
"![proto](//cdn.example.com/remote.png)",
"![anchor](#not-an-image)",
"![data](data:image/png;base64,AAAA)",
"![gone](images/already-gone.png)",
"![dir](images/dir)",
"",
].join("\n")
);
stubFetch(allReadmes());
const { warn, err } = await runSync();

expect(exitSpy).not.toHaveBeenCalled();
expect(err).toBe("");
expect(fs.existsSync(stale)).toBe(false);
expect(warn).toContain("removed stale hotshot/linux.md");
expect(fs.existsSync(outside)).toBe(true);
expect(fs.existsSync(sibling)).toBe(true);
expect(fs.existsSync(schemeAsPath)).toBe(true);
expect(fs.existsSync(protoAsPath)).toBe(true);
expect(fs.statSync(dir).isDirectory()).toBe(true);
});

it.each([429, 500])(
"keeps a previously synced optional page when its source answers %i",
async status => {
Expand Down
Loading