@@ -91,33 +91,35 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil
91
91
return null ;
92
92
}
93
93
94
- // Search for a name for the test
95
- // If the test has more than one argument for names, we set it to null
96
94
string testName = null ;
97
- bool alreadySawName = false ;
98
- for ( int i = 1 ; i < pesterCommandAst . CommandElements . Count ; i ++ )
99
- {
100
- CommandElementAst currentCommandElement = pesterCommandAst . CommandElements [ i ] ;
101
-
102
- // Check for an explicit "-Name" parameter
103
- if ( currentCommandElement is CommandParameterAst )
95
+ if ( PesterSymbolReference . IsPesterTestCommand ( commandName . Value ) ) {
96
+ // Search for a name for the test
97
+ // If the test has more than one argument for names, we set it to null
98
+ bool alreadySawName = false ;
99
+ for ( int i = 1 ; i < pesterCommandAst . CommandElements . Count ; i ++ )
104
100
{
105
- // Found -Name parameter, move to next element which is the argument for -TestName
106
- i ++ ;
101
+ CommandElementAst currentCommandElement = pesterCommandAst . CommandElements [ i ] ;
102
+
103
+ // Check for an explicit "-Name" parameter
104
+ if ( currentCommandElement is CommandParameterAst )
105
+ {
106
+ // Found -Name parameter, move to next element which is the argument for -TestName
107
+ i ++ ;
107
108
109
+ if ( ! alreadySawName && TryGetTestNameArgument ( pesterCommandAst . CommandElements [ i ] , out testName ) )
110
+ {
111
+ alreadySawName = true ;
112
+ }
113
+
114
+ continue ;
115
+ }
116
+
117
+ // Otherwise, if an argument is given with no parameter, we assume it's the name
118
+ // If we've already seen a name, we set the name to null
108
119
if ( ! alreadySawName && TryGetTestNameArgument ( pesterCommandAst . CommandElements [ i ] , out testName ) )
109
120
{
110
121
alreadySawName = true ;
111
122
}
112
-
113
- continue ;
114
- }
115
-
116
- // Otherwise, if an argument is given with no parameter, we assume it's the name
117
- // If we've already seen a name, we set the name to null
118
- if ( ! alreadySawName && TryGetTestNameArgument ( pesterCommandAst . CommandElements [ i ] , out testName ) )
119
- {
120
- alreadySawName = true ;
121
123
}
122
124
}
123
125
@@ -145,7 +147,7 @@ private static bool TryGetTestNameArgument(CommandElementAst commandElementAst,
145
147
}
146
148
147
149
/// <summary>
148
- /// Defines command types for Pester test blocks.
150
+ /// Defines command types for Pester blocks.
149
151
/// </summary>
150
152
internal enum PesterCommandType
151
153
{
@@ -162,7 +164,32 @@ internal enum PesterCommandType
162
164
/// <summary>
163
165
/// Identifies an It block.
164
166
/// </summary>
165
- It
167
+ It ,
168
+
169
+ /// <summary>
170
+ /// Identifies an BeforeAll block.
171
+ /// </summary>
172
+ BeforeAll ,
173
+
174
+ /// <summary>
175
+ /// Identifies an BeforeEach block.
176
+ /// </summary>
177
+ BeforeEach ,
178
+
179
+ /// <summary>
180
+ /// Identifies an AfterAll block.
181
+ /// </summary>
182
+ AfterAll ,
183
+
184
+ /// <summary>
185
+ /// Identifies an AfterEach block.
186
+ /// </summary>
187
+ AfterEach ,
188
+
189
+ /// <summary>
190
+ /// Identifies an BeforeDiscovery block.
191
+ /// </summary>
192
+ BeforeDiscovery
166
193
}
167
194
168
195
/// <summary>
@@ -216,5 +243,18 @@ internal PesterSymbolReference(
216
243
}
217
244
return pesterCommandType ;
218
245
}
246
+
247
+ /// <summary>
248
+ /// Checks if the PesterCommandType is a block with executable tests (Describe/Context/It).
249
+ /// </summary>
250
+ /// <param name="pesterCommandType">the PesterCommandType representing the Pester command</param>
251
+ /// <returns>True if command type is a block used to trigger test run. False if setup/teardown/support-block.</returns>
252
+ internal static bool IsPesterTestCommand ( PesterCommandType pesterCommandType )
253
+ {
254
+ return pesterCommandType is
255
+ PesterCommandType . Describe or
256
+ PesterCommandType . Context or
257
+ PesterCommandType . It ;
258
+ }
219
259
}
220
260
}
0 commit comments