@@ -16,6 +16,9 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
16
16
} ) ;
17
17
18
18
jestLib . beforeEach ( async function ( ) {
19
+ vscode . workspace
20
+ . getConfiguration ( )
21
+ . update ( 'dotnet.unitTests.runSettingsPath' , undefined , vscode . ConfigurationTarget . Workspace ) ;
19
22
const fileName = path . join ( 'test' , 'UnitTest1.cs' ) ;
20
23
await openFileInWorkspaceAsync ( fileName ) ;
21
24
} ) ;
@@ -26,9 +29,10 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
26
29
27
30
jestLib . test ( 'Unit test code lens items are displayed' , async ( ) => {
28
31
const codeLenses = await getCodeLensesAsync ( ) ;
29
- jestLib . expect ( codeLenses ) . toHaveLength ( 6 ) ;
32
+ jestLib . expect ( codeLenses ) . toHaveLength ( 9 ) ;
30
33
31
34
const classRange = new vscode . Range ( new vscode . Position ( 5 , 17 ) , new vscode . Position ( 5 , 26 ) ) ;
35
+
32
36
// Class level debug all tests
33
37
jestLib . expect ( codeLenses [ 1 ] . command ?. command ) . toBe ( 'dotnet.test.run' ) ;
34
38
jestLib . expect ( codeLenses [ 1 ] . command ?. title ) . toBe ( 'Debug All Tests' ) ;
@@ -41,23 +45,31 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
41
45
jestLib . expect ( codeLenses [ 2 ] . command ?. arguments ! [ 0 ] . attachDebugger ) . toBe ( false ) ;
42
46
jestLib . expect ( codeLenses [ 2 ] . range ) . toStrictEqual ( classRange ) ;
43
47
44
- const methodRange = new vscode . Range ( new vscode . Position ( 8 , 20 ) , new vscode . Position ( 8 , 25 ) ) ;
45
- // Method level debug test
48
+ let methodRange = new vscode . Range ( new vscode . Position ( 8 , 20 ) , new vscode . Position ( 8 , 25 ) ) ;
49
+ // Method level run and debug test
46
50
jestLib . expect ( codeLenses [ 4 ] . command ?. command ) . toBe ( 'dotnet.test.run' ) ;
47
51
jestLib . expect ( codeLenses [ 4 ] . command ?. title ) . toBe ( 'Debug Test' ) ;
48
52
jestLib . expect ( codeLenses [ 4 ] . command ?. arguments ! [ 0 ] . attachDebugger ) . toBe ( true ) ;
49
53
jestLib . expect ( codeLenses [ 4 ] . range ) . toStrictEqual ( methodRange ) ;
50
-
51
- // Method level run test
52
54
jestLib . expect ( codeLenses [ 5 ] . command ?. command ) . toBe ( 'dotnet.test.run' ) ;
53
55
jestLib . expect ( codeLenses [ 5 ] . command ?. title ) . toBe ( 'Run Test' ) ;
54
56
jestLib . expect ( codeLenses [ 5 ] . command ?. arguments ! [ 0 ] . attachDebugger ) . toBe ( false ) ;
55
57
jestLib . expect ( codeLenses [ 5 ] . range ) . toStrictEqual ( methodRange ) ;
58
+
59
+ methodRange = new vscode . Range ( new vscode . Position ( 15 , 20 ) , new vscode . Position ( 15 , 25 ) ) ;
60
+ jestLib . expect ( codeLenses [ 7 ] . command ?. command ) . toBe ( 'dotnet.test.run' ) ;
61
+ jestLib . expect ( codeLenses [ 7 ] . command ?. title ) . toBe ( 'Debug Test' ) ;
62
+ jestLib . expect ( codeLenses [ 7 ] . command ?. arguments ! [ 0 ] . attachDebugger ) . toBe ( true ) ;
63
+ jestLib . expect ( codeLenses [ 7 ] . range ) . toStrictEqual ( methodRange ) ;
64
+ jestLib . expect ( codeLenses [ 8 ] . command ?. command ) . toBe ( 'dotnet.test.run' ) ;
65
+ jestLib . expect ( codeLenses [ 8 ] . command ?. title ) . toBe ( 'Run Test' ) ;
66
+ jestLib . expect ( codeLenses [ 8 ] . command ?. arguments ! [ 0 ] . attachDebugger ) . toBe ( false ) ;
67
+ jestLib . expect ( codeLenses [ 8 ] . range ) . toStrictEqual ( methodRange ) ;
56
68
} ) ;
57
69
58
70
jestLib . test ( 'Code lens command executes tests' , async ( ) => {
59
71
const codeLenses = await getCodeLensesAsync ( ) ;
60
- jestLib . expect ( codeLenses ) . toHaveLength ( 6 ) ;
72
+ jestLib . expect ( codeLenses ) . toHaveLength ( 9 ) ;
61
73
62
74
const runAllTestsCommand = codeLenses [ 2 ] . command ! ;
63
75
jestLib . expect ( runAllTestsCommand . title ) . toBe ( 'Run All Tests' ) ;
@@ -67,8 +79,8 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
67
79
runAllTestsCommand . arguments ! [ 0 ]
68
80
) ;
69
81
jestLib . expect ( testResults ) . toBeDefined ( ) ;
70
- jestLib . expect ( testResults ?. totalTests ) . toEqual ( 1 ) ;
71
- jestLib . expect ( testResults ?. testsPassed ) . toEqual ( 1 ) ;
82
+ jestLib . expect ( testResults ?. totalTests ) . toEqual ( 2 ) ;
83
+ jestLib . expect ( testResults ?. testsPassed ) . toEqual ( 2 ) ;
72
84
jestLib . expect ( testResults ?. testsFailed ) . toEqual ( 0 ) ;
73
85
jestLib . expect ( testResults ?. testsSkipped ) . toEqual ( 0 ) ;
74
86
} ) ;
@@ -91,6 +103,26 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
91
103
jestLib . expect ( testResults ?. testsFailed ) . toEqual ( 0 ) ;
92
104
jestLib . expect ( testResults ?. testsSkipped ) . toEqual ( 0 ) ;
93
105
} ) ;
106
+
107
+ jestLib . test ( 'Run tests uses .runsettings' , async ( ) => {
108
+ await setConfigurationAndWaitForObserver ( 'dotnet.unitTests.runSettingsPath' , '.runsettings' ) ;
109
+
110
+ const codeLenses = await getCodeLensesAsync ( ) ;
111
+ jestLib . expect ( codeLenses ) . toHaveLength ( 9 ) ;
112
+
113
+ const runAllTestsCommand = codeLenses [ 2 ] . command ! ;
114
+ jestLib . expect ( runAllTestsCommand . title ) . toBe ( 'Run All Tests' ) ;
115
+
116
+ const testResults = await vscode . commands . executeCommand < TestProgress | undefined > (
117
+ runAllTestsCommand . command ,
118
+ runAllTestsCommand . arguments ! [ 0 ]
119
+ ) ;
120
+ jestLib . expect ( testResults ) . toBeDefined ( ) ;
121
+ jestLib . expect ( testResults ?. totalTests ) . toEqual ( 1 ) ;
122
+ jestLib . expect ( testResults ?. testsPassed ) . toEqual ( 1 ) ;
123
+ jestLib . expect ( testResults ?. testsFailed ) . toEqual ( 0 ) ;
124
+ jestLib . expect ( testResults ?. testsSkipped ) . toEqual ( 0 ) ;
125
+ } ) ;
94
126
} ) ;
95
127
96
128
async function getCodeLensesAsync ( ) : Promise < vscode . CodeLens [ ] > {
@@ -118,3 +150,15 @@ async function getCodeLensesAsync(): Promise<vscode.CodeLens[]> {
118
150
return a . command ! . title . localeCompare ( b . command ! . command ) ;
119
151
} ) ;
120
152
}
153
+
154
+ async function setConfigurationAndWaitForObserver < T > ( configuration : string , value : T ) : Promise < void > {
155
+ const changed = new Promise < void > ( ( resolve , _ ) => {
156
+ vscode . workspace . onDidChangeConfiguration ( ( e ) => {
157
+ if ( e . affectsConfiguration ( configuration ) ) {
158
+ resolve ( ) ;
159
+ }
160
+ } ) ;
161
+ } ) ;
162
+ vscode . workspace . getConfiguration ( ) . update ( configuration , value ) ;
163
+ await changed ;
164
+ }
0 commit comments