@@ -9,9 +9,10 @@ import { qTestingFramework } from './framework/framework'
9
9
import sinon from 'sinon'
10
10
import { Messenger } from './framework/messenger'
11
11
import { FollowUpTypes } from 'aws-core-vscode/amazonq'
12
- import { registerAuthHook , using , TestFolder , closeAllEditors } from 'aws-core-vscode/test'
12
+ import { registerAuthHook , using , TestFolder , closeAllEditors , getTestWorkspaceFolder } from 'aws-core-vscode/test'
13
13
import { loginToIdC } from './utils/setup'
14
14
import { waitUntil , workspaceUtils } from 'aws-core-vscode/shared'
15
+ import * as path from 'path'
15
16
16
17
describe ( 'Amazon Q Test Generation' , function ( ) {
17
18
let framework : qTestingFramework
@@ -20,11 +21,13 @@ describe('Amazon Q Test Generation', function () {
20
21
const testFiles = [
21
22
{
22
23
language : 'python' ,
23
- filePath : 'python3.7-image-sam-app/hello_world/app.py' ,
24
+ filePath : 'testGenFolder/src/main/math.py' ,
25
+ testFilePath : 'testGenFolder/src/test/test_math.py' ,
24
26
} ,
25
27
{
26
28
language : 'java' ,
27
- filePath : 'java17-gradle/HelloWorldFunction/src/main/java/helloworld/App.java' ,
29
+ filePath : 'testGenFolder/src/main/Math.java' ,
30
+ testFilePath : 'testGenFolder/src/test/MathTest.java' ,
28
31
} ,
29
32
]
30
33
@@ -33,14 +36,15 @@ describe('Amazon Q Test Generation', function () {
33
36
// must be atleast one unsupported language here for testing
34
37
{
35
38
language : 'typescript' ,
36
- filePath : 'ts-plain-sam-app /src/app .ts' ,
39
+ filePath : 'testGenFolder /src/main/math .ts' ,
37
40
} ,
38
41
{
39
42
language : 'javascript' ,
40
- filePath : 'js-plain-sam-app /src/app .js' ,
43
+ filePath : 'testGenFolder /src/main/math .js' ,
41
44
} ,
42
45
]
43
46
47
+ // handles opening the file since /test must be called on an active file
44
48
async function setupTestDocument ( filePath : string , language : string ) {
45
49
const document = await waitUntil ( async ( ) => {
46
50
const doc = await workspaceUtils . openTextDocument ( filePath )
@@ -57,7 +61,7 @@ describe('Amazon Q Test Generation', function () {
57
61
58
62
const activeEditor = vscode . window . activeTextEditor
59
63
if ( ! activeEditor || activeEditor . document . uri . fsPath !== document . uri . fsPath ) {
60
- assert . fail ( `Failed to make temp file active` )
64
+ assert . fail ( `Failed to make ${ language } file active` )
61
65
}
62
66
}
63
67
@@ -68,6 +72,15 @@ describe('Amazon Q Test Generation', function () {
68
72
} )
69
73
}
70
74
75
+ // clears test file to a blank file
76
+ // not cleaning up test file may possibly cause bloat in CI since testFixtures does not get reset
77
+ async function cleanupTestFile ( testFilePath : string ) {
78
+ const workspaceFolder = getTestWorkspaceFolder ( )
79
+ const absoluteTestFilePath = path . join ( workspaceFolder , testFilePath )
80
+ const testFileUri = vscode . Uri . file ( absoluteTestFilePath )
81
+ await vscode . workspace . fs . writeFile ( testFileUri , Buffer . from ( '' , 'utf-8' ) )
82
+ }
83
+
71
84
before ( async function ( ) {
72
85
await using( registerAuthHook ( 'amazonq-test-account' ) , async ( ) => {
73
86
await loginToIdC ( )
@@ -112,7 +125,7 @@ describe('Amazon Q Test Generation', function () {
112
125
} )
113
126
114
127
describe ( '/test entry' , ( ) => {
115
- describe ( 'Unsupported language' , ( ) => {
128
+ describe ( 'Unsupported language file ' , ( ) => {
116
129
const { language, filePath } = unsupportedLanguages [ 0 ]
117
130
118
131
beforeEach ( async ( ) => {
@@ -134,13 +147,13 @@ describe('Amazon Q Test Generation', function () {
134
147
} )
135
148
} )
136
149
137
- describe ( 'External file' , async ( ) => {
150
+ describe ( 'External file out of project ' , async ( ) => {
138
151
let testFolder : TestFolder
139
152
let fileName : string
140
153
141
154
beforeEach ( async ( ) => {
142
155
testFolder = await TestFolder . create ( )
143
- fileName = 'test .py'
156
+ fileName = 'math .py'
144
157
const filePath = await testFolder . write ( fileName , 'def add(a, b): return a + b' )
145
158
146
159
const document = await vscode . workspace . openTextDocument ( filePath )
@@ -162,10 +175,8 @@ describe('Amazon Q Test Generation', function () {
162
175
} )
163
176
} )
164
177
165
- for ( const { language, filePath } of testFiles ) {
166
- // skipping for now since this test is flaky. passes locally, but only half the time in CI
167
- // have tried retries for setupTestDocument, openTextDocument, and showTextDocument
168
- describe . skip ( `${ language } file` , ( ) => {
178
+ for ( const { language, filePath, testFilePath } of testFiles ) {
179
+ describe ( `/test on ${ language } file` , ( ) => {
169
180
beforeEach ( async ( ) => {
170
181
await waitUntil ( async ( ) => await setupTestDocument ( filePath , language ) , { } )
171
182
@@ -177,7 +188,7 @@ describe('Amazon Q Test Generation', function () {
177
188
await tab . waitForChatFinishesLoading ( )
178
189
} )
179
190
180
- describe ( 'View diff' , async ( ) => {
191
+ describe ( 'View diff of test file ' , async ( ) => {
181
192
it ( 'Clicks on view diff' , async ( ) => {
182
193
const chatItems = tab . getChatItems ( )
183
194
const viewDiffMessage = chatItems [ 5 ]
@@ -190,7 +201,14 @@ describe('Amazon Q Test Generation', function () {
190
201
} )
191
202
} )
192
203
193
- describe ( 'Accept code' , async ( ) => {
204
+ describe ( 'Accept unit tests' , async ( ) => {
205
+ afterEach ( async ( ) => {
206
+ // this e2e test generates unit tests, so we want to clean them up after this test is done
207
+ await waitUntil ( async ( ) => {
208
+ await cleanupTestFile ( testFilePath )
209
+ } , { } )
210
+ } )
211
+
194
212
it ( 'Clicks on accept' , async ( ) => {
195
213
await tab . waitForButtons ( [ FollowUpTypes . AcceptCode , FollowUpTypes . RejectCode ] )
196
214
tab . clickButton ( FollowUpTypes . AcceptCode )
@@ -204,7 +222,7 @@ describe('Amazon Q Test Generation', function () {
204
222
} )
205
223
} )
206
224
207
- describe ( 'Reject code ' , async ( ) => {
225
+ describe ( 'Reject unit tests ' , async ( ) => {
208
226
it ( 'Clicks on reject' , async ( ) => {
209
227
await tab . waitForButtons ( [ FollowUpTypes . AcceptCode , FollowUpTypes . RejectCode ] )
210
228
tab . clickButton ( FollowUpTypes . RejectCode )
0 commit comments