Skip to content

Commit

Permalink
Support assertionExceptions without priority prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
evmiguel committed Apr 24, 2024
1 parent fc74482 commit 0430504
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/data/parse-test-csv-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

'use strict';

const { setDefaultAssertionExceptionsFromTest } = require('../util/assertion-exception');

/**
* @param {AriaATCSV.Test} testRow
* @returns {AriaATParsed.Test}
Expand Down Expand Up @@ -216,12 +218,16 @@ function parseTestCSVRowV2({ tests, assertions, scripts, commands }) {
at => at.key === key && at.settings === (command.settings || 'defaultMode')
)
) {
const assertionExceptions = setDefaultAssertionExceptionsFromTest(
command.assertionExceptions,
assertions
);
const commandInfo = {
testId: command.testId,
command: command.command,
settings: command.settings || 'defaultMode',
presentationNumber: Number(command.presentationNumber),
assertionExceptions: command.assertionExceptions,
assertionExceptions: assertionExceptions,
};

// Test level commandInfo, useful for getting assertionExceptions and
Expand Down
2 changes: 1 addition & 1 deletion lib/data/process-test-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const processTestDirectory = async ({ directory, args = {} }) => {
const validCommandKeys = /^(?:testId|command|settings|assertionExceptions|presentationNumber)$/;
const numericKeyFormat = /^_(\d+)$/;
const idFormat = /^[A-Za-z0-9-]+$/;
const assertionsExceptionsFormat = /^([0123]:[a-zA-Z-\d]+\s*)+$/;
const assertionsExceptionsFormat = /^(([0123]:)?[a-zA-Z-\d]+\s*)+$/;
const settingsFormat = /^[A-Za-z0-9-\s]+$/;
function validateCommandsKeys(row) {
// example header:
Expand Down
38 changes: 38 additions & 0 deletions lib/util/assertion-exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Generates the assertionException string with a default priority prefix
* @param {String} assertionException
* @param {Number} defaultPriority
* @returns {String}
*/
function setDefaultAssertionException(assertionException, defaultPriority) {
if (assertionException && !assertionException.includes(':')) {
return `${defaultPriority}:${assertionException}`;
}
return assertionException;
}

/**
* Finds the default assertion value for an assertionException without
* a priority prefix in a string of assertionExceptions and recreates
* the string with the new default assertion priorities
* @param {String} assertionExceptions
* @param {Array} assertions
* @returns {String}
*/
function setDefaultAssertionExceptionsFromTest(assertionExceptions, assertions) {
return assertionExceptions
.split(' ')
.map(assertionException => {
const assertion = assertions.find(assertion =>
assertionException.includes(assertion.assertionId)
);
if (assertion) {
const defaultPriority = assertion.priority;
return setDefaultAssertionException(assertionException, defaultPriority);
}
return assertionException;
})
.join(' ');
}

exports.setDefaultAssertionExceptionsFromTest = setDefaultAssertionExceptionsFromTest;

0 comments on commit 0430504

Please sign in to comment.