@dereekb/vitest 13.5.2 → 13.6.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.
package/package.json CHANGED
@@ -1,10 +1,20 @@
1
1
  {
2
2
  "name": "@dereekb/vitest",
3
- "version": "13.5.2",
3
+ "version": "13.6.1",
4
4
  "peerDependencies": {
5
5
  "@vitest/expect": "4.1.0",
6
+ "axe-core": "^4.11.1",
6
7
  "date-fns": "^4.0.0",
7
- "vitest": "4.1.0"
8
+ "vitest": "4.1.0",
9
+ "vitest-axe": "^0.1.0"
10
+ },
11
+ "peerDependenciesMeta": {
12
+ "axe-core": {
13
+ "optional": true
14
+ },
15
+ "vitest-axe": {
16
+ "optional": true
17
+ }
8
18
  },
9
19
  "exports": {
10
20
  ".": {
@@ -14,6 +24,10 @@
14
24
  "./extend": {
15
25
  "types": "./src/extend.d.ts",
16
26
  "default": "./src/extend.js"
27
+ },
28
+ "./a11y": {
29
+ "types": "./src/a11y.d.ts",
30
+ "default": "./src/a11y.js"
17
31
  }
18
32
  },
19
33
  "types": "./src/index.d.ts",
package/src/a11y.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Extend entry point for vitest-axe a11y matchers.
3
+ *
4
+ * This is a separate entry point from `./extend` (which registers date matchers)
5
+ * because `vitest-axe` and `axe-core` are optional peer dependencies. Keeping them
6
+ * in a dedicated entry point means consumers who only need date matchers don't
7
+ * require the a11y packages to be installed.
8
+ *
9
+ * The `declare module 'vitest'` augmentation ships with the npm package so downstream
10
+ * consumers get types automatically. Within this workspace, `vitest.setup.typings.ts`
11
+ * also declares the same augmentation so the IDE resolves types from `tsconfig.spec.json`.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // In a vitest setup file (e.g. vitest.setup.angular.ts):
16
+ * import '@dereekb/vitest/a11y';
17
+ *
18
+ * const results = await axe(element);
19
+ * expect(results).toHaveNoViolations();
20
+ * ```
21
+ */
22
+ import 'vitest';
23
+ import type { AxeMatchers } from './lib/matcher.a11y.js';
24
+ declare module 'vitest' {
25
+ interface Assertion extends AxeMatchers {
26
+ }
27
+ interface AsymmetricMatchersContaining extends AxeMatchers {
28
+ }
29
+ }
package/src/a11y.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Extend entry point for vitest-axe a11y matchers.
3
+ *
4
+ * This is a separate entry point from `./extend` (which registers date matchers)
5
+ * because `vitest-axe` and `axe-core` are optional peer dependencies. Keeping them
6
+ * in a dedicated entry point means consumers who only need date matchers don't
7
+ * require the a11y packages to be installed.
8
+ *
9
+ * The `declare module 'vitest'` augmentation ships with the npm package so downstream
10
+ * consumers get types automatically. Within this workspace, `vitest.setup.typings.ts`
11
+ * also declares the same augmentation so the IDE resolves types from `tsconfig.spec.json`.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // In a vitest setup file (e.g. vitest.setup.angular.ts):
16
+ * import '@dereekb/vitest/a11y';
17
+ *
18
+ * const results = await axe(element);
19
+ * expect(results).toHaveNoViolations();
20
+ * ```
21
+ */
22
+ import 'vitest';
23
+ import { expect } from 'vitest';
24
+ import { allA11yMatchers } from './lib/matcher.a11y.js';
25
+ expect.extend(allA11yMatchers);
26
+ //# sourceMappingURL=a11y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a11y.js","sourceRoot":"","sources":["../../../../packages/vitest/src/a11y.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC"}
package/src/extend.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Extend entry point for date matchers.
3
+ *
4
+ * A11y matchers (vitest-axe) are registered separately via `@dereekb/vitest/a11y`
5
+ * because `vitest-axe` and `axe-core` are optional peer dependencies.
6
+ *
7
+ * @see {@link file://./a11y.ts} for the a11y extend entry point.
8
+ */
1
9
  import 'vitest';
2
10
  import type { AllDateMatchers } from './lib/matcher.date.js';
3
11
  declare module 'vitest' {
package/src/extend.js CHANGED
@@ -1,4 +1,12 @@
1
- // File Stucture derived from https://github.com/stschulte/aws-sdk-client-mock-vitest
1
+ /**
2
+ * Extend entry point for date matchers.
3
+ *
4
+ * A11y matchers (vitest-axe) are registered separately via `@dereekb/vitest/a11y`
5
+ * because `vitest-axe` and `axe-core` are optional peer dependencies.
6
+ *
7
+ * @see {@link file://./a11y.ts} for the a11y extend entry point.
8
+ */
9
+ // File structure derived from https://github.com/stschulte/aws-sdk-client-mock-vitest
2
10
  import 'vitest';
3
11
  import { expect } from 'vitest';
4
12
  import { allDateMatchers } from './lib/matcher.date.js';
package/src/extend.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"extend.js","sourceRoot":"","sources":["../../../../packages/vitest/src/extend.ts"],"names":[],"mappings":"AAAA,qFAAqF;AAErF,OAAO,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC"}
1
+ {"version":3,"file":"extend.js","sourceRoot":"","sources":["../../../../packages/vitest/src/extend.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,sFAAsF;AAEtF,OAAO,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC"}
@@ -1 +1,2 @@
1
1
  export * from './matcher.date.js';
2
+ export * from './matcher.a11y.js';
package/src/lib/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './matcher.date.js';
2
+ export * from './matcher.a11y.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/vitest/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/vitest/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,61 @@
1
+ import * as matchers from 'vitest-axe/matchers';
2
+ import type AxeCore from 'axe-core';
3
+ export type { AxeMatchers } from 'vitest-axe/matchers';
4
+ /**
5
+ * Object or wrapper that exposes a native DOM element, such as Angular's `ComponentFixture`.
6
+ */
7
+ export interface NativeElementRef {
8
+ readonly nativeElement: Element;
9
+ }
10
+ /**
11
+ * Input accepted by a11y helpers: a raw DOM element or any object exposing `nativeElement`.
12
+ */
13
+ export type A11yTestTarget = Element | NativeElementRef;
14
+ /**
15
+ * All vitest-axe matchers, ready to register via `expect.extend()`.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { allA11yMatchers } from '@dereekb/vitest';
20
+ * expect.extend(allA11yMatchers);
21
+ *
22
+ * const results = await axe(document.body);
23
+ * expect(results).toHaveNoViolations();
24
+ * ```
25
+ */
26
+ export declare const allA11yMatchers: typeof matchers;
27
+ /**
28
+ * Runs axe-core on a target element and asserts zero accessibility violations.
29
+ *
30
+ * Accepts a raw DOM `Element` or any object with a `nativeElement` property (e.g. Angular `ComponentFixture`).
31
+ *
32
+ * @param target - Element or fixture to test.
33
+ * @param options - Optional axe-core run options.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // With Angular ComponentFixture
38
+ * await expectNoA11yViolations(fixture);
39
+ *
40
+ * // With raw element
41
+ * await expectNoA11yViolations(document.getElementById('app')!);
42
+ * ```
43
+ */
44
+ export declare function expectNoA11yViolations(target: A11yTestTarget, options?: AxeCore.RunOptions): Promise<void>;
45
+ /**
46
+ * Runs axe-core on a target element and returns the results without asserting.
47
+ *
48
+ * Useful when you need to inspect violations or filter results before asserting.
49
+ *
50
+ * @param target - Element or fixture to check.
51
+ * @param options - Optional axe-core run options.
52
+ * @returns The axe-core results object.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const results = await getA11yResults(fixture);
57
+ * const critical = results.violations.filter(v => v.impact === 'critical');
58
+ * expect(critical).toHaveLength(0);
59
+ * ```
60
+ */
61
+ export declare function getA11yResults(target: A11yTestTarget, options?: AxeCore.RunOptions): Promise<AxeCore.AxeResults>;
@@ -0,0 +1,60 @@
1
+ import { expect } from 'vitest';
2
+ import * as matchers from 'vitest-axe/matchers';
3
+ import { axe } from 'vitest-axe';
4
+ function resolveElement(target) {
5
+ return 'nativeElement' in target ? target.nativeElement : target;
6
+ }
7
+ /**
8
+ * All vitest-axe matchers, ready to register via `expect.extend()`.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { allA11yMatchers } from '@dereekb/vitest';
13
+ * expect.extend(allA11yMatchers);
14
+ *
15
+ * const results = await axe(document.body);
16
+ * expect(results).toHaveNoViolations();
17
+ * ```
18
+ */
19
+ export const allA11yMatchers = matchers;
20
+ /**
21
+ * Runs axe-core on a target element and asserts zero accessibility violations.
22
+ *
23
+ * Accepts a raw DOM `Element` or any object with a `nativeElement` property (e.g. Angular `ComponentFixture`).
24
+ *
25
+ * @param target - Element or fixture to test.
26
+ * @param options - Optional axe-core run options.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * // With Angular ComponentFixture
31
+ * await expectNoA11yViolations(fixture);
32
+ *
33
+ * // With raw element
34
+ * await expectNoA11yViolations(document.getElementById('app')!);
35
+ * ```
36
+ */
37
+ export async function expectNoA11yViolations(target, options) {
38
+ const results = await axe(resolveElement(target), options);
39
+ expect(results).toHaveNoViolations();
40
+ }
41
+ /**
42
+ * Runs axe-core on a target element and returns the results without asserting.
43
+ *
44
+ * Useful when you need to inspect violations or filter results before asserting.
45
+ *
46
+ * @param target - Element or fixture to check.
47
+ * @param options - Optional axe-core run options.
48
+ * @returns The axe-core results object.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const results = await getA11yResults(fixture);
53
+ * const critical = results.violations.filter(v => v.impact === 'critical');
54
+ * expect(critical).toHaveLength(0);
55
+ * ```
56
+ */
57
+ export async function getA11yResults(target, options) {
58
+ return axe(resolveElement(target), options);
59
+ }
60
+ //# sourceMappingURL=matcher.a11y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matcher.a11y.js","sourceRoot":"","sources":["../../../../../packages/vitest/src/lib/matcher.a11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAiBjC,SAAS,cAAc,CAAC,MAAsB;IAC5C,OAAO,eAAe,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,MAAsB,EAAE,OAA4B;IAC/F,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;IAC3D,MAAM,CAAC,OAAO,CAAC,CAAC,kBAAkB,EAAE,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAsB,EAAE,OAA4B;IACvF,OAAO,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC"}