Skip to content

Commit

Permalink
special error for numeric key format
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarf committed Aug 23, 2023
1 parent 63d262d commit 7b671ce
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/data/process-test-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,16 +608,16 @@ ${rows}
try {
const firstRowKeysLength = Object.keys(rawCSV[0]).length;
for (; index < rawCSV.length; index++) {
if (!rowValidator(rawCSV[index])) {
printError('validator returned false result');
return;
}
const keysLength = Object.keys(rawCSV[index]).length;
if (keysLength != firstRowKeysLength) {
printError(
`column number mismatch, please include empty cells to match headers. Expected ${firstRowKeysLength} columns, found ${keysLength}`
);
}
if (!rowValidator(rawCSV[index])) {
printError('validator returned false result');
return;
}
}
} catch (err) {
printError(err);
Expand All @@ -635,12 +635,16 @@ ${rows}
}

const validCommandKeys = /^(?:testId|task|mode|at|command[A-Z])$/;
const numericKeyFormat = /^_(\d+)$/;
function validateCommandsKeys(row) {
// example header:
// testId,task,mode,at,commandA,commandB,commandC,commandD,commandE,commandF
for (const key of Object.keys(row)) {
if (!validCommandKeys.test(key))
if (numericKeyFormat.test(key)) {
throw new Error(`Column found without header row, ${+key.substring(1) + 1}`);
} else if (!validCommandKeys.test(key)) {
throw new Error(`Unknown commands.csv key: ${key} - check header row?`);
}
}
if (
!(
Expand All @@ -662,8 +666,11 @@ ${rows}
// example header:
// testId,title,appliesTo,mode,task,setupScript,setupScriptDescription,refs,instructions,assertion1,assertion2,assertion3,assertion4,assertion5,assertion6,assertion7
for (const key of Object.keys(row)) {
if (!validTestsKeys.test(key))
if (numericKeyFormat.test(key)) {
throw new Error(`Column found without header row, ${+key.substring(1) + 1}`);
} else if (!validTestsKeys.test(key)) {
throw new Error(`Unknown tests.csv key: ${key} - check header row?`);
}
}
if (
!(
Expand Down

0 comments on commit 7b671ce

Please sign in to comment.