@featurevisor/core 1.2.1 → 1.2.2

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.
Files changed (40) hide show
  1. package/.eslintcache +1 -1
  2. package/CHANGELOG.md +8 -0
  3. package/coverage/clover.xml +2 -2
  4. package/coverage/coverage-final.json +1 -1
  5. package/coverage/lcov-report/index.html +1 -1
  6. package/coverage/lcov-report/lib/builder/allocator.js.html +1 -1
  7. package/coverage/lcov-report/lib/builder/index.html +1 -1
  8. package/coverage/lcov-report/lib/builder/traffic.js.html +1 -1
  9. package/coverage/lcov-report/lib/tester/checkIfObjectsAreEqual.js.html +1 -1
  10. package/coverage/lcov-report/lib/tester/index.html +1 -1
  11. package/coverage/lcov-report/lib/tester/matrix.js.html +5 -5
  12. package/coverage/lcov-report/src/builder/allocator.ts.html +1 -1
  13. package/coverage/lcov-report/src/builder/index.html +1 -1
  14. package/coverage/lcov-report/src/builder/traffic.ts.html +1 -1
  15. package/coverage/lcov-report/src/tester/checkIfObjectsAreEqual.ts.html +1 -1
  16. package/coverage/lcov-report/src/tester/index.html +1 -1
  17. package/coverage/lcov-report/src/tester/matrix.ts.html +5 -5
  18. package/lib/tester/matrix.js +4 -4
  19. package/lib/tester/matrix.js.map +1 -1
  20. package/lib/tester/prettyDuration.d.ts +1 -0
  21. package/lib/tester/prettyDuration.js +31 -0
  22. package/lib/tester/prettyDuration.js.map +1 -0
  23. package/lib/tester/printTestResult.d.ts +2 -0
  24. package/lib/tester/printTestResult.js +41 -0
  25. package/lib/tester/printTestResult.js.map +1 -0
  26. package/lib/tester/testFeature.d.ts +2 -2
  27. package/lib/tester/testFeature.js +78 -31
  28. package/lib/tester/testFeature.js.map +1 -1
  29. package/lib/tester/testProject.js +37 -11
  30. package/lib/tester/testProject.js.map +1 -1
  31. package/lib/tester/testSegment.d.ts +2 -2
  32. package/lib/tester/testSegment.js +35 -12
  33. package/lib/tester/testSegment.js.map +1 -1
  34. package/package.json +5 -5
  35. package/src/tester/matrix.ts +4 -4
  36. package/src/tester/prettyDuration.ts +34 -0
  37. package/src/tester/printTestResult.ts +53 -0
  38. package/src/tester/testFeature.ts +87 -48
  39. package/src/tester/testProject.ts +44 -12
  40. package/src/tester/testSegment.ts +48 -20
@@ -6,6 +6,8 @@ import { testSegment } from "./testSegment";
6
6
  import { testFeature } from "./testFeature";
7
7
  import { CLI_FORMAT_BOLD, CLI_FORMAT_GREEN, CLI_FORMAT_RED } from "./cliFormat";
8
8
  import { Dependencies } from "../dependencies";
9
+ import { prettyDuration } from "./prettyDuration";
10
+ import { printTestResult } from "./printTestResult";
9
11
 
