Skip to content

Commit 62722a5

Browse files
authored
fix: point TypeScript output to dist directory (#644)
* suppress error/warning spam, fix key errors etc * set ts output dir to dist * retry logic to WCAG
1 parent f16bded commit 62722a5

2 files changed

Lines changed: 45 additions & 22 deletions

File tree

.storybook/wcag/test-runner.ts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,49 @@ import { Page } from 'playwright-core';
33
import { runOnly } from '../wcagConfig';
44
import { TestContext, TestRunnerConfig } from '@storybook/test-runner';
55

6+
const AXE_ALREADY_RUNNING_ERROR = 'Axe is already running';
7+
const MAX_AXE_RETRIES = 3;
8+
const AXE_RETRY_DELAY_MS = 250;
9+
10+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
11+
12+
// Retry if errors from Axe already running to decrease flakiness
13+
const runA11yCheck = async (page: Page, context: TestContext) => {
14+
for (let attempt = 1; attempt <= MAX_AXE_RETRIES; attempt++) {
15+
try {
16+
await checkA11y(
17+
page,
18+
{
19+
exclude: [
20+
'#root .mapboxgl-canvas-container',
21+
'.mapboxgl-marker',
22+
'.mapboxgl-popup-close-button'
23+
],
24+
},
25+
{
26+
axeOptions: {
27+
runOnly,
28+
rules: {
29+
'color-contrast': { enabled: context.name !== 'Loading' },
30+
},
31+
},
32+
detailedReport: true,
33+
detailedReportOptions: {
34+
html: true,
35+
},
36+
}
37+
);
38+
return;
39+
} catch (error) {
40+
const message = error instanceof Error ? error.message : String(error);
41+
if (!message.includes(AXE_ALREADY_RUNNING_ERROR) || attempt === MAX_AXE_RETRIES) {
42+
throw error;
43+
}
44+
await sleep(AXE_RETRY_DELAY_MS * attempt);
45+
}
46+
}
47+
};
48+
649
/**
750
* See https://storybook.js.org/docs/react/writing-tests/test-runner#test-hook-api-experimental
851
* to learn more about the test-runner hooks API.
@@ -12,28 +55,7 @@ const renderFunctions: TestRunnerConfig = {
1255
await injectAxe(page);
1356
},
1457
async postVisit(page: Page, context: TestContext) {
15-
await checkA11y(
16-
page,
17-
{
18-
exclude: [
19-
'#root .mapboxgl-canvas-container',
20-
'.mapboxgl-marker',
21-
'.mapboxgl-popup-close-button'
22-
],
23-
},
24-
{
25-
axeOptions: {
26-
runOnly,
27-
rules: {
28-
'color-contrast': { enabled: context.name !== 'Loading' },
29-
},
30-
},
31-
detailedReport: true,
32-
detailedReportOptions: {
33-
html: true,
34-
},
35-
}
36-
);
58+
await runA11yCheck(page, context);
3759
},
3860
};
3961

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"noImplicitAny": false,
77
"module": "es2020",
88
"moduleResolution": "node",
9+
"outDir": "dist",
910
"forceConsistentCasingInFileNames": true,
1011
"declaration": true,
1112
"declarationMap": true,

0 commit comments

Comments
 (0)