Skip to content

Commit 99eefe0

Browse files
authored
test(amazonq): add skipped test report generator (#6540)
## Problem This scripts creates a report of skipped tests in the amazon q folder ## Solution Run: `npm run skippedTestReport` ``` Skipped Tests Report Total skipped tests: 5 Files affected: 4 =================== 📁 packages/amazonq/test/e2e/amazonq/featureDev.test.ts Skipped tests: • /dev {msg} entry (line 165) • file-level accepts (line 220) 📁 packages/amazonq/test/e2e/amazonq/template.test.ts Skipped tests: • Amazon Q Test Template (line 16) 📁 packages/amazonq/test/e2e/amazonq/testGen.test.ts Skipped tests: • ${language} file (line 168) 📁 packages/amazonq/test/e2e/amazonq/transformByQ.test.ts Skipped tests: • Running a Java upgrade from start to finish (line 345) ``` --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f781fc9 commit 99eefe0

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-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.296",

scripts/skippedTestReport.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
* Note: This script doesn't handle cases where teams use this.skip() inside of their tests
13+
*
14+
* Usage: node skippedTestReport.js <directoryPath>
15+
*/
16+
17+
import * as fs from 'fs'
18+
import * as path from 'path'
19+
20+
interface SkippedTest {
21+
file: string
22+
testName: string
23+
lineNumber: number
24+
}
25+
26+
function findSkippedTests(directoryPath: string): SkippedTest[] {
27+
const skippedTests: SkippedTest[] = []
28+
29+
const skipPatterns = [/\b(describe|it)\.skip\(['"`](.*?)['"`]/g]
30+
31+
function searchInFile(filePath: string): void {
32+
try {
33+
const content = fs.readFileSync(filePath, 'utf8')
34+
const lines = content.split('\n')
35+
36+
lines.forEach((line, index) => {
37+
for (const pattern of skipPatterns) {
38+
const matches = line.matchAll(pattern)
39+
for (const match of matches) {
40+
skippedTests.push({
41+
file: filePath,
42+
testName: match[2],
43+
lineNumber: index + 1,
44+
})
45+
}
46+
}
47+
})
48+
} catch (error) {
49+
console.error(`Error reading file ${filePath}:`, error)
50+
}
51+
}
52+
53+
function visitDirectory(currentPath: string): void {
54+
const files = fs.readdirSync(currentPath)
55+
56+
files.forEach((file) => {
57+
const fullPath = path.join(currentPath, file)
58+
const stat = fs.statSync(fullPath)
59+
60+
if (stat.isDirectory()) {
61+
// Skip hidden directories
62+
if (!file.startsWith('.')) {
63+
visitDirectory(fullPath)
64+
}
65+
} else if (stat.isFile() && file.endsWith('.ts')) {
66+
searchInFile(fullPath)
67+
}
68+
})
69+
}
70+
71+
visitDirectory(directoryPath)
72+
return skippedTests
73+
}
74+
75+
function main() {
76+
const targetDirectory = process.argv[2] || '.'
77+
78+
try {
79+
const skippedTests = findSkippedTests(targetDirectory)
80+
81+
if (skippedTests.length === 0) {
82+
console.log('No skipped tests found.')
83+
return
84+
}
85+
86+
const testsByFile = skippedTests.reduce(
87+
(acc, test) => {
88+
const file = test.file
89+
if (!acc[file]) {
90+
acc[file] = []
91+
}
92+
acc[file].push(test)
93+
return acc
94+
},
95+
{} as Record<string, SkippedTest[]>
96+
)
97+
98+
console.log('\nSkipped Tests Report')
99+
console.log(`Total skipped tests: ${skippedTests.length}`)
100+
console.log(`Files affected: ${Object.keys(testsByFile).length}`)
101+
console.log('===================\n')
102+
103+
Object.entries(testsByFile).forEach(([file, tests]) => {
104+
console.log(`📁 ${file}`)
105+
console.log(' Skipped tests:')
106+
tests.forEach((test) => {
107+
console.log(` • ${test.testName} (line ${test.lineNumber})`)
108+
})
109+
console.log('')
110+
})
111+
} catch (error) {
112+
console.error('Error:', error)
113+
process.exit(1)
114+
}
115+
}
116+
117+
main()

0 commit comments

Comments
 (0)