Skip to content

Commit

Permalink
E2E test: create test summary text python script (#6101)
Browse files Browse the repository at this point in the history
npm run e2e-summary

Dump out all the test case titles according to the file and folder they
live in.


### QA Notes

No affect on tests
  • Loading branch information
testlabauto authored Jan 23, 2025
1 parent efce85a commit 7bfaf75
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"e2e-pr": "npx playwright test --project e2e-electron --grep @:critical",
"e2e-win": "npx playwright test --project e2e-electron --grep @:win",
"e2e-failed": "npx playwright test --last-failed",
"e2e-summary": "python test/e2e/create-test-summary.py test/e2e/tests",
"e2e-ui": "PW_UI_MODE=true npx playwright test --ui",
"download-builtin-extensions": "node build/lib/builtInExtensions.js",
"download-builtin-extensions-cg": "node build/lib/builtInExtensionsCG.js",
Expand Down
54 changes: 54 additions & 0 deletions test/e2e/create-test-summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import re
import sys

def list_files_and_extract_tests(tests_dir):
if not os.path.exists(tests_dir) or not os.path.isdir(tests_dir):
print(f"Directory '{tests_dir}' not found.")
return

test_pattern = re.compile(r'test\(["\'](.+?)["\']') # Regex to extract test descriptions
text_extensions = {".ts"} # Allowed file extensions
test_count = 0 # Counter for test cases

# Iterate over subdirectories in tests/
for subdir in sorted(os.listdir(tests_dir)):
subdir_path = os.path.join(tests_dir, subdir)

# Ensure it's a directory
if os.path.isdir(subdir_path):
files = sorted(f for f in os.listdir(subdir_path) if os.path.isfile(os.path.join(subdir_path, f)))

# Print header for subdirectory
if files:
print(subdir)

# Process each file in the subdirectory
for file in files:
file_path = os.path.join(subdir_path, file)

# Skip non-text files (e.g., PNG, JPG, etc.)
if not any(file.lower().endswith(ext) for ext in text_extensions):
continue

print(f" {file}") # Indented filename

# Read file and extract test descriptions
try:
with open(file_path, "r", encoding="utf-8") as f:
for line in f:
match = test_pattern.search(line)
if match:
print(f" {match.group(1)}") # Indent test description
test_count += 1 # Increment test counter
except UnicodeDecodeError:
print(f" [Skipping: Cannot read file {file}]") # Inform about skipped files
print() # Blank line for separation

# Print total test count
print(f"Total test cases found: {test_count}")

if __name__ == "__main__":
# Get directory argument or use default
tests_dir = sys.argv[1] if len(sys.argv) > 1 else "tests"
list_files_and_extract_tests(tests_dir)

0 comments on commit 7bfaf75

Please sign in to comment.