dotwee_obsidian-raindropio-.../tests/note-parser.test.ts
Lukas Wolfsteiner c22dc1f969 build: modernize TypeScript and esbuild configuration
Set compile and bundle target to ES2021 since Obsidian runs on modern Electron.
Replace individual strict flags with strict: true and add noFallthroughCasesInSwitch, skipLibCheck and forceConsistentCasingInFileNames.
Switch module resolution to bundler, removing the need for deprecation workarounds on TypeScript 6.
Drop baseUrl, allowJs and importHelpers; tests now import sources via relative paths.
Aligns the project with the modernized obsidian-sample-plugin configuration.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 11:20:56 +02:00

41 lines
1.3 KiB
TypeScript

import type { CachedMetadata } from "obsidian";
import { getNoteRaindropReferences, getUrlKey } from "../src/note-parser";
describe("getNoteRaindropReferences", () => {
it("extracts unique tags and urls from a note", () => {
const metadata: CachedMetadata = {
tags: [{ tag: "#research", position: { start: { line: 0, col: 0, offset: 0 }, end: { line: 0, col: 9, offset: 9 } } }],
frontmatter: {
tags: ["saved", "#research"],
},
};
const source = [
"[Obsidian](https://obsidian.md/)",
"https://raindrop.io/library,",
"https://obsidian.md/",
].join("\n");
expect(getNoteRaindropReferences(source, metadata)).toEqual({
tags: ["research", "saved"],
urls: ["https://obsidian.md/", "https://raindrop.io/library"],
});
});
it("handles notes without metadata", () => {
expect(getNoteRaindropReferences("No links here", null)).toEqual({
tags: [],
urls: [],
});
});
});
describe("getUrlKey", () => {
it("normalizes equivalent urls for comparison", () => {
expect(getUrlKey("https://Example.com/path/#section")).toBe("https://example.com/path");
expect(getUrlKey("https://example.com/path/")).toBe("https://example.com/path");
});
it("falls back to lower-cased text for invalid urls", () => {
expect(getUrlKey("Example/Path/")).toBe("example/path");
});
});