dididy commented on code in PR #5072:
URL: https://github.com/apache/zeppelin/pull/5072#discussion_r2362561993


##########
zeppelin-web-angular/e2e/reporter.coverage.ts:
##########
@@ -0,0 +1,304 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// @see https://playwright.dev/docs/test-reporters#custom-reporters
+import { FullResult, Reporter, TestCase, TestResult } from 
'@playwright/test/reporter';
+import { promises as fs } from 'fs';
+import { flatMap, sortBy } from 'lodash';
+import { scanDirectory, Results } from 'scandirectory';
+import cfg from './reporter.coverage.config';
+
+const TEST_STATUS = {
+  PASSED: 'passed',
+  SKIPPED: 'skipped',
+  FAILED: 'failed'
+} as const;
+
+type ResultsType = Array<[string, number, number, number, number, number]>;
+type TestStatusType = typeof TEST_STATUS[keyof typeof TEST_STATUS];
+interface TestedPathType {
+  success: number;
+  skipped: number;
+  failed: number;
+}
+
+const OUTPUT_FILE_NAME = 'coverage.log';
+const TABLE_COLUMNS = {
+  TOTAL: 1,
+  SUCCESS: 2,
+  FAILED: 3,
+  SKIPPED: 4
+} as const;
+
+class CoverageReporter implements Reporter {
+  testedPaths = new Map<string, TestedPathType>();
+  testedIds = new Map<string, TestStatusType>();
+  targetPaths: string[] = [];
+
+  async onBegin() {
+    console.log('Coverage reporter starting...');
+    console.log('Root path:', cfg.rootPath);
+
+    const results = await scanDirectory({
+      directory: cfg.rootPath
+    });
+
+    this.targetPaths = this.processScannedFiles(results);
+    console.log('Target paths:', this.targetPaths.length);
+  }
+
+  processScannedFiles(results: Results): string[] {
+    return Object.keys(results)
+      .filter(key => !results[key].directory)
+      .map(key => this.normalizeFilePath(key, results))
+      .filter(key => key !== '.')
+      .filter(key => this.shouldIncludeFile(key));
+  }
+
+  normalizeFilePath(key: string, results: Results): string {
+    if (/index\.tsx?$/.test(key)) {
+      return results[key].parent?.relativePath || '.';
+    }
+    return key.replace(/\.tsx?$/, '');
+  }
+
+  shouldIncludeFile(key: string): boolean {
+    if (cfg.testMatch?.length) {
+      const matchesTest = cfg.testMatch.some(rule => (rule instanceof RegExp ? 
rule.test(key) : rule === key));
+      if (!matchesTest) {
+        return false;
+      }
+    }
+
+    if (cfg.excludes?.length) {
+      const isExcluded = cfg.excludes.some(rule => (rule instanceof RegExp ? 
rule.test(key) : rule === key));
+      if (isExcluded) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  onTestEnd(test: TestCase, result: TestResult) {
+    const status =
+      result.status === TEST_STATUS.PASSED || result.status === 
TEST_STATUS.SKIPPED
+        ? (result.status as TestStatusType)

Review Comment:
   Thanks for the thorough review — I’ve applied the feedback. Let me know if I 
missed anything or if further changes are needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to