Skip to content

Commit dcbe34c

Browse files
committed
tests(amazonq): add skipped test report generator
1 parent 53f11e7 commit dcbe34c

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"clean": "npm run clean -w packages/ -w plugins/",
3838
"reset": "npm run clean && ts-node ./scripts/clean.ts node_modules && npm install",
3939
"generateNonCodeFiles": "npm run generateNonCodeFiles -w packages/ --if-present",
40-
"mergeReports": "ts-node ./scripts/mergeReports.ts"
40+
"mergeReports": "ts-node ./scripts/mergeReports.ts",
41+
"skippedTestReport": "ts-node ./scripts/skippedTestReport.ts ./packages/amazonq/test/e2e/"
4142
},
4243
"devDependencies": {
4344
"@aws-toolkits/telemetry": "^1.0.295",

scripts/skippedTestReport.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* Scans test files for skipped Mocha tests.
8+
*
9+
* It uses a regex instead of mocha's loader, because mocha's
10+
* loader can't resolve vscode by default
11+
*/
12+
13+
import * as fs from 'fs'
14+
import * as path from 'path'
15+
16+
interface SkippedTest {
17+
file: string
18+
testName: string
19+
lineNumber: number
20+
}
21+
22+
function findSkippedTests(directoryPath: string): SkippedTest[] {
23+
const skippedTests: SkippedTest[] = []
24+
25+
const skipPatterns = [/\b(describe|it)\.skip\(['"`](.*?)['"`]/g]
26+
27+
function searchInFile(filePath: string): void {
28+
try {
29+
const content = fs.readFileSync(filePath, 'utf8')
30+
const lines = content.split('\n')
31+
32+
lines.forEach((line, index) => {
33+
for (const pattern of skipPatterns) {
34+
const matches = line.matchAll(pattern)
35+
for (const match of matches) {
36+
skippedTests.push({
37+
file: filePath,
38+
testName: match[2],
39+
lineNumber: index + 1,
40+
})
41+
}
42+
}
43+
})
44+
} catch (error) {
45+
console.error(`Error reading file ${filePath}:`, error)
46+
}
47+
}
48+
49+
function visitDirectory(currentPath: string): void {
50+
const files = fs.readdirSync(currentPath)
51+
52+
files.forEach((file) => {
53+
const fullPath = path.join(currentPath, file)
54+
const stat = fs.statSync(fullPath)
55+
56+
if (stat.isDirectory()) {
57+
// Skip hidden directories
58+
if (!file.startsWith('.')) {
59+
visitDirectory(fullPath)
60+
}
61+
} else if (stat.isFile() && file.endsWith('.ts')) {
62+
searchInFile(fullPath)
63+
}
64+
})
65+
}
66+
67+
visitDirectory(directoryPath)
68+
return skippedTests
69+
}
70+
71+
function main() {
72+
const targetDirectory = process.argv[2] || '.'
73+
74+
try {
75+
const skippedTests = findSkippedTests(targetDirectory)
76+
77+
if (skippedTests.length === 0) {
78+
console.log('No skipped tests found.')
79+
return
80+
}
81+
82+
const testsByFile = skippedTests.reduce(
83+
(acc, test) => {
84+
const file = test.file
85+
if (!acc[file]) {
86+
acc[file] = []
87+
}
88+
acc[file].push(test)
89+
return acc
90+
},
91+
{} as Record<string, SkippedTest[]>
92+
)
93+
94+
console.log('\nSkipped Tests Report')
95+
console.log(`Total skipped tests: ${skippedTests.length}`)
96+
console.log(`Files affected: ${Object.keys(testsByFile).length}`)
97+
console.log('===================\n')
98+
99+
Object.entries(testsByFile).forEach(([file, tests]) => {
100+
console.log(`📁 ${file}`)
101+
console.log(' Skipped tests:')
102+
tests.forEach((test) => {
103+
console.log(` • ${test.testName} (line ${test.lineNumber})`)
104+
})
105+
console.log('')
106+
})
107+
} catch (error) {
108+
console.error('Error:', error)
109+
process.exit(1)
110+
}
111+
}
112+
113+
main()

0 commit comments

Comments
 (0)