-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E test: create test summary text python script (#6101)
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
1 parent
efce85a
commit 7bfaf75
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |