Skip to content

Commit 823fec9

Browse files
authored
Merge pull request #210 from pegasystems/bugfix/prval
fix: enhance accessibility checks in test runner with error handling …
2 parents 96b996d + 4ec0181 commit 823fec9

File tree

3 files changed

+60
-24
lines changed

3 files changed

+60
-24
lines changed

.github/workflows/validatepr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
curl -vvvv http://localhost:6006/index.html
5151
cat log.txt
5252
- name: Run tests
53-
run: npm run test-storybook
53+
run: npm run test-storybook -- --maxWorkers=1 --verbose

.storybook/test-runner.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,41 @@ const config: TestRunnerConfig = {
1111
async preVisit(page) {
1212
await injectAxe(page);
1313
},
14+
1415
async postVisit(page, context) {
15-
// Get the entire context of a story, including parameters, args, argTypes, etc.
16-
const storyContext = await getStoryContext(page, context);
16+
try {
17+
// Get the entire context of a story, including parameters, args, argTypes, etc.
18+
const storyContext = await getStoryContext(page, context);
19+
20+
// Apply story-level a11y rules
21+
await configureAxe(page, {
22+
rules: storyContext.parameters?.a11y?.config?.rules,
23+
});
1724

18-
// Apply story-level a11y rules
19-
await configureAxe(page, {
20-
rules: storyContext.parameters?.a11y?.config?.rules,
21-
});
25+
// Wait a bit to ensure any previous Axe runs have completed
26+
await page.waitForTimeout(200);
2227

23-
await checkA11y(page, '#storybook-root', {
24-
detailedReport: true,
25-
detailedReportOptions: {
26-
html: true,
27-
},
28-
});
28+
await checkA11y(page, '#storybook-root', {
29+
detailedReport: true,
30+
detailedReportOptions: {
31+
html: true,
32+
},
33+
});
34+
} catch (error) {
35+
// If Axe is already running, wait and retry once
36+
if (error instanceof Error && error.message.includes('Axe is already running')) {
37+
console.warn('Axe was already running, waiting and retrying...');
38+
await page.waitForTimeout(1000); // Increased wait time
39+
await checkA11y(page, '#storybook-root', {
40+
detailedReport: true,
41+
detailedReportOptions: {
42+
html: true,
43+
},
44+
});
45+
} else {
46+
throw error;
47+
}
48+
}
2949
},
3050
};
3151

src/components/Pega_Extensions_DisplayPDF/demo.stories.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,44 @@ export default {
2424
component: PegaExtensionsDisplayPDF,
2525
};
2626

27-
const blob2base64 = (blob: Blob, mimeType: string) => {
27+
const blob2base64 = (blob: Blob) => {
2828
return new Promise((resolve, reject) => {
2929
const reader = new FileReader();
3030
reader.onloadend = () => {
31-
const dataUrlPrefix = `data:${mimeType};base64,`;
32-
const base64WithDataUrlPrefix = reader.result;
33-
const base64 =
34-
typeof base64WithDataUrlPrefix === 'string' ? base64WithDataUrlPrefix.replace(dataUrlPrefix, '') : '';
35-
resolve(base64);
31+
const result = reader.result;
32+
if (typeof result === 'string') {
33+
// Remove the data URL prefix to get just the base64 string
34+
const base64 = result.split(',')[1];
35+
console.log('Base64 length:', base64?.length);
36+
resolve(base64 || '');
37+
} else {
38+
reject(new Error('Failed to read blob as data URL'));
39+
}
3640
};
3741
reader.onerror = reject;
3842
reader.readAsDataURL(blob);
3943
});
4044
};
4145

4246
const getBinary = async () => {
43-
const response = await fetch('./SamplePDF.pdf');
44-
if (response.blob) {
45-
const blob = await response.blob();
46-
return blob2base64(blob, 'application/pdf');
47+
try {
48+
const response = await fetch('/SamplePDF.pdf');
49+
console.log('PDF fetch response status:', response.status);
50+
console.log('PDF fetch response ok:', response.ok);
51+
52+
if (response.ok && response.blob) {
53+
const blob = await response.blob();
54+
console.log('PDF blob size:', blob.size);
55+
return blob2base64(blob);
56+
}
57+
console.warn('PDF fetch failed or no blob available');
58+
// Fallback to a minimal valid PDF for testing
59+
return 'JVBERi0xLjQKJcOkw7zDtsO8CjIgMCBvYmoKPDwKL0xlbmd0aCAzIDAgUgovVHlwZSAvUGFnZQo+PgpzdHJlYW0KZW5kb2JqCjMgMCBvYmoKMTEKZW5kb2JqCjEgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFsyIDAgUl0KL0NvdW50IDEKL01lZGlhQm94IFswIDAgNTk1IDg0Ml0KPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0NhdGFsb2cKL1BhZ2VzIDEgMCBSCj4+CmVuZG9iagp4cmVmCjAgNQowMDAwMDAwMDAwIDY1NTM1IGYKMDAwMDAwMDAwOSAwMDAwMCBuCjAwMDAwMDAwNTggMDAwMDAgbgowMDAwMDAwMTE1IDAwMDAwIG4KMDAwMDAwMDM3OCAwMDAwMCBuCnRyYWlsZXIKPDwKL1NpemUgNQovUm9vdCA0IDAgUgo+PgpzdGFydHhyZWYKNDk3CiUlRU9G';
60+
} catch (error) {
61+
console.error('PDF fetch error:', error);
62+
// Fallback to a minimal valid PDF for testing
63+
return 'JVBERi0xLjQKJcOkw7zDtsO8CjIgMCBvYmoKPDwKL0xlbmd0aCAzIDAgUgovVHlwZSAvUGFnZQo+PgpzdHJlYW0KZW5kb2JqCjMgMCBvYmoKMTEKZW5kb2JqCjEgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFsyIDAgUl0KL0NvdW50IDEKL01lZGlhQm94IFswIDAgNTk1IDg0Ml0KPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0NhdGFsb2cKL1BhZ2VzIDEgMCBSCj4+CmVuZG9iagp4cmVmCjAgNQowMDAwMDAwMDAwIDY1NTM1IGYKMDAwMDAwMDAwOSAwMDAwMCBuCjAwMDAwMDAwNTggMDAwMDAgbgowMDAwMDAwMTE1IDAwMDAwIG4KMDAwMDAwMDM3OCAwMDAwMCBuCnRyYWlsZXIKPDwKL1NpemUgNQovUm9vdCA0IDAgUgo+PgpzdGFydHhyZWYKNDk3CiUlRU9G';
4764
}
48-
return '';
4965
};
5066

5167
const setPCore = (url: string) => {

0 commit comments

Comments
 (0)