Skip to content

Commit d8db613

Browse files
committed
Check for duplicate test names
1 parent 733fe52 commit d8db613

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

build.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ function buildTestSuite(testsFolder, tags, all, exclude) {
9292
: list => tags.some(t => list.includes(t))
9393
const tests = readTestsFromDir(testsFolder)
9494
.filter(test => tags.length === 0 || (tagFilter(getTags(test)) !== exclude));
95+
checkDuplicateNames(tests);
96+
9597
tests.forEach(test => {
9698
if ('tags' in test) test.tags.sort();
9799
});
@@ -194,3 +196,28 @@ function prependToTestName(prefix) {
194196
};
195197
}
196198

199+
/**
200+
* Verifies that no tests have duplicate names.
201+
* @param allTests - The list of all tests.
202+
*/
203+
function checkDuplicateNames(allTests) {
204+
const names = new Set();
205+
const duplicates = [];
206+
207+
for (const test of allTests) {
208+
const oldSize = names.size;
209+
const name = test.name;
210+
names.add(name);
211+
212+
if (oldSize === names.size) {
213+
duplicates.push(name);
214+
}
215+
}
216+
217+
duplicates.sort();
218+
if (duplicates.length > 0) {
219+
const prefix = "\n ";
220+
console.error("Error: Duplicate test names:" + prefix + duplicates.join(prefix));
221+
process.exit(1);
222+
}
223+
}

tests/whitespace/selectors.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@
3636
"tags": ["whitespace"]
3737
},
3838
{
39-
"name": "newline between root and bracket",
39+
"name": "newline between bracket and bracket",
4040
"selector" : "$['a'] \n['b']",
4141
"document" : {"a": {"b": "ab"} },
4242
"result": [ "ab" ],
4343
"tags": ["whitespace"]
4444
},
4545
{
46-
"name": "tab between root and bracket",
46+
"name": "tab between bracket and bracket",
4747
"selector" : "$['a'] \t['b']",
4848
"document" : {"a": {"b": "ab"} },
4949
"result": [ "ab" ],
5050
"tags": ["whitespace"]
5151
},
5252
{
53-
"name": "return between root and bracket",
53+
"name": "return between bracket and bracket",
5454
"selector" : "$['a'] \r['b']",
5555
"document" : {"a": {"b": "ab"} },
5656
"result": [ "ab" ],

0 commit comments

Comments
 (0)