From 117293a795cc1ffb21ce24a14d35ea74c791c442 Mon Sep 17 00:00:00 2001 From: Howard Edwards Date: Mon, 26 Feb 2024 16:10:41 -0500 Subject: [PATCH 1/2] Update tests.csv#assertions column regex; support 0 priority assertion being parsed in test parser --- lib/data/parse-test-csv-row.js | 28 +++++++++++++++++++++++----- lib/data/process-test-directory.js | 8 +++++++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/data/parse-test-csv-row.js b/lib/data/parse-test-csv-row.js index 378928985..065032a1b 100644 --- a/lib/data/parse-test-csv-row.js +++ b/lib/data/parse-test-csv-row.js @@ -110,14 +110,32 @@ 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; + // If tests.csv defines assertion with priority of 0, and *-commands.csv overrides it, it must be presented at the + // end of the assertions list, so pre-sort to push 0-priority assertions to end of array + if (assertionsValue) assertionsValue.sort(a => (a.priority === 0 ? 1 : -1)); + // Create references values let referencesValue = assertionsValue ? assertionsValue.flatMap(assertion => assertion.refIds.trim().split(' ')) diff --git a/lib/data/process-test-directory.js b/lib/data/process-test-directory.js index c9609e748..ffafef9ec 100644 --- a/lib/data/process-test-directory.js +++ b/lib/data/process-test-directory.js @@ -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 @@ -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 @@ -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).` From 096cc149a0fe3a9275990b0cbc42693df34daac3 Mon Sep 17 00:00:00 2001 From: Howard Edwards Date: Wed, 28 Feb 2024 10:18:29 -0500 Subject: [PATCH 2/2] Revert test parsing to maintain order of assertions are defined in tests.csv --- lib/data/parse-test-csv-row.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/data/parse-test-csv-row.js b/lib/data/parse-test-csv-row.js index 065032a1b..4fdd791ce 100644 --- a/lib/data/parse-test-csv-row.js +++ b/lib/data/parse-test-csv-row.js @@ -132,10 +132,6 @@ function parseTestCSVRowV2({ tests, assertions, scripts, commands }) { }) : undefined; - // If tests.csv defines assertion with priority of 0, and *-commands.csv overrides it, it must be presented at the - // end of the assertions list, so pre-sort to push 0-priority assertions to end of array - if (assertionsValue) assertionsValue.sort(a => (a.priority === 0 ? 1 : -1)); - // Create references values let referencesValue = assertionsValue ? assertionsValue.flatMap(assertion => assertion.refIds.trim().split(' '))