Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
- name: Typecheck (plugin and tests) and build
run: pnpm run build
- name: Lint
run: pnpm run lint
41 changes: 21 additions & 20 deletions __tests__/kanbanHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {afterEach, beforeEach, describe, it, expect, vi} from "vitest";
import {KanbanHelper} from "../src/automators/onFileModifyAutomators/kanbanHelper";
import {Notice, TFile} from "obsidian";
import {type TFile} from "obsidian";
import {createTFile, Notice} from "../tests/obsidian-stub";
import {log} from "../src/logger/logManager";
import {GuiLogger} from "../src/logger/guiLogger";

Expand All @@ -9,7 +10,7 @@ type MockFn = ReturnType<typeof vi.fn>;
vi.spyOn(console, "debug").mockImplementation(() => {});

const resetRegisteredLoggers = () => {
(log.constructor as {loggers: unknown[]}).loggers = [];
(log.constructor as unknown as {loggers: unknown[]}).loggers = [];
};

beforeEach(() => {
Expand Down Expand Up @@ -121,11 +122,11 @@ function setupBoard(board: string, notes: Record<string, NoteSpec>, boardName =
const app = createApp();
const plugin = createPlugin(app, [{boardName, property: "status"}]);
const helper = new KanbanHelper(plugin as any);
const boardFile = new TFile(`${boardName}.md`);
const boardFile = createTFile(`${boardName}.md`);

const noteFiles: Record<string, TFile> = {};
for (const name of Object.keys(notes)) {
noteFiles[name] = new TFile(notes[name].path ?? `${name}.md`);
noteFiles[name] = createTFile(notes[name].path ?? `${name}.md`);
}

app.metadataCache.getFileCache.mockReturnValue(buildBoardCache(board));
Expand Down Expand Up @@ -160,7 +161,7 @@ describe("KanbanHelper link resolution", () => {
const plugin = createPlugin(app);
const helper = new KanbanHelper(plugin as any);

const targetFile = new TFile("Folder/My Note.md");
const targetFile = createTFile("Folder/My Note.md");
app.metadataCache.getFirstLinkpathDest.mockImplementation((linkpath: string) => {
if (linkpath === "Folder/My Note") {
return targetFile;
Expand All @@ -183,7 +184,7 @@ describe("KanbanHelper link resolution", () => {

// Path resolution is only used for links that already name a folder path: such a
// path identifies exactly one file, so the direct lookup is unambiguous.
const targetFile = new TFile("Folder/Note.md");
const targetFile = createTFile("Folder/Note.md");
app.metadataCache.getFirstLinkpathDest.mockReturnValue(null);
app.vault.getAbstractFileByPath.mockImplementation((path: string) => {
return path === "Folder/Note.md" ? targetFile : null;
Expand All @@ -206,8 +207,8 @@ describe("KanbanHelper link resolution", () => {
const plugin = createPlugin(app);
const helper = new KanbanHelper(plugin as any);

const rootNote = new TFile("Note.md");
const folderNote = new TFile("Areas/Note.md");
const rootNote = createTFile("Note.md");
const folderNote = createTFile("Areas/Note.md");
app.metadataCache.getFirstLinkpathDest.mockReturnValue(null);
// The real vault WOULD return the root file here; the fix must not act on it.
app.vault.getAbstractFileByPath.mockImplementation((path: string) =>
Expand All @@ -226,7 +227,7 @@ describe("KanbanHelper link resolution", () => {
const plugin = createPlugin(app);
const helper = new KanbanHelper(plugin as any);

const targetFile = new TFile("Folder/Note.md");
const targetFile = createTFile("Folder/Note.md");
app.metadataCache.getFirstLinkpathDest.mockReturnValue(null);
app.vault.getAbstractFileByPath.mockReturnValue(null);
app.vault.getMarkdownFiles.mockReturnValue([targetFile]);
Expand All @@ -242,8 +243,8 @@ describe("KanbanHelper link resolution", () => {
const plugin = createPlugin(app);
const helper = new KanbanHelper(plugin as any);

const noteA = new TFile("Areas/Note.md");
const noteB = new TFile("Archive/Note.md");
const noteA = createTFile("Areas/Note.md");
const noteB = createTFile("Archive/Note.md");
app.metadataCache.getFirstLinkpathDest.mockReturnValue(null);
app.vault.getAbstractFileByPath.mockReturnValue(null);
app.vault.getMarkdownFiles.mockReturnValue([noteA, noteB]);
Expand All @@ -260,7 +261,7 @@ describe("KanbanHelper link resolution", () => {
const plugin = createPlugin(app);
const helper = new KanbanHelper(plugin as any);

const unrelatedFile = new TFile("Other/Note.md");
const unrelatedFile = createTFile("Other/Note.md");
app.metadataCache.getFirstLinkpathDest.mockReturnValue(null);
app.vault.getAbstractFileByPath.mockReturnValue(null);
app.vault.getMarkdownFiles.mockReturnValue([unrelatedFile]);
Expand Down Expand Up @@ -501,8 +502,8 @@ describe("KanbanHelper updates linked file properties", () => {
const app = createApp();
const plugin = createPlugin(app, [{boardName: "Board", property: "status"}]);
const helper = new KanbanHelper(plugin as any);
const boardFile = new TFile("Board.md");
const noteFile = new TFile("Note.md");
const boardFile = createTFile("Board.md");
const noteFile = createTFile("Note.md");

const staleLink = {link: "Note", original: "[[Note]]", position: {start: {line: 2, col: 6}}};
app.metadataCache.getFileCache.mockReturnValue({
Expand All @@ -528,9 +529,9 @@ describe("KanbanHelper updates linked file properties", () => {
const app = createApp();
const plugin = createPlugin(app, [{boardName: "Board", property: "status"}]);
const helper = new KanbanHelper(plugin as any);
const boardFile = new TFile("Board.md");
const rootTask = new TFile("Task.md");
const archiveTask = new TFile("Archive/Task.md");
const boardFile = createTFile("Board.md");
const rootTask = createTFile("Task.md");
const archiveTask = createTFile("Archive/Task.md");

const board = "## Doing\n\n- [ ] [[Task]]\n";
app.metadataCache.getFileCache.mockReturnValue(buildBoardCache(board));
Expand All @@ -552,8 +553,8 @@ describe("KanbanHelper updates linked file properties", () => {
const app = createApp();
const plugin = createPlugin(app, [{boardName: "Board", property: "status"}]);
const helper = new KanbanHelper(plugin as any);
const boardFile = new TFile("Board.md");
const note = new TFile("Areas/Task.md");
const boardFile = createTFile("Board.md");
const note = createTFile("Areas/Task.md");

const board = "## Doing\n\n- [ ] [[Task]]\n";
app.metadataCache.getFileCache.mockReturnValue(buildBoardCache(board));
Expand Down Expand Up @@ -615,7 +616,7 @@ describe("KanbanHelper updates linked file properties", () => {
it("does nothing when the modified file is not a configured board", async () => {
const board = "## Doing\n\n- [ ] [[Note]]\n";
const {helper, plugin} = setupBoard(board, {Note: {status: "Backlog"}});
const otherFile = new TFile("Not A Board.md");
const otherFile = createTFile("Not A Board.md");

await helper.onFileModify(otherFile);

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "pnpm run typecheck && node esbuild.config.mjs production",
"typecheck": "tsc --noEmit -p tsconfig.src.json && svelte-check --tsconfig ./tsconfig.src.json --threshold error",
"typecheck": "tsc --noEmit -p tsconfig.src.json && svelte-check --tsconfig ./tsconfig.src.json --threshold error && pnpm run typecheck:tests",
"typecheck:tests": "tsc --noEmit -p tsconfig.json",
"lint": "eslint . --max-warnings=0",
"test": "vitest run --passWithNoTests",
"test:watch": "vitest",
Expand Down
5 changes: 3 additions & 2 deletions src/Modals/GenericPrompt/valueSuggest.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {describe, expect, it} from "vitest";
import {TFile} from "obsidian";
import {type TFile} from "obsidian";
import {createTFile} from "../../../tests/obsidian-stub";
import {filterSuggestions, getDateInputType, getKnownPropertyNames, getValueSuggestions} from "./valueSuggest";
import {MetaType} from "../../Types/metaType";

Expand All @@ -14,7 +15,7 @@ const makeApp = (options: {
noTypeManager?: boolean;
}) => {
const files = options.files ?? {};
const markdownFiles = Object.keys(files).map(path => new TFile(path));
const markdownFiles = Object.keys(files).map(path => createTFile(path));

return {
vault: {
Expand Down
4 changes: 2 additions & 2 deletions src/Modals/menuFilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe("canStructureEditProperty", () => {
});

it("withholds structure edits on nested/virtual YAML rows", () => {
expect(canStructureEditProperty({key: "a.b", content: "v", type: MetaType.YAML, isNested: true})).toBe(false);
expect(canStructureEditProperty({key: "a.b", content: "v", type: MetaType.YAML, isVirtual: true})).toBe(false);
expect(canStructureEditProperty({type: MetaType.YAML, isNested: true})).toBe(false);
expect(canStructureEditProperty({type: MetaType.YAML, isVirtual: true})).toBe(false);
});
});
2 changes: 1 addition & 1 deletion src/Settings/settingsMigration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("mergeSettings", () => {
SomeFutureSection: {foo: 1},
};

const merged = mergeSettings(loaded) as typeof loaded & Record<string, unknown>;
const merged: Record<string, unknown> = {...mergeSettings(loaded)};
expect(merged.SomeFutureSection).toEqual({foo: 1});
});

Expand Down
17 changes: 9 additions & 8 deletions src/bulk/bulkMetadataEditor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { TFile } from "obsidian";
import { type TFile } from "obsidian";
import {createTFile} from "../../tests/obsidian-stub";

// MetaController and BulkMetadataEditor transitively import Svelte-backed modals
// (and BulkOptionModal extends obsidian's Modal), which the node test environment
Expand Down Expand Up @@ -154,7 +155,7 @@ describe("BulkMetadataEditor serialization through the controller write queue",
const path = "race-order.md";
const harness = makeHarness({ [path]: "---\ntitle: Note\n---\nbody\n" });

const result = await runGatedRace(harness, new TFile(path));
const result = await runGatedRace(harness, createTFile(path));

// The bulk write must NOT have begun while the controller write held the
// queue. Pre-fix (direct processFrontMatter, unqueued) this is true and the
Expand All @@ -168,7 +169,7 @@ describe("BulkMetadataEditor serialization through the controller write queue",
const path = "race-loss.md";
const harness = makeHarness({ [path]: "---\ntitle: Note\n---\nbody\n" });

const result = await runGatedRace(harness, new TFile(path));
const result = await runGatedRace(harness, createTFile(path));

// Both writes survive: the controller's appended inline field AND the bulk
// frontmatter property. Pre-fix the controller's stale snapshot overwrites
Expand All @@ -181,7 +182,7 @@ describe("BulkMetadataEditor serialization through the controller write queue",
it("isolates a failing bulk write and keeps the per-file queue usable for the next write", async () => {
const path = "race-error.md";
const harness = makeHarness({ [path]: "---\ntitle: Note\n---\nbody\n" });
const file = new TFile(path);
const file = createTFile(path);

const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
// The queued bulk write rejects. enqueueFileWrite must still propagate the
Expand Down Expand Up @@ -223,7 +224,7 @@ describe("BulkMetadataEditor reserved-key guard", () => {
for (const key of RESERVED) {
const path = `reserved-apply-${key}.md`;
const harness = makeHarness({ [path]: ORIGINAL });
const file = new TFile(path);
const file = createTFile(path);

// apply() refuses the whole batch once - it rejects rather than returning
// a summary that overstates the refusal as N per-note write failures.
Expand All @@ -243,7 +244,7 @@ describe("BulkMetadataEditor reserved-key guard", () => {
// keep "__proto__" from reaching `frontmatter[key] = ...`.
const path = "reserved-applyToFile.md";
const harness = makeHarness({ [path]: ORIGINAL });
const file = new TFile(path);
const file = createTFile(path);

await expect(
(harness.bulkEditor as any).applyToFile(file, "__proto__", "draft", "skip", false),
Expand All @@ -262,7 +263,7 @@ describe("BulkMetadataEditor reserved-key guard", () => {
(GenericPrompt.Prompt as ReturnType<typeof vi.fn>).mockResolvedValueOnce(" __proto__ ");
const applySpy = vi.spyOn(harness.bulkEditor, "apply");

await harness.bulkEditor.run([new TFile(path)], "Folder");
await harness.bulkEditor.run([createTFile(path)], "Folder");

// Trimmed to "__proto__", refused before the value prompt: apply (and thus
// any added/success summary) is never reached, and the note is untouched.
Expand All @@ -275,7 +276,7 @@ describe("BulkMetadataEditor reserved-key guard", () => {
const path = "reserved-normal-key.md";
const harness = makeHarness({ [path]: ORIGINAL });

const summary = await harness.bulkEditor.apply([new TFile(path)], "status", "draft", "skip");
const summary = await harness.bulkEditor.apply([createTFile(path)], "status", "draft", "skip");

expect(summary.added).toBe(1);
expect(summary.failed).toBe(0);
Expand Down
11 changes: 6 additions & 5 deletions src/metaController.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {beforeEach, describe, expect, it, vi} from "vitest";
import {TFile} from "obsidian";
import {type TFile} from "obsidian";
import {createTFile} from "../tests/obsidian-stub";

// The controller transitively imports Svelte-backed modals, which the node test
// environment cannot transform. The append writer never touches them, so replace the
Expand Down Expand Up @@ -32,7 +33,7 @@ const setup = (initial: string) => {
},
};
const controller = new MetaController(app as never, {} as never);
return {controller, file: new TFile("note.md"), store, app};
return {controller, file: createTFile("note.md"), store, app};
};

const callUpdateMultiple = (controller: MetaController, props: Property[], file: TFile) =>
Expand Down Expand Up @@ -362,7 +363,7 @@ describe("MetaController native YAML property editing", () => {
},
};
const controller = new MetaController(app as never, plugin as never);
return {controller, file: new TFile("note.md"), fm, processFrontMatter, setType};
return {controller, file: createTFile("note.md"), fm, processFrontMatter, setType};
};

beforeEach(() => {
Expand Down Expand Up @@ -562,7 +563,7 @@ describe("MetaController reserved-key guard", () => {
},
};
const controller = new MetaController(app as never, plugin as never);
return {controller, file: new TFile("note.md"), fm, processFrontMatter, vaultModify};
return {controller, file: createTFile("note.md"), fm, processFrontMatter, vaultModify};
};

beforeEach(() => {
Expand Down Expand Up @@ -676,7 +677,7 @@ describe("MetaController.createNativeYamlProperty (fluid creation write path)",
};
const plugin = {settings: {EditMode: {mode, properties: [] as string[]}, AutoProperties: {enabled: false, properties: []}}};
const controller = new MetaController(app as never, plugin as never);
return {controller, file: new TFile("note.md"), fm, processFrontMatter};
return {controller, file: createTFile("note.md"), fm, processFrontMatter};
};

beforeEach(() => {
Expand Down
Loading
Loading