@techsio/storybook-a11y-reporter 0.0.3 → 0.0.4

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/dist/cli.js CHANGED
@@ -35,7 +35,11 @@ function formatSummary(entries) {
35
35
  }
36
36
  function readReport(filePath = 'a11y-report/report.json') {
37
37
  const resolvedPath = node_path.resolve(process.cwd(), filePath);
38
- return fs_extra.readJSONSync(resolvedPath);
38
+ if (fs_extra.existsSync(resolvedPath)) return fs_extra.readJSONSync(resolvedPath);
39
+ const ndjsonPath = resolvedPath.endsWith('report.json') ? resolvedPath.replace(/report\.json$/, 'report.ndjson') : `${resolvedPath}.ndjson`;
40
+ if (!fs_extra.existsSync(ndjsonPath)) return [];
41
+ const content = fs_extra.readFileSync(ndjsonPath, 'utf8');
42
+ return content.split('\n').map((line)=>line.trim()).filter(Boolean).map((line)=>JSON.parse(line));
39
43
  }
40
44
  function printSummary(entries) {
41
45
  return formatSummary(entries);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5C,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;CACrB;AAgHD,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,gBAAgB,CAkC9E;AAED,wBAAgB,UAAU,CAAC,QAAQ,SAA4B,GAAG,gBAAgB,EAAE,CAGnF;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAEhE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5C,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;CACrB;AAyID,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,gBAAgB,CA6C9E;AAED,wBAAgB,UAAU,CAAC,QAAQ,SAA4B,GAAG,gBAAgB,EAAE,CAoBnF;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAEhE"}
package/dist/index.js CHANGED
@@ -76,31 +76,50 @@ function formatJUnit(entries) {
76
76
  ''
77
77
  ].join('\n');
78
78
  }
79
- async function writeReports(entries, options) {
79
+ function getOutputPaths(options) {
80
80
  const outputDir = node_path.resolve(process.cwd(), options.outputDir);
81
+ return {
82
+ outputDir,
83
+ reportPath: node_path.join(outputDir, 'report.json'),
84
+ ndjsonPath: node_path.join(outputDir, 'report.ndjson'),
85
+ summaryPath: node_path.join(outputDir, 'summary.md'),
86
+ junitPath: node_path.join(outputDir, 'junit.xml')
87
+ };
88
+ }
89
+ async function appendEntry(entry, options) {
90
+ const { outputDir, ndjsonPath } = getOutputPaths(options);
91
+ await fs_extra.ensureDir(outputDir);
92
+ await fs_extra.appendFile(ndjsonPath, `${JSON.stringify(entry)}\n`);
93
+ return ndjsonPath;
94
+ }
95
+ async function readEntriesFromNdjson(ndjsonPath) {
96
+ const exists = await fs_extra.pathExists(ndjsonPath);
97
+ if (!exists) return [];
98
+ const content = await fs_extra.readFile(ndjsonPath, 'utf8');
99
+ return content.split('\n').map((line)=>line.trim()).filter(Boolean).map((line)=>JSON.parse(line));
100
+ }
101
+ async function writeReports(entries, options) {
102
+ const { outputDir, reportPath, summaryPath, junitPath } = getOutputPaths(options);
81
103
  await fs_extra.ensureDir(outputDir);
82
- const reportPath = node_path.join(outputDir, 'report.json');
83
104
  await fs_extra.writeJSON(reportPath, entries, {
84
105
  spaces: 2
85
106
  });
86
- const summaryPath = node_path.join(outputDir, 'summary.md');
87
107
  await fs_extra.writeFile(summaryPath, formatSummary(entries));
88
- if (options.writeJUnit) {
89
- const junitPath = node_path.join(outputDir, 'junit.xml');
90
- await fs_extra.writeFile(junitPath, formatJUnit(entries));
91
- }
108
+ if (options.writeJUnit) await fs_extra.writeFile(junitPath, formatJUnit(entries));
92
109
  }
93
110
  function createA11yReporter(options) {
94
111
  const resolved = resolveOptions(options);
95
- const entries = [];
96
112
  return {
97
113
  async postVisit (page, context) {
98
114
  const storyId = context.id;
99
115
  const storyContext = await getStoryContext(page, context).catch(()=>null);
100
- await page.waitForFunction((id)=>window.__TECHSIO_A11Y_RESULTS__?.storyId === id, storyId, {
116
+ const a11yParams = storyContext?.parameters?.a11y ?? null;
117
+ const a11yGlobals = storyContext?.globals?.a11y ?? null;
118
+ const shouldWaitForResults = a11yParams?.disable !== true && a11yParams?.test !== 'off' && a11yGlobals?.manual !== true;
119
+ if (shouldWaitForResults) await page.waitForFunction((id)=>window.__TECHSIO_A11Y_RESULTS__?.storyId === id, storyId, {
101
120
  timeout: resolved.waitForResultsMs
102
121
  });
103
- const pageResults = await page.evaluate(()=>window.__TECHSIO_A11Y_RESULTS__ ?? null);
122
+ const pageResults = shouldWaitForResults ? await page.evaluate(()=>window.__TECHSIO_A11Y_RESULTS__ ?? null) : null;
104
123
  const entry = {
105
124
  storyId,
106
125
  title: context.title,
@@ -109,7 +128,8 @@ function createA11yReporter(options) {
109
128
  parameters: storyContext?.parameters?.a11y ?? null,
110
129
  results: pageResults?.results ?? null
111
130
  };
112
- entries.push(entry);
131
+ const ndjsonPath = await appendEntry(entry, resolved);
132
+ const entries = await readEntriesFromNdjson(ndjsonPath);
113
133
  await writeReports(entries, resolved);
114
134
  if (resolved.failOnViolations && countViolations(entry.results) > 0) throw new Error(`A11y violations detected in ${context.title} / ${context.name}`);
115
135
  }
@@ -117,7 +137,11 @@ function createA11yReporter(options) {
117
137
  }
118
138
  function readReport(filePath = 'a11y-report/report.json') {
119
139
  const resolvedPath = node_path.resolve(process.cwd(), filePath);
120
- return fs_extra.readJSONSync(resolvedPath);
140
+ if (fs_extra.existsSync(resolvedPath)) return fs_extra.readJSONSync(resolvedPath);
141
+ const ndjsonPath = resolvedPath.endsWith('report.json') ? resolvedPath.replace(/report\.json$/, 'report.ndjson') : `${resolvedPath}.ndjson`;
142
+ if (!fs_extra.existsSync(ndjsonPath)) return [];
143
+ const content = fs_extra.readFileSync(ndjsonPath, 'utf8');
144
+ return content.split('\n').map((line)=>line.trim()).filter(Boolean).map((line)=>JSON.parse(line));
121
145
  }
122
146
  function printSummary(entries) {
123
147
  return formatSummary(entries);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techsio/storybook-a11y-reporter",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Storybook a11y reporter with APCA support for CI/CLI",
5
5
  "type": "module",
6
6
  "repository": {