From b4a673bb24f33894f2c847fd539e63e13ff641c5 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 31 Oct 2022 16:27:20 -0700 Subject: [PATCH 1/2] feat: add test for markdown webview --- test/e2e/webview.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/e2e/webview.test.ts diff --git a/test/e2e/webview.test.ts b/test/e2e/webview.test.ts new file mode 100644 index 000000000000..4705761e4bec --- /dev/null +++ b/test/e2e/webview.test.ts @@ -0,0 +1,30 @@ +import { promises as fs } from "fs" +import * as path from "path" +import { describe, test, expect } from "./baseFixture" + +describe("Webviews", ["--disable-workspace-trust"], {}, () => { + test("should preview a Markdown file", async ({ codeServerPage }) => { + // Create Markdown file + const heading = "Hello world" + const dir = await codeServerPage.workspaceDir + const file = path.join(dir, "text.md") + await fs.writeFile(file, `# ${heading}`) + await codeServerPage.openFile(file) + + // Open Preview + await codeServerPage.executeCommandViaMenus("Markdown: Open Preview to the Side") + // Wait for the iframe to open and load + await codeServerPage.page.waitForTimeout(2000) + await codeServerPage.waitForTab(`Preview ${file}`) + + let totalCount = 0 + for (const frame of codeServerPage.page.frames()) { + // Check for heading in frames + const count = await frame.locator(`text=${heading}`).count() + totalCount += count + } + + // One in the file and one in the preview + expect(totalCount).toBe(2) + }) +}) From 646868261a6b5499f1de64abb89b0ec22f44f1df Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 3 Nov 2022 10:28:32 -0700 Subject: [PATCH 2/2] fixup!: use frameLocator --- test/e2e/webview.test.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/e2e/webview.test.ts b/test/e2e/webview.test.ts index 4705761e4bec..fb6d88667089 100644 --- a/test/e2e/webview.test.ts +++ b/test/e2e/webview.test.ts @@ -14,17 +14,15 @@ describe("Webviews", ["--disable-workspace-trust"], {}, () => { // Open Preview await codeServerPage.executeCommandViaMenus("Markdown: Open Preview to the Side") // Wait for the iframe to open and load - await codeServerPage.page.waitForTimeout(2000) await codeServerPage.waitForTab(`Preview ${file}`) - let totalCount = 0 - for (const frame of codeServerPage.page.frames()) { - // Check for heading in frames - const count = await frame.locator(`text=${heading}`).count() - totalCount += count - } + // It's an iframe within an iframe + // so we have to do .frameLocator twice + const renderedText = await codeServerPage.page + .frameLocator("iframe.webview.ready") + .frameLocator("#active-frame") + .locator("text=Hello world") - // One in the file and one in the preview - expect(totalCount).toBe(2) + expect(renderedText).toBeVisible }) })