Skip to content

Commit

Permalink
fixing lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fungairino committed Apr 27, 2024
1 parent e4dc7e3 commit 0c94e51
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ module.exports = {
allowConditional: true,
},
],
"playwright/no-wait-for-timeout": "error",
"playwright/no-useless-not": "error",
"playwright/expect-expect": [
"error",
{ assertFunctionNames: ["checkUnavailibilityForNavigationMethod"] },
],
"playwright/no-conditional-in-test": "error",
"playwright/no-conditional-expect": "error",
"playwright/no-commented-out-tests": "error",
"playwright/no-hooks": "error", // Use fixtures instead to share common setup / teardown code
"playwright/no-get-by-title": "error",
Expand Down
1 change: 1 addition & 0 deletions end-to-end-tests/fixtures/envSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const test = base.extend<{
assertRequiredEnvVariables();

for (const key of additionalRequiredEnvVariables) {
// eslint-disable-next-line security/detect-object-injection -- internally controlled
if (process.env[key] === undefined) {
throw new Error(
`This test requires additional environment variable ${key} to be configured. Configure it in your .env.development file and re-build the extension.`,
Expand Down
2 changes: 1 addition & 1 deletion end-to-end-tests/tests/runtime/sidebarController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test.describe("sidebar controller", () => {

// The focus dialog should not be shown in the iframe. Check after checking the top-level frame
// because it's a positive check for the dialog being shown.
await expect(frame.getByRole("button", { name: "OK" })).not.toBeVisible();
await expect(frame.getByRole("button", { name: "OK" })).toBeHidden();

// Will error if page/frame not available
await getSidebarPage(page, extensionId);
Expand Down
2 changes: 1 addition & 1 deletion end-to-end-tests/tests/runtime/sidebarNavigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function checkUnavailibilityForNavigationMethod(

// Click on "contentEditable" header, which updates the url to .../#contenteditable
await page.getByRole("link", { name: "contentEditable" }).click();
expect(page.url()).toEqual(
expect(page.url()).toBe(
"https://pbx.vercel.app/advanced-fields/#contenteditable",
);
// Should not cause the temporary panel to become unavailable
Expand Down
61 changes: 35 additions & 26 deletions end-to-end-tests/tests/telemetry/errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import { test, expect } from "../../fixtures/extensionBase";
import { type Request } from "playwright-core";
// @ts-expect-error -- https://youtrack.jetbrains.com/issue/AQUA-711/Provide-a-run-configuration-for-Playwright-tests-in-specs-with-fixture-imports-only
import { type Page, test as base } from "@playwright/test";
import { type BrowserContext, type Page, test as base } from "@playwright/test";
import { getBaseExtensionConsoleUrl } from "../../pageObjects/constants";
import { MV } from "../../env";

async function waitForBackgroundPageRequest(
context: BrowserContext,
extensionId: string,
errorServiceEndpoint: string,
) {
if (MV === "3") {
// Due to service worker limitations with the Datadog SDK, we need to report errors via an offscreen document
// (see https://github.com/pixiebrix/pixiebrix-extension/issues/8268). The offscreen document is created when
// the first error is reported, so we need to wait for it to be created before we can interact with it.
let offscreenPage: Page | undefined;
await expect(async () => {
offscreenPage = context
.pages()
.find((value) =>
value
.url()
.startsWith(`chrome-extension://${extensionId}/offscreen.html`),
);

expect(offscreenPage?.url()).toBeDefined();
}).toPass({ timeout: 5000 });
return offscreenPage?.waitForRequest(errorServiceEndpoint);
}

const backgroundPage = context.backgroundPages()[0];
return backgroundPage?.waitForRequest(errorServiceEndpoint);
}

test.use({
additionalRequiredEnvVariables: [
"DATADOG_CLIENT_TOKEN",
Expand Down Expand Up @@ -39,32 +66,14 @@ test("can report application error to telemetry service", async ({
await page.goto(getBaseExtensionConsoleUrl(extensionId));
await expect(page.getByText("Something went wrong.")).toBeVisible();

let waitForRequest: Promise<Request> | undefined;
if (MV === "3") {
// Due to service worker limitations with the Datadog SDK, we need to report errors via an offscreen document
// (see https://github.com/pixiebrix/pixiebrix-extension/issues/8268). The offscreen document is created when
// the first error is reported, so we need to wait for it to be created before we can interact with it.
let offscreenPage: Page | undefined;
await expect(async () => {
offscreenPage = context
.pages()
.find((value) =>
value
.url()
.startsWith(`chrome-extension://${extensionId}/offscreen.html`),
);

expect(offscreenPage?.url()).toBeDefined();
}).toPass({ timeout: 5000 });
waitForRequest = offscreenPage?.waitForRequest(errorServiceEndpoint);
} else {
const backgroundPage = context.backgroundPages()[0];
waitForRequest = backgroundPage?.waitForRequest(errorServiceEndpoint);
}

// TODO: due to Datadog SDK implementation, it will take ~30 seconds for the
// request to be sent. We should figure out a way to induce the request to be sent sooner.
const request = await waitForRequest;
const request = await waitForBackgroundPageRequest(
context,
extensionId,
errorServiceEndpoint,
);

const errorLogsJson = request
?.postData()
?.split("\n")
Expand Down
12 changes: 6 additions & 6 deletions end-to-end-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export async function runModViaQuickBar(page: Page, modName: string) {
await page.locator("html").focus(); // Ensure the page is focused before running the keyboard shortcut
await page.keyboard.press("Meta+M"); // MacOS
await page.keyboard.press("Control+M"); // Windows and Linux
// Short delay to allow the quickbar to finish loading - TODO: Find a better way to detect when the quickbar is done loading opening
// Short delay to allow the quickbar to finish opening
// eslint-disable-next-line playwright/no-wait-for-timeout -- TODO: Find a better way to detect when the quickbar is done loading opening
await page.waitForTimeout(500);
await page.getByRole("option", { name: modName }).click();
}
Expand Down Expand Up @@ -164,12 +165,11 @@ export async function waitForSelectionMenuReadiness(page: Page) {
}

// Waits for the quick bar to be ready to use
export async function waitForQuickBarReadiness(page: Page) {
async function waitForQuickBarReadiness(page: Page) {
await expect(async () => {
const pbReady = await page
.locator("html")
.getAttribute("data-pb-quick-bar-ready");
expect(pbReady).toBeTruthy();
await expect(page.locator("html")).toHaveAttribute(
"data-pb-quick-bar-ready",
);
}).toPass({ timeout: 5000 });
}

Expand Down

0 comments on commit 0c94e51

Please sign in to comment.