MCPcopy Create free account
hub / github.com/chhoumann/quickadd / makeHarness

Function makeHarness

src/engine/TemplateInsertEngine.test.ts:129–202  ·  view source on GitHub ↗
(options: {
	templateContent: string;
	noteContent: string;
	frontmatter?: Record<string, unknown>;
	rootFolders?: string[];
})

Source from the content-addressed store, hash-verified

127}
128
129function 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: () =>

Callers 2

makePathHarnessFunction · 0.85

Calls 3

fnMethod · 0.80
makeFileFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected