mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-06-10 14:37:40 +01:00
Enable test coverage for playwright tests.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { DataExplorer, TEST_AUTOSCALE_THROUGHPUT_RU, TestAccount, generateUniqueName } from "../fx";
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Custom Playwright fixture that collects Istanbul code coverage after each test.
|
||||
*
|
||||
* When the app is built with COVERAGE=1 (which enables babel-plugin-istanbul),
|
||||
* the bundled code exposes `window.__coverage__`. This fixture grabs that object
|
||||
* after every test and writes it to `.nyc_output/` so `nyc report` can merge and
|
||||
* render a coverage report.
|
||||
*
|
||||
* Usage: In spec files, replace
|
||||
* import { test, expect } from "@playwright/test";
|
||||
* with
|
||||
* import { test, expect } from "../coverage"; // adjust relative path
|
||||
*/
|
||||
import { test as base, Browser, expect, Frame, Locator, Page } from "@playwright/test";
|
||||
import * as crypto from "crypto";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
const nycOutputDir = path.join(__dirname, "..", ".nyc_output");
|
||||
|
||||
/**
|
||||
* Try to pull `window.__coverage__` from every frame in the page.
|
||||
* The app loads inside an iframe in testExplorer.html, so we check
|
||||
* both the main page and all child frames.
|
||||
*/
|
||||
async function collectCoverage(page: Page): Promise<Record<string, unknown> | null> {
|
||||
// Try main frame first
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const cov = await page.evaluate(() => (window as Record<string, any>).__coverage__);
|
||||
if (cov && Object.keys(cov).length > 0) {
|
||||
return cov as Record<string, unknown>;
|
||||
}
|
||||
} catch {
|
||||
// page may have been closed already
|
||||
}
|
||||
|
||||
// Try child frames (the explorer often runs inside an iframe)
|
||||
for (const frame of page.frames()) {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const cov = await frame.evaluate(() => (window as Record<string, any>).__coverage__);
|
||||
if (cov && Object.keys(cov).length > 0) {
|
||||
return cov as Record<string, unknown>;
|
||||
}
|
||||
} catch {
|
||||
// frame may be detached
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
const test = base.extend({
|
||||
page: async ({ page }, use) => {
|
||||
await use(page);
|
||||
|
||||
const coverage = await collectCoverage(page);
|
||||
if (coverage) {
|
||||
fs.mkdirSync(nycOutputDir, { recursive: true });
|
||||
const id = crypto.randomBytes(8).toString("hex");
|
||||
fs.writeFileSync(path.join(nycOutputDir, `coverage-${id}.json`), JSON.stringify(coverage));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export { Browser, expect, Frame, Locator, Page, test };
|
||||
export type { Page as PageType };
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { DataExplorer, TEST_AUTOSCALE_THROUGHPUT_RU, TestAccount, generateUniqueName } from "../fx";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { DataExplorer, TEST_AUTOSCALE_THROUGHPUT_RU, TestAccount, generateUniqueName } from "../fx";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { setupCORSBypass } from "../CORSBypass";
|
||||
import { CommandBarButton, DataExplorer, DocumentsTab, TestAccount } from "../fx";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { setupCORSBypass } from "../CORSBypass";
|
||||
import { DataExplorer, QueryTab, TestAccount, CommandBarButton, Editor } from "../fx";
|
||||
import { expect, test } from "../coverage";
|
||||
import { CommandBarButton, DataExplorer, Editor, QueryTab, TestAccount } from "../fx";
|
||||
import { serializeMongoToJson } from "../testData";
|
||||
|
||||
const databaseId = "test-e2etests-mongo-pagination";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { DataExplorer, TEST_AUTOSCALE_THROUGHPUT_RU, TestAccount, generateUniqueName } from "../fx";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
||||
import { truncateName } from "../../../src/Explorer/ContainerCopy/CopyJobUtils";
|
||||
import { expect, Frame, Locator, Page, test } from "../../coverage";
|
||||
import {
|
||||
ContainerCopy,
|
||||
getAccountName,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
||||
import { expect, Frame, Locator, Page, test } from "../../coverage";
|
||||
import {
|
||||
ContainerCopy,
|
||||
getAccountName,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
||||
import { set } from "lodash";
|
||||
import { expect, Frame, Locator, Page, test } from "../../coverage";
|
||||
import { ContainerCopy, getAccountName, TestAccount } from "../../fx";
|
||||
|
||||
const VISIBLE_TIMEOUT_MS = 30 * 1000;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { existsSync, mkdtempSync, rmdirSync, unlinkSync, writeFileSync } from "fs";
|
||||
import { tmpdir } from "os";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { expect, test, type Page } from "../coverage";
|
||||
|
||||
import { CommandBarButton, DataExplorer, TestAccount } from "../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../testData";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { CommandBarButton, DataExplorer, Editor, QueryTab, TestAccount } from "../fx";
|
||||
import { TestContainerContext, TestItem, createTestSQLContainer } from "../testData";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { CosmosDBManagementClient } from "@azure/arm-cosmosdb";
|
||||
import { CosmosClient, PermissionMode } from "@azure/cosmos";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../../coverage";
|
||||
import { DataExplorer, TestAccount } from "../../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect, Page, test } from "@playwright/test";
|
||||
import * as DataModels from "../../../src/Contracts/DataModels";
|
||||
import { expect, Page, test } from "../../coverage";
|
||||
import { CommandBarButton, DataExplorer, ONE_MINUTE_MS, TestAccount } from "../../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { expect, test, type Page } from "../../coverage";
|
||||
import { DataExplorer, TestAccount } from "../../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Browser, expect, Locator, Page, test } from "@playwright/test";
|
||||
import { Browser, expect, Locator, Page, test } from "../../coverage";
|
||||
import {
|
||||
CommandBarButton,
|
||||
DataExplorer,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../../coverage";
|
||||
import { CommandBarButton, DataExplorer, ONE_MINUTE_MS, TestAccount } from "../../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Locator, expect, test } from "@playwright/test";
|
||||
import { Locator, expect, test } from "../../coverage";
|
||||
import {
|
||||
CommandBarButton,
|
||||
DataExplorer,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../../coverage";
|
||||
import { CommandBarButton, DataExplorer, ONE_MINUTE_MS, TestAccount } from "../../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../../coverage";
|
||||
import { CommandBarButton, DataExplorer, ONE_MINUTE_MS, TestAccount } from "../../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../../coverage";
|
||||
import { CommandBarButton, DataExplorer, ONE_MINUTE_MS, TestAccount } from "../../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
import { DataExplorer, TestAccount } from "../fx";
|
||||
|
||||
test("Self Serve", async ({ page, browserName }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../coverage";
|
||||
|
||||
import { DataExplorer, TEST_AUTOSCALE_THROUGHPUT_RU, TestAccount, generateUniqueName } from "../fx";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user