@ripplo/testing 0.0.3 → 0.0.4
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 +180 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -446,6 +446,181 @@ function looksLikeDynamicData(value) {
|
|
|
446
446
|
function isAssertionNode(node) {
|
|
447
447
|
return node.type.startsWith("assert");
|
|
448
448
|
}
|
|
449
|
+
var EFFECT_ASSERTION_TYPES = /* @__PURE__ */ new Set([
|
|
450
|
+
"assertText",
|
|
451
|
+
"assertValue",
|
|
452
|
+
"assertCount",
|
|
453
|
+
"assertUrl",
|
|
454
|
+
"assertNotVisible",
|
|
455
|
+
"assertChecked",
|
|
456
|
+
"assertNotChecked",
|
|
457
|
+
"assertAttribute",
|
|
458
|
+
"assertDisabled",
|
|
459
|
+
"assertEnabled"
|
|
460
|
+
]);
|
|
461
|
+
function isEffectAssertion(node) {
|
|
462
|
+
return EFFECT_ASSERTION_TYPES.has(node.type);
|
|
463
|
+
}
|
|
464
|
+
function noAssertions(nodes, test, report) {
|
|
465
|
+
if (!test.implemented || nodes.length === 0) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (!nodes.some((n) => isAssertionNode(n))) {
|
|
469
|
+
report({
|
|
470
|
+
message: "Test has zero assertion steps \u2014 cannot verify expectedOutcome. Add assert.* steps.",
|
|
471
|
+
rule: "no-assertions",
|
|
472
|
+
step: void 0
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
function lowAssertionRatio(nodes, test, report) {
|
|
477
|
+
if (!test.implemented || nodes.length <= 3) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const assertions = nodes.filter((n) => isAssertionNode(n)).length;
|
|
481
|
+
if (assertions === 0) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const ratio = assertions / nodes.length;
|
|
485
|
+
if (ratio < 0.15) {
|
|
486
|
+
const pct = Math.round(ratio * 100);
|
|
487
|
+
report({
|
|
488
|
+
message: `Only ${String(assertions)}/${String(nodes.length)} steps are assertions (${String(pct)}%) \u2014 add more verification between actions`,
|
|
489
|
+
rule: "low-assertion-ratio",
|
|
490
|
+
step: void 0
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function locatorSignature(node) {
|
|
495
|
+
if (!("locator" in node) || node.locator == null) {
|
|
496
|
+
return void 0;
|
|
497
|
+
}
|
|
498
|
+
const loc = node.locator;
|
|
499
|
+
if (loc.by === "role") {
|
|
500
|
+
return `role:${loc.role}:${loc.name ?? ""}`;
|
|
501
|
+
}
|
|
502
|
+
return `testId:${loc.value}`;
|
|
503
|
+
}
|
|
504
|
+
function tautologicalPostClickAssert(nodes, _test, report) {
|
|
505
|
+
nodes.forEach((node, index) => {
|
|
506
|
+
if (node.type !== "click") {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
const sig = locatorSignature(node);
|
|
510
|
+
if (sig == null) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const window = nodes.slice(index + 1, index + 4);
|
|
514
|
+
const matchesSameAssertVisible = window.find(
|
|
515
|
+
(n) => n.type === "assertVisible" && locatorSignature(n) === sig
|
|
516
|
+
);
|
|
517
|
+
if (matchesSameAssertVisible == null) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const hasOtherEffect = window.some(
|
|
521
|
+
(n) => isEffectAssertion(n) || isAssertionNode(n) && locatorSignature(n) !== sig
|
|
522
|
+
);
|
|
523
|
+
if (hasOtherEffect) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
report({
|
|
527
|
+
message: `click "${node.label ?? node.id}" is followed only by assert.visible on the same locator \u2014 verifies nothing about the click's effect`,
|
|
528
|
+
rule: "tautological-post-click-assert",
|
|
529
|
+
step: node.label ?? node.id
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
var STOPWORDS = /* @__PURE__ */ new Set([
|
|
534
|
+
"the",
|
|
535
|
+
"is",
|
|
536
|
+
"a",
|
|
537
|
+
"an",
|
|
538
|
+
"and",
|
|
539
|
+
"or",
|
|
540
|
+
"of",
|
|
541
|
+
"to",
|
|
542
|
+
"in",
|
|
543
|
+
"on",
|
|
544
|
+
"at",
|
|
545
|
+
"for",
|
|
546
|
+
"that",
|
|
547
|
+
"this",
|
|
548
|
+
"with",
|
|
549
|
+
"be",
|
|
550
|
+
"are",
|
|
551
|
+
"was",
|
|
552
|
+
"were",
|
|
553
|
+
"it",
|
|
554
|
+
"its",
|
|
555
|
+
"as",
|
|
556
|
+
"by",
|
|
557
|
+
"from",
|
|
558
|
+
"after",
|
|
559
|
+
"before",
|
|
560
|
+
"should",
|
|
561
|
+
"will",
|
|
562
|
+
"can",
|
|
563
|
+
"still",
|
|
564
|
+
"but",
|
|
565
|
+
"not",
|
|
566
|
+
"no",
|
|
567
|
+
"so",
|
|
568
|
+
"if",
|
|
569
|
+
"then",
|
|
570
|
+
"than",
|
|
571
|
+
"user",
|
|
572
|
+
"users",
|
|
573
|
+
"page",
|
|
574
|
+
"view",
|
|
575
|
+
"shows",
|
|
576
|
+
"show",
|
|
577
|
+
"see",
|
|
578
|
+
"click",
|
|
579
|
+
"clicks",
|
|
580
|
+
"clicked",
|
|
581
|
+
"clickable",
|
|
582
|
+
"visible",
|
|
583
|
+
"appears",
|
|
584
|
+
"appear",
|
|
585
|
+
"displayed",
|
|
586
|
+
"stays",
|
|
587
|
+
"remains"
|
|
588
|
+
]);
|
|
589
|
+
function tokenize(text) {
|
|
590
|
+
return text.toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length >= 3 && !STOPWORDS.has(t));
|
|
591
|
+
}
|
|
592
|
+
function nodeKeywords(node) {
|
|
593
|
+
const fromLabel = node.label == null ? [] : tokenize(node.label);
|
|
594
|
+
if (!("locator" in node) || node.locator == null) {
|
|
595
|
+
return fromLabel;
|
|
596
|
+
}
|
|
597
|
+
const loc = node.locator;
|
|
598
|
+
const locName = loc.by === "role" ? loc.name ?? "" : loc.value;
|
|
599
|
+
return [...fromLabel, ...tokenize(locName)];
|
|
600
|
+
}
|
|
601
|
+
function expectedOutcomeKeywordCoverage(nodes, test, report) {
|
|
602
|
+
if (!test.implemented || nodes.length === 0) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const outcomeTokens = new Set(tokenize(test.expectedOutcome));
|
|
606
|
+
if (outcomeTokens.size === 0) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const assertions = nodes.filter((n) => isAssertionNode(n));
|
|
610
|
+
if (assertions.length === 0) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
const covered = assertions.some(
|
|
614
|
+
(node) => nodeKeywords(node).some((tok) => outcomeTokens.has(tok))
|
|
615
|
+
);
|
|
616
|
+
if (!covered) {
|
|
617
|
+
report({
|
|
618
|
+
message: `No assertion references any keyword from expectedOutcome (${[...outcomeTokens].join(", ")}) \u2014 the outcome may not actually be verified`,
|
|
619
|
+
rule: "expected-outcome-keyword-coverage",
|
|
620
|
+
step: void 0
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
}
|
|
449
624
|
var RULES = [
|
|
450
625
|
exactTextMatch,
|
|
451
626
|
noHardcodedData,
|
|
@@ -454,7 +629,11 @@ var RULES = [
|
|
|
454
629
|
noDuplicateLabels,
|
|
455
630
|
assertAfterAction,
|
|
456
631
|
assertMatchesOutcome,
|
|
457
|
-
noEmptySteps
|
|
632
|
+
noEmptySteps,
|
|
633
|
+
noAssertions,
|
|
634
|
+
lowAssertionRatio,
|
|
635
|
+
tautologicalPostClickAssert,
|
|
636
|
+
expectedOutcomeKeywordCoverage
|
|
458
637
|
];
|
|
459
638
|
export {
|
|
460
639
|
buildSetCookieHeader,
|
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.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"tsup": "^8.5.1",
|
|
67
67
|
"typescript": "^5.9.3",
|
|
68
68
|
"vitest": "^4.1.4",
|
|
69
|
-
"@ripplo/
|
|
70
|
-
"@ripplo/
|
|
69
|
+
"@ripplo/spec": "^0.0.0",
|
|
70
|
+
"@ripplo/eslint-config": "0.0.0"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"dotenv": "^16.0.0 || ^17.0.0",
|