@fixsense/cypress-plugin 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CopilotMe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # @fixsense/cypress-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A Cypress plugin that records what each test did, run after run.
4
+
5
+ Cypress knows a test was retried inside the run it is executing and forgets it
6
+ on exit. This plugin keeps that history, which is what makes a flaky test
7
+ identifiable as flaky rather than as bad luck.
8
+
9
+ Free and MIT licensed. It works on its own; FixSense's paid analysis and
10
+ auto-fix build on the same data.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install -D @fixsense/cypress-plugin
16
+ ```
17
+
18
+ ```ts
19
+ // cypress.config.ts
20
+ import { defineConfig } from 'cypress';
21
+ import { registerFixSense } from '@fixsense/cypress-plugin';
22
+
23
+ export default defineConfig({
24
+ // Retries are what let Cypress distinguish a flaky test from a failing one.
25
+ retries: { runMode: 2, openMode: 0 },
26
+ e2e: {
27
+ setupNodeEvents(on, config) {
28
+ registerFixSense(on);
29
+ return config;
30
+ },
31
+ },
32
+ });
33
+ ```
34
+
35
+ Set `FIXSENSE_API_KEY` in CI. Without it the plugin does nothing, so local
36
+ runs are unaffected.
37
+
38
+ ## Options
39
+
40
+ ```ts
41
+ registerFixSense(on, {
42
+ apiKey: process.env.FIXSENSE_API_KEY, // default: FIXSENSE_API_KEY
43
+ apiUrl: 'https://fix-sense.com', // self-hosted installations
44
+ enabled: true,
45
+ timeoutMs: 10000,
46
+ repoFullName: 'acme/web', // when CI variables are absent
47
+ });
48
+ ```
49
+
50
+ GitHub Actions, GitLab CI, Bitbucket Pipelines and Azure Pipelines are
51
+ detected automatically.
52
+
53
+ ## What it sends
54
+
55
+ Per test: the describe/it title chain, the spec file, the outcome, the retry
56
+ count, the duration, and the error message truncated to 2000 characters.
57
+
58
+ It does not send source code, screenshots, videos or environment variables.
59
+
60
+ ## What it will not do
61
+
62
+ It will never fail your run. If the upload fails for any reason, it prints one
63
+ line to stderr and the run's own exit code is untouched.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @fixsense/cypress-plugin
3
+ *
4
+ * Records what each Cypress test did, run after run, so a flaky test can be
5
+ * recognised as flaky rather than as bad luck.
6
+ *
7
+ * Same two rules as the Playwright reporter, for the same reasons: it never
8
+ * fails a run, and it sends outcomes rather than content.
9
+ */
10
+ import { type TestRecord } from "./payload";
11
+ export interface FixSenseCypressOptions {
12
+ /** Defaults to the FIXSENSE_API_KEY environment variable. */
13
+ apiKey?: string;
14
+ /** Override for self-hosted installations. */
15
+ apiUrl?: string;
16
+ /** Set false to turn the plugin off without editing the config. */
17
+ enabled?: boolean;
18
+ timeoutMs?: number;
19
+ /** Override repo detection when CI variables are absent or wrong. */
20
+ repoFullName?: string;
21
+ }
22
+ /** The subset of Cypress's plugin event registrar we use. */
23
+ type On = (event: string, handler: (...args: never[]) => void | Promise<void>) => void;
24
+ /**
25
+ * Register the plugin from `setupNodeEvents`.
26
+ *
27
+ * Results are collected per spec and sent once at the end of the run, so one
28
+ * request covers the whole suite rather than one per spec file.
29
+ */
30
+ export declare function registerFixSense(on: On, options?: FixSenseCypressOptions): void;
31
+ export declare function sendRun(tests: TestRecord[], startedAt: Date, options: FixSenseCypressOptions): Promise<void>;
32
+ export default registerFixSense;
33
+ export * from "./payload";
package/dist/index.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /**
3
+ * @fixsense/cypress-plugin
4
+ *
5
+ * Records what each Cypress test did, run after run, so a flaky test can be
6
+ * recognised as flaky rather than as bad luck.
7
+ *
8
+ * Same two rules as the Playwright reporter, for the same reasons: it never
9
+ * fails a run, and it sends outcomes rather than content.
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
23
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.registerFixSense = registerFixSense;
27
+ exports.sendRun = sendRun;
28
+ const payload_1 = require("./payload");
29
+ const DEFAULT_API_URL = "https://fix-sense.com";
30
+ const DEFAULT_TIMEOUT_MS = 10_000;
31
+ /**
32
+ * Register the plugin from `setupNodeEvents`.
33
+ *
34
+ * Results are collected per spec and sent once at the end of the run, so one
35
+ * request covers the whole suite rather than one per spec file.
36
+ */
37
+ function registerFixSense(on, options = {}) {
38
+ const tests = [];
39
+ const startedAt = new Date();
40
+ on("after:spec", ((spec, results) => {
41
+ try {
42
+ for (const test of results?.tests ?? []) {
43
+ tests.push((0, payload_1.toTestRecord)(test, spec));
44
+ }
45
+ }
46
+ catch {
47
+ // One unreadable spec is not a reason to lose the rest of the run.
48
+ }
49
+ }));
50
+ on("after:run", (async () => {
51
+ await sendRun(tests, startedAt, options);
52
+ }));
53
+ }
54
+ async function sendRun(tests, startedAt, options) {
55
+ if (options.enabled === false)
56
+ return;
57
+ const apiKey = options.apiKey ?? process.env.FIXSENSE_API_KEY;
58
+ // Silent without a key: a developer running Cypress locally has none and
59
+ // does not need telling on every run.
60
+ if (!apiKey)
61
+ return;
62
+ if (tests.length === 0)
63
+ return;
64
+ const context = (0, payload_1.detectContext)(process.env);
65
+ const payload = {
66
+ schemaVersion: 1,
67
+ ...context,
68
+ repoFullName: options.repoFullName ?? context.repoFullName,
69
+ startedAt: startedAt.toISOString(),
70
+ durationMs: Date.now() - startedAt.getTime(),
71
+ totals: (0, payload_1.summarise)(tests),
72
+ tests,
73
+ };
74
+ const base = options.apiUrl ?? process.env.FIXSENSE_API_URL ?? DEFAULT_API_URL;
75
+ const controller = new AbortController();
76
+ const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
77
+ try {
78
+ const res = await fetch(`${base.replace(/\/$/, "")}/api/v1/runs`, {
79
+ method: "POST",
80
+ headers: {
81
+ Authorization: `Bearer ${apiKey}`,
82
+ "Content-Type": "application/json",
83
+ },
84
+ body: JSON.stringify(payload),
85
+ signal: controller.signal,
86
+ });
87
+ if (!res.ok) {
88
+ console.error(`[fixsense] Run not recorded: ${res.status} ${res.statusText}`);
89
+ }
90
+ }
91
+ catch (error) {
92
+ const reason = error instanceof Error ? error.message : String(error);
93
+ console.error(`[fixsense] Run not recorded: ${reason}`);
94
+ }
95
+ finally {
96
+ clearTimeout(timer);
97
+ }
98
+ }
99
+ exports.default = registerFixSense;
100
+ __exportStar(require("./payload"), exports);
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Building the run payload from Cypress results.
3
+ *
4
+ * The CI detection and truncation below are deliberately a copy of what
5
+ * @fixsense/playwright-reporter does, not a shared dependency. Each package
6
+ * installs on its own with no FixSense runtime dependency, which is the whole
7
+ * reason a team will add it. `tests/unit/reporter-parity.test.ts` asserts both
8
+ * copies answer identically for the same environment, so the duplication
9
+ * cannot drift silently.
10
+ */
11
+ /** Cypress calls a test's state one of these. */
12
+ export type CypressState = "passed" | "failed" | "pending" | "skipped";
13
+ /** The parts of a Cypress `after:spec` result we read. Structural on purpose. */
14
+ export interface CypressTestLike {
15
+ title: string[];
16
+ state: CypressState;
17
+ duration?: number;
18
+ attempts?: Array<{
19
+ state?: string;
20
+ }>;
21
+ displayError?: string | null;
22
+ }
23
+ export interface CypressSpecLike {
24
+ relative?: string;
25
+ absolute?: string;
26
+ }
27
+ /** The same four words the Playwright reporter sends. */
28
+ export type Outcome = "expected" | "unexpected" | "flaky" | "skipped";
29
+ export interface TestRecord {
30
+ title: string;
31
+ file: string | null;
32
+ outcome: Outcome;
33
+ status: string;
34
+ retries: number;
35
+ durationMs: number;
36
+ errorMessage: string | null;
37
+ }
38
+ export declare const MAX_ERROR_CHARS = 2000;
39
+ export declare function truncateError(message: string | undefined | null): string | null;
40
+ /**
41
+ * Cypress has no "flaky" state, so it has to be derived.
42
+ *
43
+ * With `retries` configured, a test that failed an attempt and passed a later
44
+ * one is exactly what Playwright calls flaky. Without retries configured
45
+ * Cypress cannot produce the signal at all, and such a run contributes only
46
+ * pass/fail — which the cross-run history still scores, just more slowly.
47
+ */
48
+ export declare function deriveOutcome(test: CypressTestLike): Outcome;
49
+ export declare function toTestRecord(test: CypressTestLike, spec: CypressSpecLike): TestRecord;
50
+ export declare function summarise(tests: TestRecord[]): {
51
+ total: number;
52
+ passed: number;
53
+ failed: number;
54
+ flaky: number;
55
+ skipped: number;
56
+ };
57
+ export declare function detectContext(env: Record<string, string | undefined>): {
58
+ provider: string;
59
+ repoFullName: string | null;
60
+ commitSha: string | null;
61
+ branch: string | null;
62
+ ciRunId: string | null;
63
+ ciRunUrl: string | null;
64
+ } | {
65
+ provider: null;
66
+ repoFullName: null;
67
+ commitSha: null;
68
+ branch: null;
69
+ ciRunId: null;
70
+ ciRunUrl: null;
71
+ };
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * Building the run payload from Cypress results.
4
+ *
5
+ * The CI detection and truncation below are deliberately a copy of what
6
+ * @fixsense/playwright-reporter does, not a shared dependency. Each package
7
+ * installs on its own with no FixSense runtime dependency, which is the whole
8
+ * reason a team will add it. `tests/unit/reporter-parity.test.ts` asserts both
9
+ * copies answer identically for the same environment, so the duplication
10
+ * cannot drift silently.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.MAX_ERROR_CHARS = void 0;
14
+ exports.truncateError = truncateError;
15
+ exports.deriveOutcome = deriveOutcome;
16
+ exports.toTestRecord = toTestRecord;
17
+ exports.summarise = summarise;
18
+ exports.detectContext = detectContext;
19
+ exports.MAX_ERROR_CHARS = 2000;
20
+ function truncateError(message) {
21
+ if (!message)
22
+ return null;
23
+ const clean = message.replace(/\u001b\[[0-9;]*m/g, "").trim();
24
+ if (!clean)
25
+ return null;
26
+ return clean.length > exports.MAX_ERROR_CHARS
27
+ ? `${clean.slice(0, exports.MAX_ERROR_CHARS)}… [truncated]`
28
+ : clean;
29
+ }
30
+ /**
31
+ * Cypress has no "flaky" state, so it has to be derived.
32
+ *
33
+ * With `retries` configured, a test that failed an attempt and passed a later
34
+ * one is exactly what Playwright calls flaky. Without retries configured
35
+ * Cypress cannot produce the signal at all, and such a run contributes only
36
+ * pass/fail — which the cross-run history still scores, just more slowly.
37
+ */
38
+ function deriveOutcome(test) {
39
+ if (test.state === "pending" || test.state === "skipped")
40
+ return "skipped";
41
+ if (test.state === "failed")
42
+ return "unexpected";
43
+ const attempts = test.attempts ?? [];
44
+ const failedEarlier = attempts
45
+ .slice(0, -1)
46
+ .some((attempt) => attempt.state === "failed");
47
+ return failedEarlier ? "flaky" : "expected";
48
+ }
49
+ function toTestRecord(test, spec) {
50
+ return {
51
+ // Cypress gives the describe/it chain as an array; the separator matches
52
+ // the Playwright reporter so one history reads the same from both.
53
+ title: test.title.filter(Boolean).join(" › "),
54
+ file: spec.relative ?? spec.absolute ?? null,
55
+ outcome: deriveOutcome(test),
56
+ status: test.state,
57
+ retries: Math.max(0, (test.attempts?.length ?? 1) - 1),
58
+ durationMs: test.duration ?? 0,
59
+ errorMessage: truncateError(test.displayError),
60
+ };
61
+ }
62
+ function summarise(tests) {
63
+ return {
64
+ total: tests.length,
65
+ passed: tests.filter((t) => t.outcome === "expected").length,
66
+ failed: tests.filter((t) => t.outcome === "unexpected").length,
67
+ flaky: tests.filter((t) => t.outcome === "flaky").length,
68
+ skipped: tests.filter((t) => t.outcome === "skipped").length,
69
+ };
70
+ }
71
+ function detectContext(env) {
72
+ if (env.GITHUB_ACTIONS === "true" || env.GITHUB_REPOSITORY) {
73
+ const repo = env.GITHUB_REPOSITORY ?? null;
74
+ return {
75
+ provider: "github",
76
+ repoFullName: repo,
77
+ commitSha: env.GITHUB_SHA ?? null,
78
+ branch: env.GITHUB_HEAD_REF || env.GITHUB_REF_NAME || null,
79
+ ciRunId: env.GITHUB_RUN_ID ?? null,
80
+ ciRunUrl: repo && env.GITHUB_RUN_ID
81
+ ? `${env.GITHUB_SERVER_URL ?? "https://github.com"}/${repo}/actions/runs/${env.GITHUB_RUN_ID}`
82
+ : null,
83
+ };
84
+ }
85
+ if (env.GITLAB_CI === "true" || env.CI_PROJECT_PATH) {
86
+ return {
87
+ provider: "gitlab",
88
+ repoFullName: env.CI_PROJECT_PATH ?? null,
89
+ commitSha: env.CI_COMMIT_SHA ?? null,
90
+ branch: env.CI_COMMIT_REF_NAME ?? null,
91
+ ciRunId: env.CI_PIPELINE_ID ?? null,
92
+ ciRunUrl: env.CI_PIPELINE_URL ?? null,
93
+ };
94
+ }
95
+ if (env.BITBUCKET_REPO_FULL_NAME) {
96
+ return {
97
+ provider: "bitbucket",
98
+ repoFullName: env.BITBUCKET_REPO_FULL_NAME,
99
+ commitSha: env.BITBUCKET_COMMIT ?? null,
100
+ branch: env.BITBUCKET_BRANCH ?? null,
101
+ ciRunId: env.BITBUCKET_BUILD_NUMBER ?? null,
102
+ ciRunUrl: null,
103
+ };
104
+ }
105
+ if (env.BUILD_REPOSITORY_NAME || env.TF_BUILD === "True") {
106
+ return {
107
+ provider: "azure",
108
+ repoFullName: env.BUILD_REPOSITORY_NAME ?? null,
109
+ commitSha: env.BUILD_SOURCEVERSION ?? null,
110
+ branch: (env.BUILD_SOURCEBRANCHNAME || env.BUILD_SOURCEBRANCH) ?? null,
111
+ ciRunId: env.BUILD_BUILDID ?? null,
112
+ ciRunUrl: null,
113
+ };
114
+ }
115
+ return {
116
+ provider: null,
117
+ repoFullName: null,
118
+ commitSha: null,
119
+ branch: null,
120
+ ciRunId: null,
121
+ ciRunUrl: null,
122
+ };
123
+ }
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@fixsense/cypress-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Cypress plugin that records test outcomes across runs so flaky tests can be identified over time.",
5
+ "license": "MIT",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "keywords": [
14
+ "cypress",
15
+ "cypress-plugin",
16
+ "flaky-tests",
17
+ "ci",
18
+ "test-reporting"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/CopilotMe/fix-sense.git",
23
+ "directory": "packages/cypress-plugin"
24
+ },
25
+ "homepage": "https://fix-sense.com",
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.json",
28
+ "prepublishOnly": "npm run build"
29
+ },
30
+ "peerDependencies": {
31
+ "cypress": ">=12.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20.0.0",
35
+ "typescript": "^5.0.0"
36
+ },
37
+ "engines": {
38
+ "node": ">=18"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ }
43
+ }