testaro 64.9.7 → 64.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "64.9.7",
3
+ "version": "64.10.0",
4
4
  "description": "Run 1000 web accessibility tests from 11 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/testaro/motion.js CHANGED
@@ -35,6 +35,8 @@ exports.reporter = async page => {
35
35
  const data = {};
36
36
  const totals = [0, 0, 0, 0];
37
37
  const standardInstances = [];
38
+ let violationWhat = '';
39
+ let ordinalSeverity = 0;
38
40
  try {
39
41
  // Get the screenshot PNG buffers made by the shoot0 and shoot1 tests.
40
42
  let shoot0PNGBuffer = await fs.readFile(`${tmpDir}/testaro-shoot-0.png`);
@@ -47,25 +49,16 @@ exports.reporter = async page => {
47
49
  // Parse them into PNG objects.
48
50
  let shoot0PNG = PNG.sync.read(shoot0PNGBuffer);
49
51
  let shoot1PNG = PNG.sync.read(shoot1PNGBuffer);
52
+ const {width, height} = shoot0PNG;
50
53
  // If their dimensions differ:
51
- if (shoot1PNG.width !== shoot0PNG.width || shoot1PNG.height !== shoot0PNG.height) {
52
- // Report this.
53
- data.prevented = true;
54
- data.error = 'Screenshot dimensions differ';
55
- data.dimensions = {
56
- shoot0: {
57
- width: shoot0PNG.width,
58
- height: shoot0PNG.height
59
- },
60
- shoot1: {
61
- width: shoot1PNG.width,
62
- height: shoot1PNG.height
63
- }
64
- }
54
+ if (shoot1PNG.width !== width || shoot1PNG.height !== height) {
55
+ const fromSize = `${width}×${height}`;
56
+ const toSize = `${shoot1PNG.width}×${shoot1PNG.height}`;
57
+ // Describe the violation.
58
+ violationWhat = `Page size changes spontaneously (from ${fromSize} to ${toSize})`;
65
59
  }
66
60
  // Otherwise, i.e. if their dimensions are identical:
67
61
  else {
68
- const {width, height} = shoot0PNG;
69
62
  // Get the count of differing pixels between the shots.
70
63
  const pixelChanges = pixelmatch(shoot0PNG.data, shoot1PNG.data, null, width, height);
71
64
  // Get the ratio of differing to all pixels as a percentage.
@@ -74,32 +67,39 @@ exports.reporter = async page => {
74
67
  shoot0PNG = shoot1PNG = shoot0PNGBuffer = shoot1PNGBuffer = null;
75
68
  // If any pixels were changed:
76
69
  if (pixelChanges) {
70
+ // Describe the violation.
71
+ violationWhat = `Content changes spontaneously (${changePercent}% of pixels changed)`;
77
72
  // Get the ordinal severity from the fractional pixel change.
78
- const ordinalSeverity = Math.floor(Math.min(3, 0.4 * Math.sqrt(changePercent)));
79
- // Add to the totals.
80
- totals[ordinalSeverity] = 1;
81
- // Get a summary standard instance.
82
- standardInstances.push({
83
- ruleID: 'motion',
84
- what: `Content moves or changes spontaneously (${changePercent}% of pixels changed)`,
85
- count: 1,
86
- ordinalSeverity,
87
- tagName: 'HTML',
88
- id: '',
89
- location: {
90
- doc: 'dom',
91
- type: 'box',
92
- spec: {
93
- x: 0,
94
- y: 0,
95
- width,
96
- height
97
- }
98
- },
99
- excerpt: '<html>…</html>'
100
- });
73
+ ordinalSeverity = Math.floor(Math.min(3, 0.4 * Math.sqrt(changePercent)));
101
74
  }
102
75
  }
76
+ // If there was a violation:
77
+ if (violationWhat) {
78
+ // Add to the totals.
79
+ totals[ordinalSeverity] = 1;
80
+ // Get a summary standard instance.
81
+ standardInstances.push({
82
+ ruleID: 'motion',
83
+ what: violationWhat,
84
+ count: 1,
85
+ ordinalSeverity,
86
+ tagName: 'HTML',
87
+ id: '',
88
+ location: {
89
+ doc: 'dom',
90
+ type: 'box',
91
+ spec: {
92
+ x: 0,
93
+ y: 0,
94
+ width,
95
+ height
96
+ }
97
+ },
98
+ excerpt: '<html>…</html>',
99
+ boxID: `0:0:${width}:${height}`,
100
+ pathID: '/html'
101
+ });
102
+ }
103
103
  }
104
104
  // Otherwise, i.e. if they do not both exist:
105
105
  else {
package/testaro/shoot1.js CHANGED
@@ -12,7 +12,6 @@
12
12
 
13
13
  const fs = require('fs/promises');
14
14
  const os = require('os');
15
- const path = require('path');
16
15
  const {shoot} = require('../procs/shoot');
17
16
 
18
17
  // CONSTANTS
@@ -23,15 +22,16 @@ const tmpDir = os.tmpdir();
23
22
 
24
23
  exports.reporter = async page => {
25
24
  const tempFileNames = await fs.readdir(tmpDir);
25
+ let pngPath = '';
26
26
  // If there is a shoot0 file:
27
27
  if (tempFileNames.includes('testaro-shoot-0.png')) {
28
28
  // Make and save the second screenshot.
29
- const pngPath = await shoot(page, 1);
30
- // Return whether the screenshot was prevented.
31
- return {
32
- data: {
33
- prevented: ! pngPath
34
- }
35
- };
29
+ pngPath = await shoot(page, 1);
36
30
  }
31
+ // Return whether the screenshot was prevented.
32
+ return {
33
+ data: {
34
+ prevented: ! pngPath
35
+ }
36
+ };
37
37
  };