Skip to content

Commit 59f2e0a

Browse files
Merge pull request #28 from forcedotcom/cristi/debugApex
feat: debugApexTests test in redhat
2 parents ed47653 + 250f007 commit 59f2e0a

File tree

3 files changed

+230
-5
lines changed

3 files changed

+230
-5
lines changed

test/specs/debugApexTests.e2e.ts

+225
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import { step } from 'mocha-steps';
8+
import { TestSetup } from '../testSetup';
9+
import * as utilities from '../utilities/index';
10+
import { TreeItem, after } from 'vscode-extension-tester';
11+
import { expect } from 'chai';
12+
13+
describe('Debug Apex Tests', async () => {
14+
let testSetup: TestSetup;
15+
const testReqConfig: utilities.TestReqConfig = {
16+
projectConfig: {
17+
projectShape: utilities.ProjectShapeOption.NEW
18+
},
19+
isOrgRequired: true,
20+
testSuiteSuffixName: 'DebugApexTests'
21+
};
22+
23+
step('Set up the testing environment', async () => {
24+
utilities.log(`DebugApexTests - Set up the testing environment`);
25+
testSetup = await TestSetup.setUp(testReqConfig);
26+
27+
// Create Apex class 1 and test
28+
try {
29+
await utilities.createApexClassWithTest('ExampleApexClass1');
30+
} catch (error) {
31+
await utilities.createApexClassWithTest('ExampleApexClass1');
32+
}
33+
34+
// Create Apex class 2 and test
35+
try {
36+
await utilities.createApexClassWithTest('ExampleApexClass2');
37+
} catch (error) {
38+
await utilities.createApexClassWithTest('ExampleApexClass2');
39+
}
40+
41+
// Push source to org
42+
await utilities.executeQuickPick(
43+
'SFDX: Push Source to Default Org and Ignore Conflicts',
44+
utilities.Duration.seconds(1)
45+
);
46+
47+
// Look for the success notification that appears which says, "SFDX: Push Source to Default Org and Ignore Conflicts successfully ran".
48+
let successPushNotificationWasFound;
49+
try {
50+
successPushNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
51+
'SFDX: Push Source to Default Org and Ignore Conflicts successfully ran',
52+
utilities.Duration.TEN_MINUTES
53+
);
54+
expect(successPushNotificationWasFound).to.equal(true);
55+
} catch (error) {
56+
await utilities.getWorkbench().openNotificationsCenter();
57+
successPushNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
58+
'SFDX: Push Source to Default Org and Ignore Conflicts successfully ran',
59+
utilities.Duration.TEN_MINUTES
60+
);
61+
expect(successPushNotificationWasFound).to.equal(true);
62+
}
63+
});
64+
65+
step('Verify LSP finished indexing', async () => {
66+
utilities.log(`${testSetup.testSuiteSuffixName} - Verify LSP finished indexing`);
67+
68+
// Get Apex LSP Status Bar
69+
const statusBar = await utilities.getStatusBarItemWhichIncludes('Editor Language Status');
70+
await statusBar.click();
71+
expect(await statusBar.getAttribute('aria-label')).to.contain('Indexing complete');
72+
});
73+
74+
step('Debug All Tests via Apex Class', async () => {
75+
utilities.log(`DebugApexTests - Debug All Tests via Apex Class`);
76+
const workbench = utilities.getWorkbench();
77+
const textEditor = await utilities.getTextEditor(workbench, 'ExampleApexClass1Test.cls');
78+
79+
// Clear the Output view.
80+
await utilities.dismissAllNotifications();
81+
82+
// Click the "Debug All Tests" code lens at the top of the class
83+
const debugAllTestsOption = await textEditor.getCodeLens('Debug All Tests');
84+
await debugAllTestsOption!.click();
85+
await utilities.pause(utilities.Duration.seconds(20));
86+
87+
// Look for the success notification that appears which says, "Debug Test(s) successfully ran".
88+
let successNotificationWasFound;
89+
try {
90+
successNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
91+
'Debug Test(s) successfully ran',
92+
utilities.Duration.TEN_MINUTES
93+
);
94+
expect(successNotificationWasFound).to.equal(true);
95+
} catch (error) {
96+
await workbench.openNotificationsCenter();
97+
successNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
98+
'Debug Test(s) successfully ran',
99+
utilities.Duration.ONE_MINUTE
100+
);
101+
expect(successNotificationWasFound).to.equal(true);
102+
}
103+
104+
// Continue with the debug session
105+
await utilities.continueDebugging(2, 30);
106+
});
107+
108+
step('Debug Single Test via Apex Class', async () => {
109+
utilities.log(`DebugApexTests - Debug Single Test via Apex Class`);
110+
const workbench = utilities.getWorkbench();
111+
const textEditor = await utilities.getTextEditor(workbench, 'ExampleApexClass2Test.cls');
112+
113+
// Clear the Output view.
114+
await utilities.dismissAllNotifications();
115+
116+
// Click the "Debug Test" code lens at the top of one of the test methods
117+
const debugTestOption = await textEditor.getCodeLens('Debug Test');
118+
await debugTestOption!.click();
119+
await utilities.pause(utilities.Duration.seconds(20));
120+
121+
// Look for the success notification that appears which says, "Debug Test(s) successfully ran".
122+
let successNotificationWasFound;
123+
try {
124+
successNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
125+
'Debug Test(s) successfully ran',
126+
utilities.Duration.TEN_MINUTES
127+
);
128+
expect(successNotificationWasFound).to.equal(true);
129+
} catch (error) {
130+
await workbench.openNotificationsCenter();
131+
successNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
132+
'Debug Test(s) successfully ran',
133+
utilities.Duration.ONE_MINUTE
134+
);
135+
expect(successNotificationWasFound).to.equal(true);
136+
}
137+
138+
// Continue with the debug session
139+
await utilities.continueDebugging(2, 30);
140+
});
141+
142+
step('Debug all Apex Methods on a Class via the Test Sidebar', async () => {
143+
utilities.log(`DebugApexTests - Debug All Apex Methods on a Class via the Test Sidebar`);
144+
const workbench = utilities.getWorkbench();
145+
await utilities.executeQuickPick('Testing: Focus on Apex Tests View', utilities.Duration.seconds(1));
146+
147+
// Open the Test Sidebar
148+
const apexTestsSection = await utilities.getTestsSection(workbench, 'Apex Tests');
149+
const expectedItems = ['ExampleApexClass1Test', 'ExampleApexClass2Test'];
150+
151+
await utilities.verifyTestItemsInSideBar(apexTestsSection, 'Refresh Tests', expectedItems, 4, 2);
152+
153+
// Click the debug tests button that is shown to the right when you hover a test class name on the Test sidebar
154+
await apexTestsSection.click();
155+
const apexTestItem = (await apexTestsSection.findItem('ExampleApexClass1Test')) as TreeItem;
156+
await apexTestItem.select();
157+
const debugTestsAction = await apexTestItem.getActionButton('Debug Tests');
158+
expect(debugTestsAction).to.not.be.undefined;
159+
await debugTestsAction?.click();
160+
await utilities.pause(utilities.Duration.seconds(20));
161+
162+
// Look for the success notification that appears which says, "Debug Test(s) successfully ran".
163+
let successNotificationWasFound;
164+
try {
165+
successNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
166+
'Debug Test(s) successfully ran',
167+
utilities.Duration.TEN_MINUTES
168+
);
169+
expect(successNotificationWasFound).to.equal(true);
170+
} catch (error) {
171+
await workbench.openNotificationsCenter();
172+
successNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
173+
'Debug Test(s) successfully ran',
174+
utilities.Duration.ONE_MINUTE
175+
);
176+
expect(successNotificationWasFound).to.equal(true);
177+
}
178+
179+
// Continue with the debug session
180+
await utilities.continueDebugging(2, 30);
181+
});
182+
183+
step('Debug a Single Apex Test Method via the Test Sidebar', async () => {
184+
utilities.log(`DebugApexTests - 'Debug Single Apex Test Method via the Test Sidebar`);
185+
const workbench = utilities.getWorkbench();
186+
await utilities.executeQuickPick('Testing: Focus on Apex Tests View', utilities.Duration.seconds(1));
187+
188+
// Open the Test Sidebar
189+
const apexTestsSection = await utilities.getTestsSection(workbench, 'Apex Tests');
190+
191+
// Hover a test name under one of the test class sections and click the debug button that is shown to the right of the test name on the Test sidebar
192+
await apexTestsSection.click();
193+
const apexTestItem = (await apexTestsSection.findItem('validateSayHello')) as TreeItem;
194+
await apexTestItem.select();
195+
const debugTestAction = await apexTestItem.getActionButton('Debug Single Test');
196+
expect(debugTestAction).to.not.be.undefined;
197+
await debugTestAction?.click();
198+
await utilities.pause(utilities.Duration.seconds(20));
199+
200+
// Look for the success notification that appears which says, "Debug Test(s) successfully ran".
201+
let successNotificationWasFound;
202+
try {
203+
successNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
204+
'Debug Test(s) successfully ran',
205+
utilities.Duration.TEN_MINUTES
206+
);
207+
expect(successNotificationWasFound).to.equal(true);
208+
} catch (error) {
209+
await workbench.openNotificationsCenter();
210+
successNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
211+
'Debug Test(s) successfully ran',
212+
utilities.Duration.ONE_MINUTE
213+
);
214+
expect(successNotificationWasFound).to.equal(true);
215+
}
216+
217+
// Continue with the debug session
218+
await utilities.continueDebugging(2, 30);
219+
});
220+
221+
after('Tear down and clean up the testing environment', async () => {
222+
utilities.log(`DebugApexTests - Tear down and clean up the testing environment`);
223+
await testSetup?.tearDown();
224+
});
225+
});

