@noeldemartin/solid-utils 0.6.0-next.8a6a0b585adc7a1c329fb0fed5c420bb72cdccda → 0.6.0-next.956cbec11a55691bab3170059fa908865d683e20

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.
@@ -0,0 +1,20 @@
1
+ import { expect } from 'vitest';
2
+
3
+ import matchers from './matchers';
4
+
5
+ export type VitestSolidMatchers<R = unknown> = {
6
+ [K in keyof typeof matchers]: (
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ ...args: Parameters<(typeof matchers)[K]> extends [any, ...infer Rest] ? Rest : never
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ ) => ReturnType<(typeof matchers)[K]> extends Promise<any> ? Promise<R> : R;
11
+ };
12
+
13
+ export function installVitestSolidMatchers(): void {
14
+ expect.extend(matchers);
15
+ }
16
+
17
+ declare module '@vitest/expect' {
18
+ interface Assertion<T> extends VitestSolidMatchers<T> {}
19
+ interface AsymmetricMatchersContaining extends VitestSolidMatchers {}
20
+ }
@@ -0,0 +1,68 @@
1
+ import type { MatcherState, MatchersObject } from '@vitest/expect';
2
+
3
+ import { normalizeSparql, normalizeTurtle } from '@noeldemartin/solid-utils/helpers/io';
4
+ import { jsonldEquals, sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';
5
+ import type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';
6
+ import type { JsonLD } from '@noeldemartin/solid-utils/helpers';
7
+
8
+ interface FormatResultOptions {
9
+ state: MatcherState;
10
+ hint: string;
11
+ expected: unknown;
12
+ received: unknown;
13
+ }
14
+
15
+ function formatResult(result: EqualityResult, options: FormatResultOptions) {
16
+ const pass = result.success;
17
+ const utils = options.state.utils;
18
+ const message = pass
19
+ ? () => [result.message, utils.matcherHint(options.hint)].join('\n\n')
20
+ : () =>
21
+ [
22
+ result.message,
23
+ utils.matcherHint(options.hint),
24
+ [
25
+ `Expected: not ${utils.printExpected(options.expected)}`,
26
+ `Received: ${utils.printReceived(options.received)}`,
27
+ ].join('\n'),
28
+ ].join('\n\n');
29
+
30
+ return { pass, message };
31
+ }
32
+
33
+ export function defineMatchers<T extends MatchersObject>(matchers: T): T {
34
+ return matchers;
35
+ }
36
+
37
+ export default defineMatchers({
38
+ async toEqualJsonLD(received, expected: JsonLD) {
39
+ const result = await jsonldEquals(expected, received);
40
+
41
+ return formatResult(result, {
42
+ state: this,
43
+ hint: 'toEqualJsonLD',
44
+ expected,
45
+ received,
46
+ });
47
+ },
48
+ toEqualSparql(received, expected: string) {
49
+ const result = sparqlEquals(expected, received);
50
+
51
+ return formatResult(result, {
52
+ state: this,
53
+ hint: 'toEqualSparql',
54
+ expected: normalizeSparql(expected),
55
+ received: normalizeSparql(received),
56
+ });
57
+ },
58
+ toEqualTurtle(received, expected: string) {
59
+ const result = turtleEquals(expected, received);
60
+
61
+ return formatResult(result, {
62
+ state: this,
63
+ hint: 'toEqualTurtle',
64
+ expected: normalizeTurtle(expected),
65
+ received: normalizeTurtle(received),
66
+ });
67
+ },
68
+ });
package/src/types/n3.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import '@types/n3';
2
2
 
3
3
  declare module 'n3' {
4
-
5
4
  interface Parser {
6
5
  _resolveRelativeIRI(iri: string): string;
7
6
  }
8
-
9
7
  }