-
Notifications
You must be signed in to change notification settings - Fork 749
test(amazonq): add skipped test report generator #6540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,117 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * Scans test files for skipped Mocha tests. | ||
| * | ||
| * It uses a regex instead of mocha's loader, because mocha's | ||
| * loader can't resolve vscode by default | ||
| * | ||
| * Note: This script doesn't handle cases where teams use this.skip() inside of their tests | ||
| * | ||
| * Usage: node skippedTestReport.js <directoryPath> | ||
| */ | ||
|
|
||
| import * as fs from 'fs' | ||
| import * as path from 'path' | ||
|
|
||
| interface SkippedTest { | ||
| file: string | ||
| testName: string | ||
| lineNumber: number | ||
| } | ||
|
|
||
| function findSkippedTests(directoryPath: string): SkippedTest[] { | ||
| const skippedTests: SkippedTest[] = [] | ||
|
|
||
| const skipPatterns = [/\b(describe|it)\.skip\(['"`](.*?)['"`]/g] | ||
|
|
||
| function searchInFile(filePath: string): void { | ||
| try { | ||
| const content = fs.readFileSync(filePath, 'utf8') | ||
| const lines = content.split('\n') | ||
|
|
||
| lines.forEach((line, index) => { | ||
| for (const pattern of skipPatterns) { | ||
| const matches = line.matchAll(pattern) | ||
| for (const match of matches) { | ||
| skippedTests.push({ | ||
| file: filePath, | ||
| testName: match[2], | ||
| lineNumber: index + 1, | ||
| }) | ||
| } | ||
| } | ||
| }) | ||
| } catch (error) { | ||
| console.error(`Error reading file ${filePath}:`, error) | ||
| } | ||
| } | ||
|
|
||
| function visitDirectory(currentPath: string): void { | ||
| const files = fs.readdirSync(currentPath) | ||
|
|
||
| files.forEach((file) => { | ||
| const fullPath = path.join(currentPath, file) | ||
| const stat = fs.statSync(fullPath) | ||
|
|
||
| if (stat.isDirectory()) { | ||
| // Skip hidden directories | ||
| if (!file.startsWith('.')) { | ||
| visitDirectory(fullPath) | ||
| } | ||
| } else if (stat.isFile() && file.endsWith('.ts')) { | ||
| searchInFile(fullPath) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| visitDirectory(directoryPath) | ||
| return skippedTests | ||
| } | ||
|
|
||
| function main() { | ||
| const targetDirectory = process.argv[2] || '.' | ||
|
|
||
| try { | ||
| const skippedTests = findSkippedTests(targetDirectory) | ||
|
|
||
| if (skippedTests.length === 0) { | ||
| console.log('No skipped tests found.') | ||
| return | ||
| } | ||
|
|
||
| const testsByFile = skippedTests.reduce( | ||
| (acc, test) => { | ||
| const file = test.file | ||
| if (!acc[file]) { | ||
| acc[file] = [] | ||
| } | ||
| acc[file].push(test) | ||
| return acc | ||
| }, | ||
| {} as Record<string, SkippedTest[]> | ||
| ) | ||
|
|
||
| console.log('\nSkipped Tests Report') | ||
| console.log(`Total skipped tests: ${skippedTests.length}`) | ||
| console.log(`Files affected: ${Object.keys(testsByFile).length}`) | ||
| console.log('===================\n') | ||
|
|
||
| Object.entries(testsByFile).forEach(([file, tests]) => { | ||
| console.log(`📁 ${file}`) | ||
| console.log(' Skipped tests:') | ||
| tests.forEach((test) => { | ||
| console.log(` • ${test.testName} (line ${test.lineNumber})`) | ||
| }) | ||
| console.log('') | ||
| }) | ||
| } catch (error) { | ||
| console.error('Error:', error) | ||
| process.exit(1) | ||
| } | ||
| } | ||
|
|
||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something like
aws-toolkit-vscode/packages/core/src/test/codecatalyst/uriHandlers.test.ts
Lines 122 to 137 in 29c4048
I can't think of a good solution here since it can be conditionally skipped or always skipped via
this.skip. Do you think its worth including these as a separate "conditionally skipped"?Either approach seems fine, but could be worth documenting that in this script.