Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests.csv to override priority in assertions column #1042

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading