@empiricalrun/playwright-utils 0.45.1 → 0.45.2

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,11 @@
1
1
  # @empiricalrun/playwright-utils
2
2
 
3
+ ## 0.45.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 62498f5: revert: clear disk space after successful attachments
8
+
3
9
  ## 0.45.1
4
10
 
5
11
  ### Patch Changes
@@ -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;AAsBnC,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,CA0CnC;IAEF,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU;IAwGtC,KAAK,CAAC,MAAM,EAAE,UAAU;IAkG9B,OAAO,CAAC,qBAAqB;YAkBf,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;AAsBnC,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;IAwGtC,KAAK,CAAC,MAAM,EAAE,UAAU;IAkG9B,OAAO,CAAC,qBAAqB;YAkBf,gBAAgB;YAOhB,iBAAiB;CAmChC;AAED,eAAe,iBAAiB,CAAC"}
@@ -40,12 +40,6 @@ class EmpiricalReporter {
40
40
  const destinationPath = `data/${relativePath}`;
41
41
  const publicUrl = await this._uploader.uploadFile(attachment.path, destinationPath);
42
42
  if (publicUrl) {
43
- try {
44
- await fs_1.default.promises.unlink(attachment.path);
45
- }
46
- catch (err) {
47
- logger_1.logger.warn(`[Empirical Reporter] Failed to delete uploaded attachment: ${attachment.path}`, err);
48
- }
49
43
  return { [attachment.path]: publicUrl };
50
44
  }
51
45
  };
