@empiricalrun/playwright-utils 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @empiricalrun/playwright-utils
2
2
 
3
+ ## 0.43.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ab403b8: fix: move json report location to avoid accidental agent commits
8
+
9
+ ### Patch Changes
10
+
11
+ - 002127f: feat: add code coverage helper in base fixtures
12
+
3
13
  ## 0.42.0
4
14
 
5
15
  ### Minor Changes
@@ -51,7 +51,7 @@ function getReporters() {
51
51
  ],
52
52
  ]
53
53
  : [
54
- ["json", { outputFile: "summary.json" }],
54
+ ["json", { outputFile: "playwright-report/summary.json" }],
55
55
  ["html", { open: "never" }],
56
56
  ];
57
57
  return [
@@ -1 +1 @@
1
- {"version":3,"file":"empirical-reporter.d.ts","sourceRoot":"","sources":["../../src/reporter/empirical-reporter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,EACX,MAAM,2BAA2B,CAAC;AAqBnC,cAAM,iBAAkB,YAAW,QAAQ;IACzC,OAAO,CAAC,kBAAkB,CAAyB;IACnD,OAAO,CAAC,oBAAoB,CAG1B;IACF,OAAO,CAAC,sBAAsB,CAAuB;IACrD,OAAO,CAAC,YAAY,CAAgD;IACpE,OAAO,CAAC,iBAAiB,CAAyC;IAClE,OAAO,CAAC,gBAAgB,CAAkC;IAC1D,OAAO,CAAC,SAAS,CAAyB;;IAM1C,OAAO,CAAC,6BAA6B,CAkCnC;IAEF,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU;IAuGtC,KAAK,CAAC,MAAM,EAAE,UAAU;IA8G9B,OAAO,CAAC,gBAAgB;YAoBV,gBAAgB;YAOhB,iBAAiB;CAmChC;AAED,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"empirical-reporter.d.ts","sourceRoot":"","sources":["../../src/reporter/empirical-reporter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,EACX,MAAM,2BAA2B,CAAC;AAqBnC,cAAM,iBAAkB,YAAW,QAAQ;IACzC,OAAO,CAAC,kBAAkB,CAAyB;IACnD,OAAO,CAAC,oBAAoB,CAG1B;IACF,OAAO,CAAC,sBAAsB,CAAuB;IACrD,OAAO,CAAC,YAAY,CAAgD;IACpE,OAAO,CAAC,iBAAiB,CAAyC;IAClE,OAAO,CAAC,gBAAgB,CAAkC;IAC1D,OAAO,CAAC,SAAS,CAAyB;;IAM1C,OAAO,CAAC,6BAA6B,CAkCnC;IAEF,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU;IAuGtC,KAAK,CAAC,MAAM,EAAE,UAAU;IAkH9B,OAAO,CAAC,gBAAgB;YAoBV,gBAAgB;YAOhB,iBAAiB;CAmChC;AAED,eAAe,iBAAiB,CAAC"}
@@ -134,7 +134,7 @@ class EmpiricalReporter {
134
134
  minute: "2-digit",
135
135
  second: "2-digit",
136
136
  }).format(startTime));
137
- const jsonFilePath = path_1.default.join(this._currentWorkingDir, "summary.json");
137
+ const jsonFilePath = path_1.default.join(this._currentWorkingDir, "playwright-report", "summary.json");
138
138
  const jsonExists = fs_1.default.existsSync(jsonFilePath);
139
139
  const htmlFilePath = path_1.default.join(this._currentWorkingDir, "playwright-report/index.html");
140
140
  const htmlExists = await (0, util_1.checkFileExistsAsync)(htmlFilePath);
@@ -0,0 +1,9 @@
1
+ import type { BrowserContext } from "@playwright/test";
2
+ export declare function setupCoverageCollection(context: BrowserContext): Promise<string[]>;
3
+ export declare function collectAndAttachCoverage(context: BrowserContext, coverageFiles: string[], testInfo: {
4
+ attach: (name: string, options: {
5
+ path: string;
6
+ contentType: string;
7
+ }) => Promise<void>;
8
+ }): Promise<void>;
9
+ //# sourceMappingURL=coverage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/test/coverage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAYvD,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,cAAc,qBAwBpE;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,cAAc,EACvB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,EAAE;IACR,MAAM,EAAE,CACN,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,KAC3C,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,iBAqBF"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setupCoverageCollection = setupCoverageCollection;
7
+ exports.collectAndAttachCoverage = collectAndAttachCoverage;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const istanbulCLIOutput = path_1.default.join(process.cwd(), ".nyc_output");
11
+ function generateCoverageFilename() {
12
+ const timestamp = Date.now();
13
+ const random = Math.random().toString(36).substring(2, 8);
14
+ return `coverage_${timestamp}_${random}.json`;
15
+ }
16
+ async function setupCoverageCollection(context) {
17
+ const coverageFiles = [];
18
+ await context.addInitScript(() => window.addEventListener("beforeunload", () => window.collectIstanbulCoverage(JSON.stringify(window.__coverage__))));
19
+ await fs_1.default.promises.mkdir(istanbulCLIOutput, { recursive: true });
20
+ await context.exposeFunction("collectIstanbulCoverage", (coverageJSON) => {
21
+ if (coverageJSON) {
22
+ const filepath = path_1.default.join(istanbulCLIOutput, generateCoverageFilename());
23
+ fs_1.default.writeFileSync(filepath, coverageJSON);
24
+ coverageFiles.push(filepath);
25
+ }
26
+ });
27
+ return coverageFiles;
28
+ }
29
+ async function collectAndAttachCoverage(context, coverageFiles, testInfo) {
30
+ for (const page of context.pages()) {
31
+ try {
32
+ await page.evaluate(() => window.collectIstanbulCoverage(JSON.stringify(window.__coverage__)));
33
+ }
34
+ catch {
35
+ // Page might be closed or coverage not available
36
+ }
37
+ }
38
+ for (const filepath of coverageFiles) {
39
+ if (fs_1.default.existsSync(filepath)) {
40
+ await testInfo.attach(path_1.default.basename(filepath), {
41
+ path: filepath,
42
+ contentType: "application/json",
43
+ });
44
+ }
45
+ }
46
+ }
@@ -3,7 +3,7 @@ import { KVClient } from "../kv";
3
3
  import { PostgresClient } from "../postgres";
4
4
  import { type WebhookMatcherOptions } from "./expect";
5
5
  import { injectLocatorHighlightScripts } from "./scripts";
6
- import { HighlighterOpts } from "./types";
6
+ import { type BaseTestFixtureOpts } from "./types";
7
7
  import { setVideoLabel } from "./video-labels";
8
8
  declare global {
9
9
  namespace PlaywrightTest {
@@ -24,6 +24,6 @@ type TestOptions = {
24
24
  }>;
25
25
  saveVideos: void;
26
26
  };
27
- declare const baseTestFixture: (testFn: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options?: HighlighterOpts) => TestType<PlaywrightTestArgs & PlaywrightTestOptions & TestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
27
+ declare const baseTestFixture: (testFn: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options?: BaseTestFixtureOpts) => TestType<PlaywrightTestArgs & PlaywrightTestOptions & TestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
28
28
  export { baseTestFixture, extendExpect, injectLocatorHighlightScripts, setVideoLabel, };
29
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"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IAAI,CAAC;CAClB,CAAC;AAYF,QAAA,MAAM,eAAe,GACnB,QAAQ,QAAQ,CACd,kBAAkB,GAAG,qBAAqB,EAC1C,oBAAoB,GAAG,uBAAuB,CAC/C,EACD,UAAS,mBAAoC,uHAqH9C,CAAC;AAEF,OAAO,EACL,eAAe,EACf,YAAY,EACZ,6BAA6B,EAC7B,aAAa,GACd,CAAC"}
@@ -7,6 +7,7 @@ exports.setVideoLabel = exports.injectLocatorHighlightScripts = exports.extendEx
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const kv_1 = require("../kv");
9
9
  const postgres_1 = require("../postgres");
10
+ const coverage_1 = require("./coverage");
10
11
  const expect_1 = require("./expect");
11
12
  const scripts_1 = require("./scripts");
12
13
  Object.defineProperty(exports, "injectLocatorHighlightScripts", { enumerable: true, get: function () { return scripts_1.injectLocatorHighlightScripts; } });
@@ -26,6 +27,7 @@ const defaultOptions = {
26
27
  agentCapabilities: true,
27
28
  };
28
29
  const baseTestFixture = function (testFn, options = defaultOptions) {
30
+ const coverageEnabled = options.collectCoverage ?? false;
29
31
  const extendedTestFn = testFn.extend({
30
32
  context: async ({ browser }, use, testInfo) => {
31
33
  const context = await browser.newContext({
@@ -36,7 +38,14 @@ const baseTestFixture = function (testFn, options = defaultOptions) {
36
38
  });
37
39
  const pages = [];
38
40
  context.on("page", (page) => pages.push(page));
41
+ let coverageFiles = [];
42
+ if (coverageEnabled) {
43
+ coverageFiles = await (0, coverage_1.setupCoverageCollection)(context);
44
+ }
39
45
  await use(context);
46
+ if (coverageEnabled) {
47
+ await (0, coverage_1.collectAndAttachCoverage)(context, coverageFiles, testInfo);
48
+ }
40
49
  if (!testPages.has(testInfo.testId)) {
41
50
  testPages.set(testInfo.testId, []);
42
51
  }
@@ -4,4 +4,7 @@ export type HighlighterOpts = {
4
4
  visionMethods?: boolean;
5
5
  agentCapabilities?: boolean;
6
6
  };
7
+ export type BaseTestFixtureOpts = HighlighterOpts & {
8
+ collectCoverage?: boolean;
9
+ };
7
10
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/test/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/test/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IAClD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/playwright-utils",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -1 +1 @@
1
- {"root":["./src/email.ts","./src/index.ts","./src/kv.ts","./src/logger.ts","./src/mailosaur-client.ts","./src/playwright-extensions.ts","./src/postgres.ts","./src/telemetry.ts","./src/webhook.ts","./src/auth/google.ts","./src/auth/index.ts","./src/auth/types.ts","./src/captcha/index.ts","./src/config/index.ts","./src/config/proxy.ts","./src/config/devices/types.ts","./src/overlay-tests/cache.spec.ts","./src/overlay-tests/click.spec.ts","./src/overlay-tests/fixtures.ts","./src/overlay-tests/patch.spec.ts","./src/reporter/blob-utils.ts","./src/reporter/empirical-reporter.ts","./src/reporter/failing-line.ts","./src/reporter/incremental-blob-reporter.ts","./src/reporter/uploader.ts","./src/reporter/util.ts","./src/test/constants.ts","./src/test/index.ts","./src/test/types.ts","./src/test/video-labels.ts","./src/test/expect/index.ts","./src/test/expect/types.ts","./src/test/expect/visual.ts","./src/test/expect/webhook.ts","./src/test/scripts/agent-capabilities.ts","./src/test/scripts/index.ts","./src/test/scripts/locator-highlights.ts","./src/test/scripts/locator-vision.ts","./src/test/scripts/mouse-pointer.ts","./src/test/scripts/types.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/cache.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/index.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/prompt.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/types.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/utils.ts","./src/test/scripts/pw-locator-patch/highlight/click.ts","./src/test/scripts/pw-locator-patch/highlight/expect.ts","./src/test/scripts/pw-locator-patch/highlight/hover.ts","./src/test/scripts/pw-locator-patch/highlight/inner-text.ts","./src/test/scripts/pw-locator-patch/highlight/input-value.ts","./src/test/scripts/pw-locator-patch/highlight/is-checked.ts","./src/test/scripts/pw-locator-patch/highlight/is-disabled.ts","./src/test/scripts/pw-locator-patch/highlight/is-editable.ts","./src/test/scripts/pw-locator-patch/highlight/text-content.ts","./src/test/scripts/pw-locator-patch/utils/index.ts","./src/test/scripts/pw-locator-patch/vision/query.ts"],"version":"5.8.3"}
1
+ {"root":["./src/email.ts","./src/index.ts","./src/kv.ts","./src/logger.ts","./src/mailosaur-client.ts","./src/playwright-extensions.ts","./src/postgres.ts","./src/telemetry.ts","./src/webhook.ts","./src/auth/google.ts","./src/auth/index.ts","./src/auth/types.ts","./src/captcha/index.ts","./src/config/index.ts","./src/config/proxy.ts","./src/config/devices/types.ts","./src/overlay-tests/cache.spec.ts","./src/overlay-tests/click.spec.ts","./src/overlay-tests/fixtures.ts","./src/overlay-tests/patch.spec.ts","./src/reporter/blob-utils.ts","./src/reporter/empirical-reporter.ts","./src/reporter/failing-line.ts","./src/reporter/incremental-blob-reporter.ts","./src/reporter/uploader.ts","./src/reporter/util.ts","./src/test/constants.ts","./src/test/coverage.ts","./src/test/index.ts","./src/test/types.ts","./src/test/video-labels.ts","./src/test/expect/index.ts","./src/test/expect/types.ts","./src/test/expect/visual.ts","./src/test/expect/webhook.ts","./src/test/scripts/agent-capabilities.ts","./src/test/scripts/index.ts","./src/test/scripts/locator-highlights.ts","./src/test/scripts/locator-vision.ts","./src/test/scripts/mouse-pointer.ts","./src/test/scripts/types.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/cache.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/index.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/prompt.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/types.ts","./src/test/scripts/pw-locator-patch/dismiss-overlays/utils.ts","./src/test/scripts/pw-locator-patch/highlight/click.ts","./src/test/scripts/pw-locator-patch/highlight/expect.ts","./src/test/scripts/pw-locator-patch/highlight/hover.ts","./src/test/scripts/pw-locator-patch/highlight/inner-text.ts","./src/test/scripts/pw-locator-patch/highlight/input-value.ts","./src/test/scripts/pw-locator-patch/highlight/is-checked.ts","./src/test/scripts/pw-locator-patch/highlight/is-disabled.ts","./src/test/scripts/pw-locator-patch/highlight/is-editable.ts","./src/test/scripts/pw-locator-patch/highlight/text-content.ts","./src/test/scripts/pw-locator-patch/utils/index.ts","./src/test/scripts/pw-locator-patch/vision/query.ts"],"version":"5.8.3"}