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

Support assertionExceptions without priority prefix #1053

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setDefaultAssertionPriority seems like a more appropriate name here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@howard-e addressed this in 1373d76

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;
Loading