aria-ease 5.0.3 → 6.0.1

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.
@@ -8,10 +8,15 @@ interface JestAxeResult {
8
8
  * Runs static and interactions accessibility test on UI components.
9
9
  * @param {string} componentName The name of the component contract to test against
10
10
  * @param {HTMLElement} component The UI component to be tested
11
- * @param {string} url Optional URL to run full Playwright E2E tests (requires dev server running)
11
+ * @param {string} url Optional URL to run full Playwright E2E tests. If omitted, uses isolated component testing with page.setContent()
12
12
  */
13
13
 
14
- declare function testUiComponent(componentName: string, component: HTMLElement, url?: string): Promise<JestAxeResult>;
14
+ declare function testUiComponent(componentName: string, component: HTMLElement | null, url: string | null): Promise<JestAxeResult>;
15
15
  declare let runTest: () => Promise<void>;
16
+ /**
17
+ * Cleanup function to close the shared Playwright browser
18
+ * Call this in afterAll() or after all tests complete
19
+ */
20
+ declare function cleanupTests(): Promise<void>;
16
21
 
17
- export { runTest, testUiComponent };
22
+ export { cleanupTests, runTest, testUiComponent };
@@ -8,10 +8,15 @@ interface JestAxeResult {
8
8
  * Runs static and interactions accessibility test on UI components.
9
9
  * @param {string} componentName The name of the component contract to test against
10
10
  * @param {HTMLElement} component The UI component to be tested
11
- * @param {string} url Optional URL to run full Playwright E2E tests (requires dev server running)
11
+ * @param {string} url Optional URL to run full Playwright E2E tests. If omitted, uses isolated component testing with page.setContent()
12
12
  */
13
13
 
14
- declare function testUiComponent(componentName: string, component: HTMLElement, url?: string): Promise<JestAxeResult>;
14
+ declare function testUiComponent(componentName: string, component: HTMLElement | null, url: string | null): Promise<JestAxeResult>;
15
15
  declare let runTest: () => Promise<void>;
16
+ /**
17
+ * Cleanup function to close the shared Playwright browser
18
+ * Call this in afterAll() or after all tests complete
19
+ */
20
+ declare function cleanupTests(): Promise<void>;
16
21
 
17
- export { runTest, testUiComponent };
22
+ export { cleanupTests, runTest, testUiComponent };
@@ -1,4 +1,4 @@
1
- import { ContractReporter, contract_default } from './chunk-TUWQNVQJ.js';
1
+ import { closeSharedBrowser, ContractReporter, contract_default } from './chunk-7RMRFSJL.js';
2
2
  import { axe } from 'jest-axe';
3
3
  import fs from 'fs/promises';
4
4
 
@@ -67,56 +67,58 @@ async function testUiComponent(componentName, component, url) {
67
67
  if (!componentName || typeof componentName !== "string") {
68
68
  throw new Error("\u274C testUiComponent requires a valid componentName (string)");
69
69
  }
70
- if (!component || !(component instanceof HTMLElement)) {
71
- throw new Error("\u274C testUiComponent requires a valid component (HTMLElement)");
70
+ if (!url && (!component || !(component instanceof HTMLElement))) {
71
+ throw new Error("\u274C testUiComponent requires either a valid component (HTMLElement) or a URL");
72
72
  }
73
73
  if (url && typeof url !== "string") {
74
74
  throw new Error("\u274C testUiComponent url parameter must be a string");
75
75
  }
76
76
  let results;
77
- try {
78
- results = await axe(component);
79
- } catch (error) {
80
- throw new Error(
81
- `\u274C Axe accessibility scan failed
77
+ if (component) {
78
+ try {
79
+ results = await axe(component);
80
+ } catch (error) {
81
+ throw new Error(
82
+ `\u274C Axe accessibility scan failed
82
83
  Error: ${error instanceof Error ? error.message : String(error)}`
83
- );
84
+ );
85
+ }
86
+ } else {
87
+ results = { violations: [] };
84
88
  }
85
- async function checkDevServer(testUrl) {
86
- const urlsToTry = testUrl ? [testUrl] : [
87
- "http://localhost:5173",
88
- "http://localhost:3000",
89
- "http://localhost:8080",
90
- "http://localhost:4173"
91
- ];
92
- for (const serverUrl of urlsToTry) {
93
- try {
94
- const response = await fetch(serverUrl, {
95
- method: "HEAD",
96
- signal: AbortSignal.timeout(1e3)
97
- });
98
- if (response.ok || response.status === 304) {
99
- return serverUrl;
100
- }
101
- } catch {
102
- return null;
89
+ async function checkDevServer(url2) {
90
+ try {
91
+ const response = await fetch(url2, {
92
+ method: "HEAD",
93
+ signal: AbortSignal.timeout(1e3)
94
+ });
95
+ if (response.ok || response.status === 304) {
96
+ return url2;
103
97
  }
98
+ } catch {
99
+ return null;
104
100
  }
105
101
  return null;
106
102
  }
107
103
  let contract;
108
104
  try {
109
- const devServerUrl = await checkDevServer(url);
110
- if (devServerUrl) {
111
- console.log(`\u{1F3AD} Running Playwright E2E tests on ${devServerUrl}`);
112
- const { runContractTestsPlaywright } = await import('./contractTestRunnerPlaywright-P5QZAIDR.js');
113
- contract = await runContractTestsPlaywright(componentName, devServerUrl);
114
- } else {
115
- console.log(`\u{1F9EA} Running jsdom tests (limited event handling)`);
116
- console.log(`\u26A0\uFE0F No dev server detected. Some tests may be skipped.
117
- For full coverage start your dev server and provide a URL.
118
- `);
105
+ if (url) {
106
+ const devServerUrl = await checkDevServer(url);
107
+ if (devServerUrl) {
108
+ console.log(`\u{1F3AD} Running Playwright tests on ${devServerUrl}`);
109
+ const { runContractTestsPlaywright } = await import('./contractTestRunnerPlaywright-LJHY3AB4.js');
110
+ contract = await runContractTestsPlaywright(componentName, devServerUrl);
111
+ } else {
112
+ throw new Error(
113
+ `\u274C Dev server not running at ${url}
114
+ Please start your dev server and try again.`
115
+ );
116
+ }
117
+ } else if (component) {
118
+ console.log(`\u{1F3AD} Running component contract tests in JSDOM mode`);
119
119
  contract = await runContractTests(componentName, component);
120
+ } else {
121
+ throw new Error("\u274C Either component or URL must be provided");
120
122
  }
121
123
  } catch (error) {
122
124
  if (error instanceof Error) {
@@ -182,5 +184,8 @@ if (typeof window === "undefined") {
182
184
  );
183
185
  };
184
186
  }
187
+ async function cleanupTests() {
188
+ await closeSharedBrowser();
189
+ }
185
190
 
186
- export { runTest, testUiComponent };
191
+ export { cleanupTests, runTest, testUiComponent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aria-ease",
3
- "version": "5.0.3",
3
+ "version": "6.0.1",
4
4
  "description": "Out-of-the-box accessibility utility package to develop production ready applications.",
5
5
  "main": "dist/index.cjs",
6
6
  "type": "module",
@@ -126,11 +126,11 @@
126
126
  "dependencies": {
127
127
  "chalk": "^5.6.2",
128
128
  "commander": "^14.0.1",
129
- "fs-extra": "^11.3.2",
130
- "playwright": "^1.57.0"
129
+ "fs-extra": "^11.3.2"
131
130
  },
132
131
  "peerDependencies": {
133
- "@axe-core/playwright": "^4.10.2"
132
+ "@axe-core/playwright": "^4.10.2",
133
+ "playwright": "^1.57.0"
134
134
  },
135
135
  "peerDependenciesMeta": {
136
136
  "@axe-core/playwright": {