@@ -62,13 +62,16 @@ const usage = [
62
62
' -e, --exclude Flag to exclude the specified tags instead of including them.' ,
63
63
]
64
64
65
+ const exitCodeUsageError = 1 ;
66
+ const exitCodeDuplicateNames = 2 ;
67
+
65
68
main ( )
66
69
67
70
function main ( ) {
68
71
const { values, positionals} = parseArgs ( { options, allowPositionals : true } ) ;
69
72
if ( positionals . length !== 1 ) {
70
73
usage . forEach ( line => console . error ( line ) ) ;
71
- process . exit ( 1 ) ;
74
+ process . exit ( exitCodeUsageError ) ;
72
75
}
73
76
const [ testsFolder ] = positionals ;
74
77
buildTestSuite ( testsFolder , values [ 'tag' ] , values [ 'require-all' ] , values [ 'exclude' ] ) ;
@@ -90,8 +93,10 @@ function buildTestSuite(testsFolder, tags, all, exclude) {
90
93
const tagFilter = all
91
94
? list => tags . every ( t => list . includes ( t ) )
92
95
: list => tags . some ( t => list . includes ( t ) )
93
- const tests = readTestsFromDir ( testsFolder )
94
- . filter ( test => tags . length === 0 || ( tagFilter ( getTags ( test ) ) !== exclude ) ) ;
96
+ let tests = readTestsFromDir ( testsFolder ) ;
97
+ checkDuplicateNames ( tests ) ;
98
+
99
+ tests = tests . filter ( test => tags . length === 0 || ( tagFilter ( getTags ( test ) ) !== exclude ) ) ;
95
100
tests . forEach ( test => {
96
101
if ( 'tags' in test ) test . tags . sort ( ) ;
97
102
} ) ;
@@ -194,3 +199,27 @@ function prependToTestName(prefix) {
194
199
} ;
195
200
}
196
201
202
+ /**
203
+ * Verifies that no tests have duplicate names.
204
+ * @param allTests - The list of all tests.
205
+ */
206
+ function checkDuplicateNames ( allTests ) {
207
+ const names = new Set ( ) ;
208
+ const duplicates = [ ] ;
209
+
210
+ for ( const test of allTests ) {
211
+ const name = test . name ;
212
+
213
+ if ( names . has ( name ) ) {
214
+ duplicates . push ( name ) ;
215
+ } else {
216
+ names . add ( name ) ;
217
+ }
218
+ }
219
+
220
+ if ( duplicates . length > 0 ) {
221
+ duplicates . sort ( ) ;
222
+ console . error ( [ 'Error: Duplicate test names:' , ...duplicates ] . join ( '\n ' ) ) ;
223
+ process . exit ( exitCodeDuplicateNames ) ;
224
+ }
225
+ }
0 commit comments