test/specs/runApexTests.e2e.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('Run Apex Tests', async () => {
6464
await utilities.getWorkbench().openNotificationsCenter();
6565
successPushNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
6666
'SFDX: Push Source to Default Org and Ignore Conflicts successfully ran',
67-
utilities.Duration.TEN_MINUTES
67+
utilities.Duration.ONE_MINUTE
6868
);
6969
expect(successPushNotificationWasFound).to.equal(true);
7070
}
@@ -403,7 +403,7 @@ describe('Run Apex Tests', async () => {
403403
await utilities.getWorkbench().openNotificationsCenter();
404404
successPushNotificationWasFound = await utilities.notificationIsPresentWithTimeout(
405405
'SFDX: Push Source to Default Org and Ignore Conflicts successfully ran',
406-
utilities.Duration.TEN_MINUTES
406+
utilities.Duration.ONE_MINUTE
407407
);
408408
expect(successPushNotificationWasFound).to.equal(true);
409409
}
@@ -467,7 +467,7 @@ describe('Run Apex Tests', async () => {
467467
await utilities.getWorkbench().openNotificationsCenter();
468468
successPushNotification2WasFound = await utilities.notificationIsPresentWithTimeout(
469469
'SFDX: Push Source to Default Org and Ignore Conflicts successfully ran',
470-
utilities.Duration.TEN_MINUTES
470+
utilities.Duration.ONE_MINUTE
471471
);
472472
expect(successPushNotification2WasFound).to.equal(true);
473473
}

test/utilities/testUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ export async function verifyTestItemsInSideBar(
174174
return testsItems;
175175
}
176176

177-
export async function continueDebugging(times: number): Promise<void> {
177+
export async function continueDebugging(times: number, seconds = 5): Promise<void> {
178178
const bar = await DebugToolbar.create();
179179
// Continue with the debug session
180180
for (let i = 0; i < times; i++) {
181181
await bar.continue();
182-
await pause(Duration.seconds(5));
182+
await pause(Duration.seconds(seconds));
183183
}
184184
}

0 commit comments

Comments
 (0)