@jrpool/kilotest 31.2.2 → 33.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/util.js CHANGED
@@ -22,7 +22,7 @@ const logsPath = exports.logsPath = path.join(__dirname, 'logs');
22
22
  const recsPath = exports.recsPath = path.join(__dirname, 'jobs', 'recs.json');
23
23
  // Path of the reports directory.
24
24
  const reportsPath = exports.reportsPath = path.join(__dirname, 'reports');
25
- // IDs, names, and sponsors of Testaro tools.
25
+ // IDs, names, and sponsors of Testaro rule engines.
26
26
  const tools = exports.tools = {
27
27
  alfa: ['Alfa', 'Siteimprove'],
28
28
  aslint: ['ASLint', 'eSSENTIAL Accessibility'],
@@ -399,7 +399,7 @@ exports.getReportData = async (timeStamp, jobID) => {
399
399
  .sort((a, b) => a.localeCompare(b, 'en', {sensitivity: 'base'}));
400
400
  data.reporterCount = data.reporterNames.length;
401
401
  data.violatorCount = violatorIndexSet.size;
402
- // Add the names of any prevented tools to the data.
402
+ // Add the names of any prevented rule engines to the data.
403
403
  data.preventedToolNames = Object.keys(report.jobData?.preventions || {})
404
404
  .map(toolID => tools[toolID][0])
405
405
  .sort((a, b) => a.localeCompare(b, 'en', {sensitivity: 'base'}));
@@ -506,7 +506,7 @@ const getRecs = exports.getRecs = async () => {
506
506
  }
507
507
  return recs;
508
508
  };
509
- // Returns a string of tool names.
509
+ // Returns a string of names of rule engines.
510
510
  exports.getToolNamesString = toolIDSet =>
511
511
  alphaSort(Array.from(toolIDSet).map(toolID => tools[toolID]?.[0] || toolID)).join(' + ');
512
512
  // Converts a catalog item text to a text-fragment link destination.
@@ -519,7 +519,7 @@ exports.getTextFragmentHref = (text, url) => {
519
519
  return `${url}#:~:text=${fragmentList}`;
520
520
  };
521
521
  // Returns a sorted array of the logs, with job names added, of the non-hidden reports.
522
- exports.getLogs = async () => {
522
+ const getLogs = exports.getLogs = async () => {
523
523
  // Initialize data on the tested targets.
524
524
  const logs = [];
525
525
  let logFileNames;
@@ -723,7 +723,7 @@ exports.getPageDataStrings = async (timeStamp, jobID, pageData) => {
723
723
  testInfo: `Tested ${daysAgo} days ago by job <code>${jobID}</code> on ${when}`
724
724
  };
725
725
  };
726
- // Returns tool data sorted by tool name.
726
+ // Returns data about rule engines sorted by their names.
727
727
  const getToolsData = exports.getToolsData = toolIDs => objectSort(
728
728
  Array.from(toolIDs).map(toolID => {
729
729
  const toolData = tools[toolID];
@@ -736,12 +736,12 @@ const getToolsData = exports.getToolsData = toolIDs => objectSort(
736
736
  'toolName',
737
737
  'alpha'
738
738
  );
739
- // Returns a +-delimited list of sorted tool names.
739
+ // Returns a +-delimited list of sorted names of rule engines.
740
740
  exports.getToolList = toolIDs => Array.from(toolIDs)
741
741
  .map(toolID => tools[toolID][0])
742
742
  .sort((a, b) => a.localeCompare(b, 'en', {sensitivity: 'base'}))
743
743
  .join(' + ');
744
- // Returns facts about tools.
744
+ // Returns facts about rule engines.
745
745
  exports.getToolsFacts = toolIDs => {
746
746
  const crypticData = getToolsData(toolIDs);
747
747
  return crypticData.map(tool => {
@@ -755,3 +755,12 @@ exports.getToolsFacts = toolIDs => {
755
755
  };
756
756
  // Returns a string describing a count.
757
757
  exports.getCountString = (count, singular, plural) => count === 1 ? `1 ${singular}` : `${count} ${plural}`;
758
+ // Minifies a URL for duplicate detection.
759
+ const minifyURL = exports.minifyURL = url => url.replace(/www\.|\/$/g, '');
760
+ // Returns whether a report about the specified page is already available.
761
+ exports.isReportAvailable = async (what, url) => {
762
+ const logs = await getLogs();
763
+ const whats = logs.map(log => log.what);
764
+ const miniURLs = logs.map(log => minifyURL(log.url));
765
+ return whats.includes(what) || miniURLs.includes(minifyURL(url));
766
+ };