@qaguardian/playwright-score 0.1.12 → 0.1.13

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.
@@ -24,7 +24,7 @@ export function formatMarkdown(result) {
24
24
  }
25
25
  if (result.skippedFiles?.length) {
26
26
  lines.push('');
27
- lines.push(`<details><summary>Skipped — looks like a non-Playwright test (Jest/Vitest/RTL) (${result.skippedFiles.length})</summary>`);
27
+ lines.push(`<details><summary>Skipped — looks like a non-Playwright test (Jest/Vitest/RTL/Cypress) (${result.skippedFiles.length})</summary>`);
28
28
  lines.push('');
29
29
  for (const f of result.skippedFiles) {
30
30
  lines.push(`- \`${f}\``);
@@ -26,7 +26,7 @@ export function formatText(result) {
26
26
  }
27
27
  if (result.skippedFiles?.length) {
28
28
  lines.push('');
29
- lines.push(`Skipped (looks like a non-Playwright test — Jest/Vitest/RTL — ${result.skippedFiles.length}):`);
29
+ lines.push(`Skipped (looks like a non-Playwright test — Jest/Vitest/RTL/Cypress — ${result.skippedFiles.length}):`);
30
30
  for (const f of result.skippedFiles.slice(0, 20)) {
31
31
  lines.push(` ${f}`);
32
32
  }
package/dist/index.js CHANGED
@@ -14,7 +14,20 @@ export { formatJson } from './formatters/json.js';
14
14
  export { formatText } from './formatters/text.js';
15
15
  export { formatMarkdown } from './formatters/markdown.js';
16
16
  export { formatSarif } from './formatters/sarif.js';
17
- const SPEC_GLOBS = ['**/*.{spec,test}.{ts,tsx,js,jsx}', '**/*.spec.ts', '**/*.test.ts'];
17
+ // `.e2e.` is a real, common convention for disambiguating end-to-end specs
18
+ // from unit tests living in the same tree — verified against a
19
+ // well-known, large real-world repo (cal.com: 53 real Playwright specs,
20
+ // all named *.e2e.ts, zero *.spec.ts/*.test.ts) where a directory scan
21
+ // previously hard-failed with "no files matched" despite a fully healthy,
22
+ // populated suite. looksLikeNonPlaywrightTest (see metrics.ts) is the
23
+ // safety net for a repo that uses `.e2e.` for a *different* framework —
24
+ // Cypress specifically was common enough here to get its own explicit
25
+ // check alongside the existing Jest/Vitest/RTL ones.
26
+ const SPEC_GLOBS = [
27
+ '**/*.{spec,test,e2e}.{ts,tsx,js,jsx}',
28
+ '**/*.spec.ts',
29
+ '**/*.test.ts',
30
+ ];
18
31
  // Directory/glob expansion must never sweep in vendored or generated code —
19
32
  // verified as a real bug: scanning a project root with a plain node_modules
20
33
  // dependency that ships its own *.spec.ts files silently included them
@@ -43,7 +56,7 @@ const DEFAULT_IGNORE_GLOBS = [
43
56
  * `expanded`: everything else (matched via a directory scan or a glob
44
57
  * pattern) — subject to the looksLikePlaywrightSpec filter in scorePaths,
45
58
  * since a broad `**\/*.test.ts`-style match can just as easily sweep in
46
- * unrelated Jest/Vitest/RTL unit tests sitting in the same repo.
59
+ * unrelated Jest/Vitest/RTL/Cypress unit tests sitting in the same repo.
47
60
  */
48
61
  function expandPaths(inputs, cwd) {
49
62
  const explicit = new Set();
@@ -166,7 +179,7 @@ export async function scorePaths(options) {
166
179
  {
167
180
  rule: 'playwright-score/no-files',
168
181
  severity: 'error',
169
- message: `${expanded.length} file(s) matched but all look like non-Playwright tests (Jest/Vitest/RTL) — nothing to score.`,
182
+ message: `${expanded.length} file(s) matched but all look like non-Playwright tests (Jest/Vitest/RTL/Cypress) — nothing to score.`,
170
183
  file: cwd,
171
184
  dimension: 'structure',
172
185
  },
package/dist/metrics.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { Finding, LocatorCounts } from './types.js';
2
2
  /**
3
3
  * Heuristic: does this file show positive evidence of being a *non*-
4
- * Playwright test (Jest/Vitest/Mocha/Jasmine/React Testing Library), as
5
- * opposed to a Playwright spec that a broad `**\/*.test.ts` glob would
6
- * otherwise sweep in alongside real e2e specs? Used only to decide whether
7
- * to auto-exclude a file discovered via directory/glob expansion — never
8
- * applied to a file path the caller named explicitly.
4
+ * Playwright test (Jest/Vitest/Mocha/Jasmine/React Testing Library/
5
+ * Cypress), as opposed to a Playwright spec that a broad `**\/*.test.ts`
6
+ * glob would otherwise sweep in alongside real e2e specs? Used only to
7
+ * decide whether to auto-exclude a file discovered via directory/glob
8
+ * expansion — never applied to a file path the caller named explicitly.
9
9
  */
10
10
  export declare function looksLikeNonPlaywrightTest(source: string): boolean;
11
11
  export declare function countLocators(source: string, file?: string): LocatorCounts;
package/dist/metrics.js CHANGED
@@ -13,18 +13,27 @@ import { countSloc } from './sloc.js';
13
13
  // in one real suite). Denylisting known non-Playwright frameworks is much
14
14
  // safer — a missed rare/unusual file just scores harmlessly, where a
15
15
  // falsely-skipped real spec silently stops being scored at all.
16
- const NON_PLAYWRIGHT_IMPORT_RE = /from\s+['"](?:vitest|jest|@jest\/[a-z-]+|mocha|jasmine|chai|@testing-library\/[a-z-]+)['"]/;
16
+ const NON_PLAYWRIGHT_IMPORT_RE = /from\s+['"](?:vitest|jest|@jest\/[a-z-]+|mocha|jasmine|chai|@testing-library\/[a-z-]+|cypress)['"]/;
17
17
  const RTL_API_RE = /\bscreen\.(?:getBy|queryBy|findBy|getAllBy|queryAllBy|findAllBy)\w*\(|\btoBeInTheDocument\(/;
18
+ // Cypress's `cy` command object is globally available without an import in
19
+ // the framework's default setup, the same way RTL's `screen` often is —
20
+ // matched on specific, common Cypress command names (not a bare `cy.`
21
+ // prefix) to avoid colliding with an unrelated local variable named `cy`.
22
+ // Added alongside SPEC_GLOBS picking up `*.e2e.*` by default (see
23
+ // index.ts): `.e2e.` is Cypress's own scaffolding convention too, so
24
+ // broadening spec discovery to that suffix needed this as a companion
25
+ // safety net, not just Playwright's own conventions.
26
+ const CYPRESS_API_RE = /\bcy\.(?:visit|get|contains|click|type|should|intercept|wait|request|fixture)\(/;
18
27
  /**
19
28
  * Heuristic: does this file show positive evidence of being a *non*-
20
- * Playwright test (Jest/Vitest/Mocha/Jasmine/React Testing Library), as
21
- * opposed to a Playwright spec that a broad `**\/*.test.ts` glob would
22
- * otherwise sweep in alongside real e2e specs? Used only to decide whether
23
- * to auto-exclude a file discovered via directory/glob expansion — never
24
- * applied to a file path the caller named explicitly.
29
+ * Playwright test (Jest/Vitest/Mocha/Jasmine/React Testing Library/
30
+ * Cypress), as opposed to a Playwright spec that a broad `**\/*.test.ts`
31
+ * glob would otherwise sweep in alongside real e2e specs? Used only to
32
+ * decide whether to auto-exclude a file discovered via directory/glob
33
+ * expansion — never applied to a file path the caller named explicitly.
25
34
  */
26
35
  export function looksLikeNonPlaywrightTest(source) {
27
- return NON_PLAYWRIGHT_IMPORT_RE.test(source) || RTL_API_RE.test(source);
36
+ return NON_PLAYWRIGHT_IMPORT_RE.test(source) || RTL_API_RE.test(source) || CYPRESS_API_RE.test(source);
28
37
  }
29
38
  const NATIVE_METHODS = new Set([
30
39
  'getByRole',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qaguardian/playwright-score",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Deterministic, AI-free Playwright spec quality score (sqs-v1). Lint + score with standard and guardian profiles.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",