Skip to content

Commit

Permalink
Update tests.csv to override priority in assertions column (#1042)
Browse files Browse the repository at this point in the history
* Update tests.csv#assertions column regex; support 0 priority assertion being parsed in test parser

* Revert test parsing to maintain order of assertions are defined in tests.csv
  • Loading branch information
howard-e authored Mar 7, 2024
1 parent 19a3f5a commit d276efa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
24 changes: 19 additions & 5 deletions lib/data/parse-test-csv-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,25 @@ function parseTestCSVRowV2({ tests, assertions, scripts, commands }) {
// Create assertions value
const assertionsValue = test.assertions
? test.assertions.split(' ').map(assertion => {
// TODO: Return error if foundAssertion undefined
const foundAssertion = assertions.find(e => e.assertionId === assertion);
return foundAssertion
? { ...foundAssertion, priority: Number(foundAssertion.priority) }
: {};
// TODO: Return error if foundAssertion is empty
let foundAssertion = {};
assertions.forEach(e => {
if (assertion.includes(':')) {
const [priority, assertionId] = assertion.split(':');
if (e.assertionId === assertionId) {
foundAssertion = {
...e,
priority: Number(priority),
};
}
} else if (e.assertionId === assertion) {
foundAssertion = {
...e,
priority: Number(e.priority),
};
}
});
return foundAssertion;
})
: undefined;

Expand Down
8 changes: 7 additions & 1 deletion lib/data/process-test-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const processTestDirectory = async ({ directory, args = {} }) => {
const validTestsKeys =
/^(?:testId|title|presentationNumber|setupScript|instructions|assertions)$/;
const titleFormat = /^[A-Z]([A-Za-z-',\s]){2,}[^.]$/;
const assertionsFormat = /^(([0123]:)?[a-zA-Z-\d]+\s*)+$/;
function validateTestsKeys(row) {
// example header:
// testId,title,presentationNumber,setupScript,instructions,assertions
Expand Down Expand Up @@ -275,6 +276,8 @@ const processTestDirectory = async ({ directory, args = {} }) => {
throw new Error('testId does not match the expected format: ' + row.testId);
if (!titleFormat.test(row.title))
throw new Error('title does not match the expected format: ' + row.title);
if (row.assertions && !assertionsFormat.test(row.assertions))
throw new Error('assertions does not match the expectedFormat: ' + row.assertions);
if (!Number(row.presentationNumber) > 0)
throw new Error(
'presentationNumber does not match the expected format: ' + row.presentationNumber
Expand Down Expand Up @@ -1518,7 +1521,10 @@ function validateTest(testParsed, data, { addTestError = () => {} } = {}) {

if (
typeof assertion.priority === 'string' ||
(assertion.priority !== 1 && assertion.priority !== 2 && assertion.priority !== 3)
(assertion.priority !== 0 &&
assertion.priority !== 1 &&
assertion.priority !== 2 &&
assertion.priority !== 3)
) {
addTestError(
`Level value must be 1, 2 or 3, value found was "${assertion.priority}" for assertion "${assertion.assertionStatement}" (NOTE: Priority 3 defined for this assertion).`
Expand Down

0 comments on commit d276efa

Please sign in to comment.