10
12
  export interface TestProjectOptions {
11
13
  keyPattern?: string;
@@ -38,11 +40,19 @@ export async function testProject(
38
40
  return hasError;
39
41
  }
40
42
 
43
+ const startTime = Date.now();
44
+
41
45
  const patterns = {
42
46
  keyPattern: options.keyPattern ? new RegExp(options.keyPattern) : undefined,
43
47
  assertionPattern: options.assertionPattern ? new RegExp(options.assertionPattern) : undefined,
44
48
  };
45
49
 
50
+ let passedTestsCount = 0;
51
+ let failedTestsCount = 0;
52
+
53
+ let passedAssertionsCount = 0;
54
+ let failedAssertionsCount = 0;
55
+
46
56
  for (const testFile of testFiles) {
47
57
  const testFilePath = datasource.getTestSpecName(testFile);
48
58
 
@@ -56,12 +66,19 @@ export async function testProject(
56
66
  continue;
57
67
  }
58
68
 
59
- console.log(CLI_FORMAT_BOLD, `\nTesting: ${testFilePath.replace(rootDirectoryPath, "")}`);
69
+ const testResult = await testSegment(datasource, test, patterns);
70
+ printTestResult(testResult, testFilePath, rootDirectoryPath);
60
71
 
61
- const segmentHasError = await testSegment(datasource, test, patterns);
62
-
63
- if (segmentHasError) {
72
+ if (!testResult.passed) {
64
73
  hasError = true;
74
+ failedTestsCount++;
75
+
76
+ failedAssertionsCount += testResult.assertions.filter((a) => !a.passed).length;
77
+ passedAssertionsCount += testResult.assertions.length - failedAssertionsCount;
78
+ } else {
79
+ passedTestsCount++;
80
+
81
+ passedAssertionsCount += testResult.assertions.length;
65
82
  }
66
83
  } else if ((t as TestFeature).feature) {
67
84
  // feature testing
@@ -71,12 +88,19 @@ export async function testProject(
71
88
  continue;
72
89
  }
73
90
 
74
- console.log(CLI_FORMAT_BOLD, `\nTesting: ${testFilePath.replace(rootDirectoryPath, "")}`);
91
+ const testResult = await testFeature(datasource, projectConfig, test, options, patterns);
92
+ printTestResult(testResult, testFilePath, rootDirectoryPath);
75
93
 
76
- const featureHasError = await testFeature(datasource, projectConfig, test, options, patterns);
77
-
78
- if (featureHasError) {
94
+ if (!testResult.passed) {
79
95
  hasError = true;
96
+ failedTestsCount++;
97
+
98
+ failedAssertionsCount += testResult.assertions.filter((a) => !a.passed).length;
99
+ passedAssertionsCount += testResult.assertions.length - failedAssertionsCount;
100
+ } else {
101
+ passedTestsCount++;
102
+
103
+ passedAssertionsCount += testResult.assertions.length;
80
104
  }
81
105
  } else {
82
106
  console.error(` => Invalid test: ${JSON.stringify(test)}`);
@@ -84,13 +108,21 @@ export async function testProject(
84
108
  }
85
109
  }
86
110
 
87
- console.log("");
111
+ const diffInMs = Date.now() - startTime;
112
+
113
+ console.log("\n---\n");
114
+
115
+ const testSpecsMessage = `Test specs: ${passedTestsCount} passed, ${failedTestsCount} failed`;
116
+ const testAssertionsMessage = `Assertions: ${passedAssertionsCount} passed, ${failedAssertionsCount} failed`;
88
117
  if (hasError) {
89
- console.log(CLI_FORMAT_RED, `Some tests failed`);
118
+ console.log(CLI_FORMAT_RED, testSpecsMessage);
119
+ console.log(CLI_FORMAT_RED, testAssertionsMessage);
90
120
  } else {
91
- console.log(CLI_FORMAT_GREEN, `All tests passed`);
121
+ console.log(CLI_FORMAT_GREEN, testSpecsMessage);
122
+ console.log(CLI_FORMAT_GREEN, testAssertionsMessage);
92
123
  }
93
- console.log("");
124
+
125
+ console.log(CLI_FORMAT_BOLD, `Time: ${prettyDuration(diffInMs)}`);
94
126
 
95
127
  return hasError;
96
128
  }
@@ -1,29 +1,42 @@
1
- import { TestSegment, Condition } from "@featurevisor/types";
1
+ import {
2
+ TestSegment,
3
+ Condition,
4
+ TestResult,
5
+ TestResultAssertion,
6
+ TestResultAssertionError,
7
+ } from "@featurevisor/types";
2
8
  import { allConditionsAreMatched } from "@featurevisor/sdk";
3
9
 
4
10
  import { Datasource } from "../datasource";
5
11
 
6
- import { CLI_FORMAT_BOLD, CLI_FORMAT_RED } from "./cliFormat";
7
12
  import { getSegmentAssertionsFromMatrix } from "./matrix";
8
13
 
9
14
  export async function testSegment(
10
15
  datasource: Datasource,
11
16
  test: TestSegment,
12
17
  patterns,
13
- ): Promise<boolean> {
14
- let hasError = false;
15
-
18
+ ): Promise<TestResult> {
19
+ const testStartTime = Date.now();
16
20
  const segmentKey = test.segment;
17
21
 
18
- console.log(CLI_FORMAT_BOLD, ` Segment "${segmentKey}":`);
22
+ const testResult: TestResult = {
23
+ type: "segment",
24
+ key: segmentKey,
25
+
26
+ // to be updated later
27
+ notFound: false,
28
+ duration: 0,
29
+ passed: true,
30
+ assertions: [],
31
+ };
19
32
 
20
33
  const segmentExists = await datasource.segmentExists(segmentKey);
21
34
 
22
35
  if (!segmentExists) {
23
- console.error(CLI_FORMAT_RED, ` Segment does not exist: ${segmentKey}`);
24
- hasError = true;
36
+ testResult.notFound = true;
37
+ testResult.passed = false;
25
38
 
26
- return hasError;
39
+ return testResult;
27
40
  }
28
41
 
29
42
  const parsedSegment = await datasource.readSegment(segmentKey);
@@ -33,25 +46,40 @@ export async function testSegment(
33
46
  const assertions = getSegmentAssertionsFromMatrix(aIndex, assertion);
34
47
 
35
48
  assertions.forEach(function (assertion) {
49
+ const assertionStartTime = Date.now();
50
+ const testResultAssertion: TestResultAssertion = {
51
+ description: assertion.description as string,
52
+ duration: 0,
53
+ passed: true,
54
+ errors: [],
55
+ };
56
+
36
57
  if (patterns.assertionPattern && !patterns.assertionPattern.test(assertion.description)) {
37
58
  return;
38
59
  }
39
60
 
40
- console.log(assertion.description);
41
-
42
61
  const expected = assertion.expectedToMatch;
43
62
  const actual = allConditionsAreMatched(conditions, assertion.context);
44
-
45
- if (actual !== expected) {
46
- hasError = true;
47
-
48
- console.error(
49
- CLI_FORMAT_RED,
50
- ` Segment failed: expected "${expected}", got "${actual}"`,
51
- );
63
+ const passed = actual === expected;
64
+
65
+ if (!passed) {
66
+ const testResultAssertionError: TestResultAssertionError = {
67
+ type: "segment",
68
+ expected,
69
+ actual,
70
+ };
71
+
72
+ (testResultAssertion.errors as TestResultAssertionError[]).push(testResultAssertionError);
73
+ testResult.passed = false;
74
+ testResultAssertion.passed = passed;
52
75
  }
76
+
77
+ testResult.assertions.push(testResultAssertion);
78
+ testResultAssertion.duration = Date.now() - assertionStartTime;
53
79
  });
54
80
  });
55
81
 
56
- return hasError;
82
+ testResult.duration = Date.now() - testStartTime;
83
+
84
+ return testResult;
57
85
  }