(options: {
templateContent: string;
noteContent: string;
frontmatter?: Record<string, unknown>;
rootFolders?: string[];
})
| 127 | } |
| 128 | |
| 129 | function makeHarness(options: { |
| 130 | templateContent: string; |
| 131 | noteContent: string; |
| 132 | frontmatter?: Record<string, unknown>; |
| 133 | rootFolders?: string[]; |
| 134 | }): TestHarness { |
| 135 | const templateFile = makeFile({ |
| 136 | path: TEMPLATE_PATH, |
| 137 | basename: "tpl", |
| 138 | }); |
| 139 | |
| 140 | const modify = vi.fn(); |
| 141 | const frontmatter = options.frontmatter ?? {}; |
| 142 | const replaceSelection = vi.fn(); |
| 143 | let activeViewFile: TFile | null = null; |
| 144 | |
| 145 | const rootFolders = new Map( |
| 146 | (options.rootFolders ?? []).map((path) => { |
| 147 | const folder = new TFolder(); |
| 148 | folder.path = path; |
| 149 | return [path, folder]; |
| 150 | }), |
| 151 | ); |
| 152 | |
| 153 | const app = { |
| 154 | vault: { |
| 155 | getAbstractFileByPath: (path: string) => |
| 156 | path === TEMPLATE_PATH |
| 157 | ? templateFile |
| 158 | : (rootFolders.get(path) ?? null), |
| 159 | cachedRead: async (file: TFile) => |
| 160 | file.path === TEMPLATE_PATH |
| 161 | ? options.templateContent |
| 162 | : options.noteContent, |
| 163 | modify, |
| 164 | // Mirror Obsidian's atomic read-modify-write: read current content, |
| 165 | // apply the transform, then write via the same `modify` spy so existing |
| 166 | // modify-call assertions continue to hold. |
| 167 | process: async (file: TFile, fn: (data: string) => string) => { |
| 168 | const data = |
| 169 | file.path === TEMPLATE_PATH |
| 170 | ? options.templateContent |
| 171 | : options.noteContent; |
| 172 | const next = fn(data); |
| 173 | modify(file, next); |
| 174 | return next; |
| 175 | }, |
| 176 | }, |
| 177 | fileManager: { |
| 178 | processFrontMatter: async ( |
| 179 | _file: TFile, |
| 180 | fn: (fm: Record<string, unknown>) => void, |
| 181 | ) => { |
| 182 | fn(frontmatter); |
| 183 | }, |
| 184 | }, |
| 185 | workspace: { |
| 186 | getActiveViewOfType: () => |
no test coverage detected