diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index c68d873..86d9a80 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/packages/obsidian-testing-framework/package.json b/packages/obsidian-testing-framework/package.json index 48323f5..948a89d 100644 --- a/packages/obsidian-testing-framework/package.json +++ b/packages/obsidian-testing-framework/package.json @@ -19,7 +19,7 @@ "../../README.md" ], "readme": "", - "version": "0.0.3", + "version": "0.0.4", "exports": { ".": { "types": "./lib/index.d.ts", diff --git a/packages/obsidian-testing-framework/src/util.ts b/packages/obsidian-testing-framework/src/util.ts index 83a8b25..d8d661a 100644 --- a/packages/obsidian-testing-framework/src/util.ts +++ b/packages/obsidian-testing-framework/src/util.ts @@ -53,10 +53,10 @@ export async function assertLineEquals( * * @export * @param {Page} page - a Playwright page - * @param {string} path the file to check + * @param {string} path - the file to check * @param {number} start - the start of the desired line range (0-based) * @param {number} end - the end of the desired line range (1-based) - * @param {string} expected the expected content + * @param {string} expected - the expected content * @param {boolean} [cached=true] - whether to use `app.vault.cachedRead` */ export async function assertLinesEqual( @@ -81,6 +81,23 @@ const getFile = (file: string): TFile => { return f; } +/** + * asserts all lines in the given range match a regex. + * + * @export + * @param {Page} page - a Playwright page + * @param {string} path - the file to check + * @param {number} start - the start of the desired line range (0-based) + * @param {number} end - the end of the desired line range (1-based) + * @param {RegExp} regex - the regex to test against + * @param {boolean} [cached=true] - whether to use `app.vault.cachedRead` + */ +export async function assertLinesMatch(page: Page, path: string, start: number, end: number, regex: RegExp, cached: boolean = true) { + const fileContent = await readFile(page, path, cached); + const lines = fileContent.split("\n").slice(start, end); + expect(lines.every(l => regex.test(l))).toEqual(true); +} + /** * reads the file at `path` and returns its contents * @@ -88,7 +105,7 @@ const getFile = (file: string): TFile => { * @param {Page} page - a Playwright page * @param {string} path the file to read * @param {boolean} [cached=true] - whether to use `app.vault.cachedRead` - * @return {*} {Promise} the file's contents + * @return {Promise} the file's contents */ export async function readFile( page: Page, @@ -115,7 +132,7 @@ export async function readFile( * @param {Page} page - a Playwright page * @param {((a: App, args?: A) => T | Promise)} callback - the function to execute * @param {A} [args] - optional arguments to pass to the callback - * @return {*} {Promise} a promise containing `callback`'s return value (if any) + * @return {Promise} a promise containing `callback`'s return value (if any) */ export async function doWithApp( page: Page,