@ripplo/testing 0.0.3 → 0.0.5

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/dist/index.js CHANGED
@@ -61,7 +61,11 @@ function createRipplo(rawConfig) {
61
61
  },
62
62
  precondition(name) {
63
63
  if (preconditionNames.has(name)) {
64
- throw new Error(`Duplicate precondition name: "${name}"`);
64
+ preconditions.splice(
65
+ 0,
66
+ preconditions.length,
67
+ ...preconditions.filter((p) => p.name !== name)
68
+ );
65
69
  }
66
70
  preconditionNames.add(name);
67
71
  return buildPrecondition(name, preconditions);
@@ -69,7 +73,7 @@ function createRipplo(rawConfig) {
69
73
  test(id) {
70
74
  validateTestId(id);
71
75
  if (testNames.has(id)) {
72
- throw new Error(`Duplicate test id: "${id}"`);
76
+ tests.splice(0, tests.length, ...tests.filter((t) => t.id !== id));
73
77
  }
74
78
  testNames.add(id);
75
79
  return buildTestName(id, tests);
@@ -446,6 +450,181 @@ function looksLikeDynamicData(value) {
446
450
  function isAssertionNode(node) {
447
451
  return node.type.startsWith("assert");
448
452
  }
453
+ var EFFECT_ASSERTION_TYPES = /* @__PURE__ */ new Set([
454
+ "assertText",
455
+ "assertValue",
456
+ "assertCount",
457
+ "assertUrl",
458
+ "assertNotVisible",
459
+ "assertChecked",
460
+ "assertNotChecked",
461
+ "assertAttribute",
462
+ "assertDisabled",
463
+ "assertEnabled"
464
+ ]);
465
+ function isEffectAssertion(node) {
466
+ return EFFECT_ASSERTION_TYPES.has(node.type);
467
+ }
468
+ function noAssertions(nodes, test, report) {
469
+ if (!test.implemented || nodes.length === 0) {
470
+ return;
471
+ }
472
+ if (!nodes.some((n) => isAssertionNode(n))) {
473
+ report({
474
+ message: "Test has zero assertion steps \u2014 cannot verify expectedOutcome. Add assert.* steps.",
475
+ rule: "no-assertions",
476
+ step: void 0
477
+ });
478
+ }
479
+ }
480
+ function lowAssertionRatio(nodes, test, report) {
481
+ if (!test.implemented || nodes.length <= 3) {
482
+ return;
483
+ }
484
+ const assertions = nodes.filter((n) => isAssertionNode(n)).length;
485
+ if (assertions === 0) {
486
+ return;
487
+ }
488
+ const ratio = assertions / nodes.length;
489
+ if (ratio < 0.15) {
490
+ const pct = Math.round(ratio * 100);
491
+ report({
492
+ message: `Only ${String(assertions)}/${String(nodes.length)} steps are assertions (${String(pct)}%) \u2014 add more verification between actions`,
493
+ rule: "low-assertion-ratio",
494
+ step: void 0
495
+ });
496
+ }
497
+ }
498
+ function locatorSignature(node) {
499
+ if (!("locator" in node) || node.locator == null) {
500
+ return void 0;
501
+ }
502
+ const loc = node.locator;
503
+ if (loc.by === "role") {
504
+ return `role:${loc.role}:${loc.name ?? ""}`;
505
+ }
506
+ return `testId:${loc.value}`;
507
+ }
508
+ function tautologicalPostClickAssert(nodes, _test, report) {
509
+ nodes.forEach((node, index) => {
510
+ if (node.type !== "click") {
511
+ return;
512
+ }
513
+ const sig = locatorSignature(node);
514
+ if (sig == null) {
515
+ return;
516
+ }
517
+ const window = nodes.slice(index + 1, index + 4);
518
+ const matchesSameAssertVisible = window.find(
519
+ (n) => n.type === "assertVisible" && locatorSignature(n) === sig
520
+ );
521
+ if (matchesSameAssertVisible == null) {
522
+ return;
523
+ }
524
+ const hasOtherEffect = window.some(
525
+ (n) => isEffectAssertion(n) || isAssertionNode(n) && locatorSignature(n) !== sig
526
+ );
527
+ if (hasOtherEffect) {
528
+ return;
529
+ }
530
+ report({
531
+ message: `click "${node.label ?? node.id}" is followed only by assert.visible on the same locator \u2014 verifies nothing about the click's effect`,
532
+ rule: "tautological-post-click-assert",
533
+ step: node.label ?? node.id
534
+ });
535
+ });
536
+ }
537
+ var STOPWORDS = /* @__PURE__ */ new Set([
538
+ "the",
539
+ "is",
540
+ "a",
541
+ "an",
542
+ "and",
543
+ "or",
544
+ "of",
545
+ "to",
546
+ "in",
547
+ "on",
548
+ "at",
549
+ "for",
550
+ "that",
551
+ "this",
552
+ "with",
553
+ "be",
554
+ "are",
555
+ "was",
556
+ "were",
557
+ "it",
558
+ "its",
559
+ "as",
560
+ "by",
561
+ "from",
562
+ "after",
563
+ "before",
564
+ "should",
565
+ "will",
566
+ "can",
567
+ "still",
568
+ "but",
569
+ "not",
570
+ "no",
571
+ "so",
572
+ "if",
573
+ "then",
574
+ "than",
575
+ "user",
576
+ "users",
577
+ "page",
578
+ "view",
579
+ "shows",
580
+ "show",
581
+ "see",
582
+ "click",
583
+ "clicks",
584
+ "clicked",
585
+ "clickable",
586
+ "visible",
587
+ "appears",
588
+ "appear",
589
+ "displayed",
590
+ "stays",
591
+ "remains"
592
+ ]);
593
+ function tokenize(text) {
594
+ return text.toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length >= 3 && !STOPWORDS.has(t));
595
+ }
596
+ function nodeKeywords(node) {
597
+ const fromLabel = node.label == null ? [] : tokenize(node.label);
598
+ if (!("locator" in node) || node.locator == null) {
599
+ return fromLabel;
600
+ }
601
+ const loc = node.locator;
602
+ const locName = loc.by === "role" ? loc.name ?? "" : loc.value;
603
+ return [...fromLabel, ...tokenize(locName)];
604
+ }
605
+ function expectedOutcomeKeywordCoverage(nodes, test, report) {
606
+ if (!test.implemented || nodes.length === 0) {
607
+ return;
608
+ }
609
+ const outcomeTokens = new Set(tokenize(test.expectedOutcome));
610
+ if (outcomeTokens.size === 0) {
611
+ return;
612
+ }
613
+ const assertions = nodes.filter((n) => isAssertionNode(n));
614
+ if (assertions.length === 0) {
615
+ return;
616
+ }
617
+ const covered = assertions.some(
618
+ (node) => nodeKeywords(node).some((tok) => outcomeTokens.has(tok))
619
+ );
620
+ if (!covered) {
621
+ report({
622
+ message: `No assertion references any keyword from expectedOutcome (${[...outcomeTokens].join(", ")}) \u2014 the outcome may not actually be verified`,
623
+ rule: "expected-outcome-keyword-coverage",
624
+ step: void 0
625
+ });
626
+ }
627
+ }
449
628
  var RULES = [
450
629
  exactTextMatch,
451
630
  noHardcodedData,
@@ -454,7 +633,11 @@ var RULES = [
454
633
  noDuplicateLabels,
455
634
  assertAfterAction,
456
635
  assertMatchesOutcome,
457
- noEmptySteps
636
+ noEmptySteps,
637
+ noAssertions,
638
+ lowAssertionRatio,
639
+ tautologicalPostClickAssert,
640
+ expectedOutcomeKeywordCoverage
458
641
  ];
459
642
  export {
460
643
  buildSetCookieHeader,
package/dist/nextjs.js CHANGED
@@ -23,10 +23,9 @@ function createNextHandler({ enabled, ripplo }) {
23
23
  if ("error" in verified) {
24
24
  return verified.error;
25
25
  }
26
- if (action === "execute-batch") {
27
- return handleExecuteBatch({ body: verified.body, engine, req });
28
- }
29
- return handleTeardown({ body: verified.body, engine });
26
+ return runGuarded(
27
+ () => action === "execute-batch" ? handleExecuteBatch({ body: verified.body, engine, req }) : handleTeardown({ body: verified.body, engine })
28
+ );
30
29
  };
31
30
  }
32
31
  async function handleExecuteBatch({
@@ -85,6 +84,20 @@ async function verifyAndReadBody(req, webhookSecret) {
85
84
  }
86
85
  return { body };
87
86
  }
87
+ async function runGuarded(fn) {
88
+ try {
89
+ return await fn();
90
+ } catch (error) {
91
+ return jsonResponse(
92
+ {
93
+ error: error instanceof Error ? error.message : "Unknown error",
94
+ stack: error instanceof Error ? error.stack : void 0,
95
+ success: false
96
+ },
97
+ 500
98
+ );
99
+ }
100
+ }
88
101
  function lastPathSegment(url) {
89
102
  const pathname = new URL(url).pathname;
90
103
  const segments = pathname.split("/").filter((s) => s.length > 0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ripplo/testing",
3
3
  "description": "TypeScript DSL for defining and running Ripplo e2e workflow tests",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -55,16 +55,16 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "standardwebhooks": "^1.0.0",
58
- "zod": "^4.3.6"
58
+ "zod": "catalog:"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/express": "^5.0.2",
62
- "@types/node": "^22.15.3",
63
- "eslint": "^9.39.1",
62
+ "@types/node": "catalog:",
63
+ "eslint": "catalog:",
64
64
  "express": "^5.1.0",
65
65
  "fastify": "^5.3.3",
66
66
  "tsup": "^8.5.1",
67
- "typescript": "^5.9.3",
67
+ "typescript": "catalog:",
68
68
  "vitest": "^4.1.4",
69
69
  "@ripplo/eslint-config": "0.0.0",
70
70
  "@ripplo/spec": "^0.0.0"