@@ -0,0 +1,42 @@
1
+ export interface IBRTestContext {
2
+ tempDir: string;
3
+ blobDir: string;
4
+ zipPath: string;
5
+ }
6
+ export declare function sleep(ms: number): Promise<void>;
7
+ /**
8
+ * Sets up a temp directory with the IBR fixture files.
9
+ * Returns a context object and a cleanup function.
10
+ */
11
+ export declare function setupFixture(suite: string): Promise<{
12
+ ctx: IBRTestContext;
13
+ cleanup: () => Promise<void>;
14
+ }>;
15
+ /**
16
+ * Cleans blob artifacts from a previous run inside the same temp dir.
17
+ */
18
+ export declare function cleanBlobArtifacts(ctx: IBRTestContext): Promise<void>;
19
+ export interface RunResult {
20
+ stdout: string;
21
+ stderr: string;
22
+ }
23
+ export type WaitFor = "first-passed" | "first-failed";
24
+ /**
25
+ * Spawns `playwright test` with the IBR reporter, waits for a test outcome,
26
+ * sends SIGINT, and waits for the process to exit.
27
+ *
28
+ * Returns captured stdout/stderr.
29
+ */
30
+ export declare function runPlaywrightWithSigint(ctx: IBRTestContext, opts: {
31
+ workers: number;
32
+ waitFor: WaitFor;
33
+ }): Promise<RunResult>;
34
+ export interface BlobEvent {
35
+ method: string;
36
+ params?: Record<string, unknown>;
37
+ }
38
+ /**
39
+ * Reads `report.jsonl` from the blob zip and returns parsed events.
40
+ */
41
+ export declare function readBlobEvents(ctx: IBRTestContext): Promise<BlobEvent[]>;
42
+ //# sourceMappingURL=harness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/reporter/harness.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErD;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACzD,GAAG,EAAE,cAAc,CAAC;IACpB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC,CA2BD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAI3E;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,OAAO,GAAG,cAAc,GAAG,cAAc,CAAC;AAOtD;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC1C,OAAO,CAAC,SAAS,CAAC,CA8CpB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,SAAS,EAAE,CAAC,CAUtB"}
@@ -0,0 +1,121 @@
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.sleep = sleep;
7
+ exports.setupFixture = setupFixture;
8
+ exports.cleanBlobArtifacts = cleanBlobArtifacts;
9
+ exports.runPlaywrightWithSigint = runPlaywrightWithSigint;
10
+ exports.readBlobEvents = readBlobEvents;
11
+ const zip_1 = require("@empiricalrun/r2-uploader/zip");
12
+ const child_process_1 = require("child_process");
13
+ const fs_1 = __importDefault(require("fs"));
14
+ const os_1 = __importDefault(require("os"));
15
+ const path_1 = __importDefault(require("path"));
16
+ const TEST_DATA_DIR = path_1.default.resolve(__dirname, "../../test-data");
17
+ const REPORTER_PATH = path_1.default.resolve(__dirname, "../../dist/reporter/incremental-blob-reporter.js");
18
+ const PLAYWRIGHT_BIN = path_1.default.resolve(__dirname, "../../node_modules/.bin/playwright");
19
+ async function sleep(ms) {
20
+ return new Promise((resolve) => setTimeout(resolve, ms));
21
+ }
22
+ /**
23
+ * Sets up a temp directory with the IBR fixture files.
24
+ * Returns a context object and a cleanup function.
25
+ */
26
+ async function setupFixture(suite) {
27
+ const fixtureDir = path_1.default.join(TEST_DATA_DIR, suite);
28
+ const tempDir = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), "incr-blob-test-"));
29
+ const files = await fs_1.default.promises.readdir(fixtureDir);
30
+ for (const file of files) {
31
+ const src = path_1.default.join(fixtureDir, file);
32
+ const dest = path_1.default.join(tempDir, file);
33
+ if (file === "playwright.config.ts") {
34
+ const content = await fs_1.default.promises.readFile(src, "utf8");
35
+ await fs_1.default.promises.writeFile(dest, content.replace("__REPORTER_PATH__", REPORTER_PATH));
36
+ }
37
+ else {
38
+ await fs_1.default.promises.copyFile(src, dest);
39
+ }
40
+ }
41
+ const blobDir = path_1.default.join(tempDir, "blob-report-incremental");
42
+ const zipPath = path_1.default.join(blobDir, "incremental-report-1.zip");
43
+ return {
44
+ ctx: { tempDir, blobDir, zipPath },
45
+ cleanup: () => fs_1.default.promises.rm(tempDir, { recursive: true, force: true }),
46
+ };
47
+ }
48
+ /**
49
+ * Cleans blob artifacts from a previous run inside the same temp dir.
50
+ */
51
+ async function cleanBlobArtifacts(ctx) {
52
+ if (fs_1.default.existsSync(ctx.blobDir)) {
53
+ await fs_1.default.promises.rm(ctx.blobDir, { recursive: true, force: true });
54
+ }
55
+ }
56
+ const WAIT_FOR_PATTERNS = {
57
+ "first-passed": /passed|✓/,
58
+ "first-failed": /failed|✘|×/,
59
+ };
60
+ /**
61
+ * Spawns `playwright test` with the IBR reporter, waits for a test outcome,
62
+ * sends SIGINT, and waits for the process to exit.
63
+ *
64
+ * Returns captured stdout/stderr.
65
+ */
66
+ async function runPlaywrightWithSigint(ctx, opts) {
67
+ const { workers, waitFor } = opts;
68
+ const pattern = WAIT_FOR_PATTERNS[waitFor];
69
+ const child = (0, child_process_1.spawn)(PLAYWRIGHT_BIN, ["test", `--workers=${workers}`], {
70
+ cwd: ctx.tempDir,
71
+ env: {
72
+ ...process.env,
73
+ LOCAL_TEST: "false",
74
+ SHARD_INDEX: "1",
75
+ TOTAL_SHARDS: "1",
76
+ },
77
+ stdio: ["pipe", "pipe", "pipe"],
78
+ });
79
+ let stdout = "";
80
+ let stderr = "";
81
+ child.stdout?.on("data", (data) => {
82
+ stdout += data.toString();
83
+ });
84
+ child.stderr?.on("data", (data) => {
85
+ stderr += data.toString();
86
+ });
87
+ // Wait for at least one test to complete before sending SIGINT
88
+ await new Promise((resolve) => {
89
+ const checkInterval = setInterval(() => {
90
+ if (pattern.test(stdout)) {
91
+ clearInterval(checkInterval);
92
+ resolve(true);
93
+ }
94
+ }, 200);
95
+ setTimeout(() => {
96
+ clearInterval(checkInterval);
97
+ resolve(false);
98
+ }, 30_000);
99
+ });
100
+ // Waiting for 1 sec to ensure second test has started
101
+ await sleep(1_000);
102
+ child.kill("SIGINT");
103
+ await new Promise((resolve) => {
104
+ child.on("close", () => resolve());
105
+ });
106
+ return { stdout, stderr };
107
+ }
108
+ /**
109
+ * Reads `report.jsonl` from the blob zip and returns parsed events.
110
+ */
111
+ async function readBlobEvents(ctx) {
112
+ const reportBuffer = await (0, zip_1.readZipEntry)(ctx.zipPath, "report.jsonl");
113
+ if (!reportBuffer) {
114
+ throw new Error(`report.jsonl not found in zip: ${ctx.zipPath}`);
115
+ }
116
+ return reportBuffer
117
+ .toString("utf8")
118
+ .trim()
119
+ .split("\n")
120
+ .map((line) => JSON.parse(line));
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/playwright-utils",
3
- "version": "0.45.1",
3
+ "version": "0.45.2",
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/local-test.ts","./src/reporter/reporter-state.ts","./src/reporter/uploader.ts","./src/reporter/util.ts","./src/reporter/IBR-unit-test/example.spec.ts","./src/reporter/IBR-unit-test/playwright.config.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"}
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/harness.ts","./src/reporter/incremental-blob-reporter.ts","./src/reporter/local-test.ts","./src/reporter/reporter-state.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"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=example.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"example.spec.d.ts","sourceRoot":"","sources":["../../../src/reporter/IBR-unit-test/example.spec.ts"],"names":[],"mappings":""}
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const test_1 = require("@playwright/test");
4
- (0, test_1.test)("fast test", async () => {
5
- (0, test_1.expect)(1 + 1).toBe(2);
6
- });
7
- (0, test_1.test)("slow test 1", async () => {
8
- await new Promise((r) => setTimeout(r, 20000));
9
- (0, test_1.expect)(true).toBe(true);
10
- });
11
- (0, test_1.test)("slow test 2", async () => {
12
- await new Promise((r) => setTimeout(r, 20000));
13
- (0, test_1.expect)(true).toBe(true);
14
- });
@@ -1,3 +0,0 @@
1
- declare const _default: import("@playwright/test").PlaywrightTestConfig<{}, {}>;
2
- export default _default;
3
- //# sourceMappingURL=playwright.config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"playwright.config.d.ts","sourceRoot":"","sources":["../../../src/reporter/IBR-unit-test/playwright.config.ts"],"names":[],"mappings":";AAEA,wBAIG"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const test_1 = require("@playwright/test");
4
- exports.default = (0, test_1.defineConfig)({
5
- reporter: [["__REPORTER_PATH__"], ["list"]],
6
- testDir: ".",
7
- timeout: 30000,
8
- });