@ripplo/testing 0.0.2 → 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/{chunk-X2FROZPN.js → chunk-GTHRSFXF.js} +1 -0
- package/dist/compiler.d.ts +1 -0
- package/dist/compiler.js +1 -1
- package/dist/index.js +185 -3
- package/package.json +3 -3
package/dist/compiler.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ interface CompiledTest {
|
|
|
12
12
|
readonly additionalChecks: ReadonlyArray<string>;
|
|
13
13
|
readonly description: string;
|
|
14
14
|
readonly expectedOutcome: string;
|
|
15
|
+
readonly implemented: boolean;
|
|
15
16
|
readonly name: string;
|
|
16
17
|
readonly slug: string;
|
|
17
18
|
readonly spec: WorkflowSpec;
|
package/dist/compiler.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
compile
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GTHRSFXF.js";
|
|
4
4
|
import "./chunk-MGATMMCZ.js";
|
|
5
5
|
import {
|
|
6
6
|
buildSetCookieHeader,
|
|
@@ -413,7 +413,10 @@ function assertMatchesOutcome(nodes, _test, report) {
|
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
|
-
function noEmptySteps(nodes,
|
|
416
|
+
function noEmptySteps(nodes, test, report) {
|
|
417
|
+
if (!test.implemented) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
417
420
|
if (nodes.length === 0) {
|
|
418
421
|
report({
|
|
419
422
|
message: "Test has zero steps",
|
|
@@ -443,6 +446,181 @@ function looksLikeDynamicData(value) {
|
|
|
443
446
|
function isAssertionNode(node) {
|
|
444
447
|
return node.type.startsWith("assert");
|
|
445
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
|
+
}
|
|
446
624
|
var RULES = [
|
|
447
625
|
exactTextMatch,
|
|
448
626
|
noHardcodedData,
|
|
@@ -451,7 +629,11 @@ var RULES = [
|
|
|
451
629
|
noDuplicateLabels,
|
|
452
630
|
assertAfterAction,
|
|
453
631
|
assertMatchesOutcome,
|
|
454
|
-
noEmptySteps
|
|
632
|
+
noEmptySteps,
|
|
633
|
+
noAssertions,
|
|
634
|
+
lowAssertionRatio,
|
|
635
|
+
tautologicalPostClickAssert,
|
|
636
|
+
expectedOutcomeKeywordCoverage
|
|
455
637
|
];
|
|
456
638
|
export {
|
|
457
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",
|