@noeldemartin/solid-utils 0.6.0-next.70fba2db4562da63a3ae210c80936d148acfc0de → 0.6.0-next.851da2f1bc379a62ccbf7fcdef05b34e6e9ea4ae

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.
@@ -2,12 +2,17 @@ import { BlankNode } from '@rdfjs/types';
2
2
  import { JSError } from '@noeldemartin/utils';
3
3
  import { JSErrorOptions } from '@noeldemartin/utils';
4
4
  import { Literal } from '@rdfjs/types';
5
+ import { MatcherState } from '@vitest/expect';
5
6
  import { NamedNode } from '@rdfjs/types';
6
7
  import { Quad } from '@rdfjs/types';
7
8
  import { Variable } from '@rdfjs/types';
8
9
 
9
10
  export declare type AnyFetch = (input: any, options?: any) => Promise<Response>;
10
11
 
12
+ export declare type ChaiSolidAssertions = {
13
+ [assertion in keyof typeof _default]: (typeof _default)[assertion];
14
+ };
15
+
11
16
  export declare function compactJsonLDGraph(json: JsonLDGraph): Promise<JsonLDGraph>;
12
17
 
13
18
  /**
@@ -22,6 +27,27 @@ export declare function createPublicTypeIndex(user: SolidUserProfile, fetch?: Fe
22
27
 
23
28
  export declare function createSolidDocument(url: string, body: string, fetch?: Fetch): Promise<SolidDocument>;
24
29
 
30
+ declare const _default: {
31
+ turtle(this: Chai.AssertionStatic, graph: string): void;
32
+ sparql(this: Chai.AssertionStatic, query: string): void;
33
+ equalityResult(this: Chai.AssertionStatic): void;
34
+ };
35
+
36
+ declare const _default_2: {
37
+ toEqualJsonLD(this: MatcherState, received: any, expected: JsonLD): Promise<{
38
+ pass: boolean;
39
+ message: () => string;
40
+ }>;
41
+ toEqualSparql(this: MatcherState, received: any, expected: string): {
42
+ pass: boolean;
43
+ message: () => string;
44
+ };
45
+ toEqualTurtle(this: MatcherState, received: any, expected: string): {
46
+ pass: boolean;
47
+ message: () => string;
48
+ };
49
+ };
50
+
25
51
  export declare function defineIRIPrefix(name: string, value: string): void;
26
52
 
27
53
  export declare function expandIRI(iri: string, options?: Partial<ExpandIRIOptions>): string;
@@ -237,4 +263,26 @@ export declare class UnsupportedAuthorizationProtocolError extends JSError {
237
263
 
238
264
  export declare function updateSolidDocument(url: string, body: string, fetch?: Fetch): Promise<void>;
239
265
 
266
+ export declare type VitestSolidMatchers<R = unknown> = {
267
+ [K in keyof typeof _default_2]: (...args: Parameters<(typeof _default_2)[K]> extends [any, ...infer Rest] ? Rest : never) => ReturnType<(typeof _default_2)[K]> extends Promise<any> ? Promise<R> : R;
268
+ };
269
+
240
270
  export { }
271
+
272
+
273
+ declare module '@vitest/expect' {
274
+ interface Assertion<T> extends VitestSolidMatchers<T> {
275
+ }
276
+ interface AsymmetricMatchersContaining extends VitestSolidMatchers {
277
+ }
278
+ }
279
+
280
+
281
+ declare global {
282
+ namespace Chai {
283
+ interface Assertion extends ChaiSolidAssertions {
284
+ }
285
+ interface Include extends ChaiSolidAssertions {
286
+ }
287
+ }
288
+ }
package/dist/testing.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { MatcherState } from '@vitest/expect';
2
2
 
3
+ export declare type ChaiSolidAssertions = {
4
+ [assertion in keyof typeof _default_2]: (typeof _default_2)[assertion];
5
+ };
6
+
3
7
  declare const _default: {
4
8
  toEqualJsonLD(this: MatcherState, received: any, expected: JsonLD): Promise<{
5
9
  pass: boolean;
@@ -15,6 +19,12 @@ declare const _default: {
15
19
  };
16
20
  };
17
21
 
22
+ declare const _default_2: {
23
+ turtle(this: Chai.AssertionStatic, graph: string): void;
24
+ sparql(this: Chai.AssertionStatic, query: string): void;
25
+ equalityResult(this: Chai.AssertionStatic): void;
26
+ };
27
+
18
28
  export declare interface EqualityResult {
19
29
  success: boolean;
20
30
  message: string;
@@ -22,6 +32,8 @@ export declare interface EqualityResult {
22
32
  actual: string;
23
33
  }
24
34
 
35
+ export declare function installChaiPlugin(): void;
36
+
25
37
  export declare function installVitestSolidMatchers(): void;
26
38
 
27
39
  declare type JsonLD = Partial<{
@@ -43,3 +55,21 @@ export declare type VitestSolidMatchers<R = unknown> = {
43
55
  };
44
56
 
45
57
  export { }
58
+
59
+
60
+ declare module '@vitest/expect' {
61
+ interface Assertion<T> extends VitestSolidMatchers<T> {
62
+ }
63
+ interface AsymmetricMatchersContaining extends VitestSolidMatchers {
64
+ }
65
+ }
66
+
67
+
68
+ declare global {
69
+ namespace Chai {
70
+ interface Assertion extends ChaiSolidAssertions {
71
+ }
72
+ interface Include extends ChaiSolidAssertions {
73
+ }
74
+ }
75
+ }
package/dist/testing.js CHANGED
@@ -1,125 +1,125 @@
1
1
  import { expect as Q } from "vitest";
2
- import { j as g, g as E, k as q, h as y, l as T, e as $, n as v } from "./io-CMHtz5bu.js";
3
- import { pull as w, arrayRemove as b, JSError as R, stringMatchAll as S } from "@noeldemartin/utils";
4
- let i = {};
2
+ import { j as g, g as E, k as q, h as b, l as T, e as j, n as y } from "./io-CMHtz5bu.js";
3
+ import { pull as $, arrayRemove as R, JSError as O, stringMatchAll as S } from "@noeldemartin/utils";
4
+ let c = {};
5
5
  const k = {
6
6
  "%uuid%": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
7
7
  };
8
- class c extends R {
8
+ class i extends O {
9
9
  constructor(e) {
10
- super(`Couldn't find the following triple: ${y(e)}`), this.expectedQuad = e;
10
+ super(`Couldn't find the following triple: ${b(e)}`), this.expectedQuad = e;
11
11
  }
12
12
  }
13
13
  function p(t, e) {
14
- for (const n of t) {
15
- const r = e.find((a) => z(n, a));
16
- if (!r) throw new c(n);
17
- b(e, r);
14
+ for (const s of t) {
15
+ const n = e.find((a) => P(s, a));
16
+ if (!n) throw new i(s);
17
+ R(e, n);
18
18
  }
19
19
  }
20
- function j(t) {
20
+ function v(t) {
21
21
  return /\[\[(.*\]\[)?([^\]]+)\]\]/.test(t);
22
22
  }
23
- function x(t) {
24
- const e = [], n = S(t, /\[\[((.*?)\]\[)?([^\]]+)\]\]/g), r = [];
23
+ function A(t) {
24
+ const e = [], s = S(t, /\[\[((.*?)\]\[)?([^\]]+)\]\]/g), n = [];
25
25
  let a = t;
26
- for (const s of n)
27
- s[2] && e.push(s[2]), r.push(s[3]), a = a.replace(s[0], `%PATTERN${r.length - 1}%`);
26
+ for (const r of s)
27
+ r[2] && e.push(r[2]), n.push(r[3]), a = a.replace(r[0], `%PATTERN${n.length - 1}%`);
28
28
  a = a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
29
- for (const [s, o] of Object.entries(r))
30
- a = a.replace(`%PATTERN${s}%`, k[o] ?? o);
29
+ for (const [r, o] of Object.entries(n))
30
+ a = a.replace(`%PATTERN${r}%`, k[o] ?? o);
31
31
  return new RegExp(a);
32
32
  }
33
33
  function h(t, e) {
34
- return j(t) ? (i[t] ?? (i[t] = x(t))).test(e) : t === e;
34
+ return v(t) ? (c[t] ?? (c[t] = A(t))).test(e) : t === e;
35
35
  }
36
- function O(t, e) {
36
+ function M(t, e) {
37
37
  if (t.termType !== e.termType) return !1;
38
38
  if (t.termType === "Literal" && e.termType === "Literal") {
39
39
  if (t.datatype.value !== e.datatype.value) return !1;
40
- if (!j(t.value))
40
+ if (!v(t.value))
41
41
  return t.datatype.value === "http://www.w3.org/2001/XMLSchema#dateTime" ? new Date(t.value).getTime() === new Date(e.value).getTime() : t.value === e.value;
42
42
  }
43
43
  return h(t.value, e.value);
44
44
  }
45
- function z(t, e) {
46
- return O(t.object, e.object) && h(t.subject.value, e.subject.value) && h(t.predicate.value, e.predicate.value);
45
+ function P(t, e) {
46
+ return M(t.object, e.object) && h(t.subject.value, e.subject.value) && h(t.predicate.value, e.predicate.value);
47
47
  }
48
48
  function m() {
49
- i = {};
49
+ c = {};
50
50
  }
51
- async function M(t, e) {
51
+ async function z(t, e) {
52
52
  m();
53
- const n = await g(t), r = await g(e), a = E(n), s = E(r), o = (u, l) => ({
53
+ const s = await g(t), n = await g(e), a = E(s), r = E(n), o = (u, l) => ({
54
54
  success: u,
55
55
  message: l,
56
56
  expected: a,
57
- actual: s
57
+ actual: r
58
58
  });
59
- if (n.length !== r.length)
60
- return o(!1, `Expected ${n.length} triples, found ${r.length}.`);
59
+ if (s.length !== n.length)
60
+ return o(!1, `Expected ${s.length} triples, found ${n.length}.`);
61
61
  try {
62
- p(n, r);
62
+ p(s, n);
63
63
  } catch (u) {
64
- if (!(u instanceof c)) throw u;
64
+ if (!(u instanceof i)) throw u;
65
65
  return o(!1, u.message);
66
66
  }
67
67
  return o(!0, "jsonld matches");
68
68
  }
69
- function N(t, e) {
69
+ function w(t, e) {
70
70
  m();
71
- const n = q(t, { normalizeBlankNodes: !0 }), r = q(e, { normalizeBlankNodes: !0 }), a = (o, u) => ({ success: o, message: u, expected: t, actual: e });
72
- for (const o of Object.keys(n)) {
73
- if (!(o in r)) return a(!1, `Couldn't find expected ${o} operation.`);
74
- const u = w(n, o), l = w(r, o);
71
+ const s = q(t, { normalizeBlankNodes: !0 }), n = q(e, { normalizeBlankNodes: !0 }), a = (o, u) => ({ success: o, message: u, expected: t, actual: e });
72
+ for (const o of Object.keys(s)) {
73
+ if (!(o in n)) return a(!1, `Couldn't find expected ${o} operation.`);
74
+ const u = $(s, o), l = $(n, o);
75
75
  if (u.length !== l.length)
76
76
  return a(!1, `Expected ${u.length} ${o} triples, found ${l.length}.`);
77
77
  try {
78
78
  p(u, l);
79
79
  } catch (f) {
80
- if (!(f instanceof c)) throw f;
80
+ if (!(f instanceof i)) throw f;
81
81
  return a(
82
82
  !1,
83
- `Couldn't find the following ${o} triple: ${y(f.expectedQuad)}`
83
+ `Couldn't find the following ${o} triple: ${b(f.expectedQuad)}`
84
84
  );
85
85
  }
86
86
  }
87
- const s = Object.keys(r)[0] ?? null;
88
- return s ? a(!1, `Did not expect to find ${s} triples.`) : a(!0, "sparql matches");
87
+ const r = Object.keys(n)[0] ?? null;
88
+ return r ? a(!1, `Did not expect to find ${r} triples.`) : a(!0, "sparql matches");
89
89
  }
90
- function P(t, e) {
90
+ function x(t, e) {
91
91
  m();
92
- const n = T(t, { normalizeBlankNodes: !0 }), r = T(e, { normalizeBlankNodes: !0 }), a = (s, o) => ({ success: s, message: o, expected: t, actual: e });
93
- if (n.length !== r.length)
94
- return a(!1, `Expected ${n.length} triples, found ${r.length}.`);
92
+ const s = T(t, { normalizeBlankNodes: !0 }), n = T(e, { normalizeBlankNodes: !0 }), a = (r, o) => ({ success: r, message: o, expected: t, actual: e });
93
+ if (s.length !== n.length)
94
+ return a(!1, `Expected ${s.length} triples, found ${n.length}.`);
95
95
  try {
96
- p(n, r);
97
- } catch (s) {
98
- if (!(s instanceof c)) throw s;
99
- return a(!1, s.message);
96
+ p(s, n);
97
+ } catch (r) {
98
+ if (!(r instanceof i)) throw r;
99
+ return a(!1, r.message);
100
100
  }
101
101
  return a(!0, "turtle matches");
102
102
  }
103
103
  function d(t, e) {
104
- const n = t.success, r = e.state.utils;
105
- return { pass: n, message: n ? () => [t.message, r.matcherHint(e.hint)].join(`
104
+ const s = t.success, n = e.state.utils;
105
+ return { pass: s, message: s ? () => [t.message, n.matcherHint(e.hint)].join(`
106
106
 
107
107
  `) : () => [
108
108
  t.message,
109
- r.matcherHint(e.hint),
109
+ n.matcherHint(e.hint),
110
110
  [
111
- `Expected: not ${r.printExpected(e.expected)}`,
112
- `Received: ${r.printReceived(e.received)}`
111
+ `Expected: not ${n.printExpected(e.expected)}`,
112
+ `Received: ${n.printReceived(e.received)}`
113
113
  ].join(`
114
114
  `)
115
115
  ].join(`
116
116
 
117
117
  `) };
118
118
  }
119
- const A = {
119
+ const N = {
120
120
  async toEqualJsonLD(t, e) {
121
- const n = await M(e, t);
122
- return d(n, {
121
+ const s = await z(e, t);
122
+ return d(s, {
123
123
  state: this,
124
124
  hint: "toEqualJsonLD",
125
125
  expected: e,
@@ -127,31 +127,50 @@ const A = {
127
127
  });
128
128
  },
129
129
  toEqualSparql(t, e) {
130
- const n = N(e, t);
131
- return d(n, {
130
+ const s = w(e, t);
131
+ return d(s, {
132
132
  state: this,
133
133
  hint: "toEqualSparql",
134
- expected: v(e),
135
- received: v(t)
134
+ expected: y(e),
135
+ received: y(t)
136
136
  });
137
137
  },
138
138
  toEqualTurtle(t, e) {
139
- const n = P(e, t);
140
- return d(n, {
139
+ const s = x(e, t);
140
+ return d(s, {
141
141
  state: this,
142
142
  hint: "toEqualTurtle",
143
- expected: $(e),
144
- received: $(t)
143
+ expected: j(e),
144
+ received: j(t)
145
145
  });
146
146
  }
147
147
  };
148
- function C() {
149
- Q.extend(A);
148
+ function J() {
149
+ Q.extend(N);
150
+ }
151
+ const C = {
152
+ turtle(t) {
153
+ const e = this, s = e._obj, n = e.assert.bind(this), r = x(t, s);
154
+ n(r.success, r.message, "", r.expected, r.actual);
155
+ },
156
+ sparql(t) {
157
+ const e = this, s = e._obj, n = e.assert.bind(this), r = w(t, s);
158
+ n(r.success, r.message, "", r.expected, r.actual);
159
+ },
160
+ equalityResult() {
161
+ const t = this, e = t._obj;
162
+ t.assert.bind(this)(e.success, e.message, "", e.expected, e.actual);
163
+ }
164
+ };
165
+ function _() {
166
+ var t;
167
+ (t = globalThis.chai) == null || t.use((e) => Object.entries(C).forEach(([s, n]) => e.Assertion.addMethod(s, n)));
150
168
  }
151
169
  export {
152
- C as installVitestSolidMatchers,
153
- M as jsonldEquals,
154
- N as sparqlEquals,
155
- P as turtleEquals
170
+ _ as installChaiPlugin,
171
+ J as installVitestSolidMatchers,
172
+ z as jsonldEquals,
173
+ w as sparqlEquals,
174
+ x as turtleEquals
156
175
  };
157
176
  //# sourceMappingURL=testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","sources":["../src/testing/helpers.ts","../src/testing/vitest/matchers.ts","../src/testing/vitest/index.ts"],"sourcesContent":["import { JSError, arrayRemove, pull, stringMatchAll } from '@noeldemartin/utils';\nimport type { Quad, Quad_Object } from '@rdfjs/types';\n\nimport {\n jsonldToQuads,\n quadToTurtle,\n quadsToTurtle,\n sparqlToQuadsSync,\n turtleToQuadsSync,\n} from '@noeldemartin/solid-utils/helpers/io';\nimport type { JsonLD } from '@noeldemartin/solid-utils/helpers/jsonld';\n\nlet patternsRegExpsIndex: Record<string, RegExp> = {};\nconst builtInPatterns: Record<string, string> = {\n '%uuid%': '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',\n};\n\nclass ExpectedQuadAssertionError extends JSError {\n\n constructor(public readonly expectedQuad: Quad) {\n super(`Couldn't find the following triple: ${quadToTurtle(expectedQuad)}`);\n }\n\n}\n\nfunction assertExpectedQuadsExist(expectedQuads: Quad[], actualQuads: Quad[]): void {\n for (const expectedQuad of expectedQuads) {\n const matchingQuad = actualQuads.find((actualQuad) => quadEquals(expectedQuad, actualQuad));\n\n if (!matchingQuad) throw new ExpectedQuadAssertionError(expectedQuad);\n\n arrayRemove(actualQuads, matchingQuad);\n }\n}\n\nfunction containsPatterns(value: string): boolean {\n return /\\[\\[(.*\\]\\[)?([^\\]]+)\\]\\]/.test(value);\n}\n\nfunction createPatternRegexp(expected: string): RegExp {\n const patternAliases = [];\n const patternMatches = stringMatchAll<4, 1 | 2>(expected, /\\[\\[((.*?)\\]\\[)?([^\\]]+)\\]\\]/g);\n const patterns: string[] = [];\n let expectedRegExp = expected;\n\n for (const patternMatch of patternMatches) {\n patternMatch[2] && patternAliases.push(patternMatch[2]);\n\n patterns.push(patternMatch[3]);\n\n expectedRegExp = expectedRegExp.replace(patternMatch[0], `%PATTERN${patterns.length - 1}%`);\n }\n\n expectedRegExp = expectedRegExp.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\n\n for (const [patternIndex, pattern] of Object.entries(patterns)) {\n expectedRegExp = expectedRegExp.replace(`%PATTERN${patternIndex}%`, builtInPatterns[pattern] ?? pattern);\n }\n\n return new RegExp(expectedRegExp);\n}\n\nfunction quadValueEquals(expected: string, actual: string): boolean {\n return containsPatterns(expected)\n ? (patternsRegExpsIndex[expected] ??= createPatternRegexp(expected)).test(actual)\n : expected === actual;\n}\n\nfunction quadObjectEquals(expected: Quad_Object, actual: Quad_Object): boolean {\n if (expected.termType !== actual.termType) return false;\n\n if (expected.termType === 'Literal' && actual.termType === 'Literal') {\n if (expected.datatype.value !== actual.datatype.value) return false;\n\n if (!containsPatterns(expected.value))\n return expected.datatype.value === 'http://www.w3.org/2001/XMLSchema#dateTime'\n ? new Date(expected.value).getTime() === new Date(actual.value).getTime()\n : expected.value === actual.value;\n }\n\n return quadValueEquals(expected.value, actual.value);\n}\n\nfunction quadEquals(expected: Quad, actual: Quad): boolean {\n return (\n quadObjectEquals(expected.object, actual.object) &&\n quadValueEquals(expected.subject.value, actual.subject.value) &&\n quadValueEquals(expected.predicate.value, actual.predicate.value)\n );\n}\n\nfunction resetPatterns(): void {\n patternsRegExpsIndex = {};\n}\n\nexport interface EqualityResult {\n success: boolean;\n message: string;\n expected: string;\n actual: string;\n}\n\nexport async function jsonldEquals(expected: JsonLD, actual: JsonLD): Promise<EqualityResult> {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedQuads = await jsonldToQuads(expected);\n const actualQuads = await jsonldToQuads(actual);\n const expectedTurtle = quadsToTurtle(expectedQuads);\n const actualTurtle = quadsToTurtle(actualQuads);\n const result = (success: boolean, message: string) => ({\n success,\n message,\n expected: expectedTurtle,\n actual: actualTurtle,\n });\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(false, error.message);\n }\n\n return result(true, 'jsonld matches');\n}\n\nexport function sparqlEquals(expected: string, actual: string): EqualityResult {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedOperations = sparqlToQuadsSync(expected, { normalizeBlankNodes: true });\n const actualOperations = sparqlToQuadsSync(actual, { normalizeBlankNodes: true });\n const result = (success: boolean, message: string) => ({ success, message, expected, actual });\n\n for (const operation of Object.keys(expectedOperations)) {\n if (!(operation in actualOperations)) return result(false, `Couldn't find expected ${operation} operation.`);\n\n const expectedQuads = pull(expectedOperations, operation);\n const actualQuads = pull(actualOperations, operation);\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} ${operation} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(\n false,\n `Couldn't find the following ${operation} triple: ${quadToTurtle(error.expectedQuad)}`,\n );\n }\n }\n\n const unexpectedOperation = Object.keys(actualOperations)[0] ?? null;\n if (unexpectedOperation) return result(false, `Did not expect to find ${unexpectedOperation} triples.`);\n\n return result(true, 'sparql matches');\n}\n\nexport function turtleEquals(expected: string, actual: string): EqualityResult {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedQuads = turtleToQuadsSync(expected, { normalizeBlankNodes: true });\n const actualQuads = turtleToQuadsSync(actual, { normalizeBlankNodes: true });\n const result = (success: boolean, message: string) => ({ success, message, expected, actual });\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(false, error.message);\n }\n\n return result(true, 'turtle matches');\n}\n","import type { MatcherState, MatchersObject } from '@vitest/expect';\n\nimport { normalizeSparql, normalizeTurtle } from '@noeldemartin/solid-utils/helpers/io';\nimport { jsonldEquals, sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { JsonLD } from '@noeldemartin/solid-utils/helpers';\n\ninterface FormatResultOptions {\n state: MatcherState;\n hint: string;\n expected: unknown;\n received: unknown;\n}\n\nfunction formatResult(result: EqualityResult, options: FormatResultOptions) {\n const pass = result.success;\n const utils = options.state.utils;\n const message = pass\n ? () => [result.message, utils.matcherHint(options.hint)].join('\\n\\n')\n : () =>\n [\n result.message,\n utils.matcherHint(options.hint),\n [\n `Expected: not ${utils.printExpected(options.expected)}`,\n `Received: ${utils.printReceived(options.received)}`,\n ].join('\\n'),\n ].join('\\n\\n');\n\n return { pass, message };\n}\n\nexport function defineMatchers<T extends MatchersObject>(matchers: T): T {\n return matchers;\n}\n\nexport default defineMatchers({\n async toEqualJsonLD(received, expected: JsonLD) {\n const result = await jsonldEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualJsonLD',\n expected,\n received,\n });\n },\n toEqualSparql(received, expected: string) {\n const result = sparqlEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualSparql',\n expected: normalizeSparql(expected),\n received: normalizeSparql(received),\n });\n },\n toEqualTurtle(received, expected: string) {\n const result = turtleEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualTurtle',\n expected: normalizeTurtle(expected),\n received: normalizeTurtle(received),\n });\n },\n});\n","import { expect } from 'vitest';\n\nimport matchers from './matchers';\n\nexport type VitestSolidMatchers<R = unknown> = {\n [K in keyof typeof matchers]: (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Parameters<(typeof matchers)[K]> extends [any, ...infer Rest] ? Rest : never\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => ReturnType<(typeof matchers)[K]> extends Promise<any> ? Promise<R> : R;\n};\n\nexport function installVitestSolidMatchers(): void {\n expect.extend(matchers);\n}\n"],"names":["patternsRegExpsIndex","builtInPatterns","ExpectedQuadAssertionError","JSError","expectedQuad","quadToTurtle","assertExpectedQuadsExist","expectedQuads","actualQuads","matchingQuad","actualQuad","quadEquals","arrayRemove","containsPatterns","value","createPatternRegexp","expected","patternAliases","patternMatches","stringMatchAll","patterns","expectedRegExp","patternMatch","patternIndex","pattern","quadValueEquals","actual","quadObjectEquals","resetPatterns","jsonldEquals","jsonldToQuads","expectedTurtle","quadsToTurtle","actualTurtle","result","success","message","error","sparqlEquals","expectedOperations","sparqlToQuadsSync","actualOperations","operation","pull","unexpectedOperation","turtleEquals","turtleToQuadsSync","formatResult","options","pass","utils","matchers","received","normalizeSparql","normalizeTurtle","installVitestSolidMatchers","expect"],"mappings":";;;AAYA,IAAIA,IAA+C,CAAC;AACpD,MAAMC,IAA0C;AAAA,EAC5C,UAAU;AACd;AAEA,MAAMC,UAAmCC,EAAQ;AAAA,EAE7C,YAA4BC,GAAoB;AAC5C,UAAM,uCAAuCC,EAAaD,CAAY,CAAC,EAAE,GADjD,KAAA,eAAAA;AAAA,EAAA;AAIhC;AAEA,SAASE,EAAyBC,GAAuBC,GAA2B;AAChF,aAAWJ,KAAgBG,GAAe;AAChC,UAAAE,IAAeD,EAAY,KAAK,CAACE,MAAeC,EAAWP,GAAcM,CAAU,CAAC;AAE1F,QAAI,CAACD,EAAoB,OAAA,IAAIP,EAA2BE,CAAY;AAEpE,IAAAQ,EAAYJ,GAAaC,CAAY;AAAA,EAAA;AAE7C;AAEA,SAASI,EAAiBC,GAAwB;AACvC,SAAA,4BAA4B,KAAKA,CAAK;AACjD;AAEA,SAASC,EAAoBC,GAA0B;AACnD,QAAMC,IAAiB,CAAC,GAClBC,IAAiBC,EAAyBH,GAAU,+BAA+B,GACnFI,IAAqB,CAAC;AAC5B,MAAIC,IAAiBL;AAErB,aAAWM,KAAgBJ;AACvB,IAAAI,EAAa,CAAC,KAAKL,EAAe,KAAKK,EAAa,CAAC,CAAC,GAE7CF,EAAA,KAAKE,EAAa,CAAC,CAAC,GAEZD,IAAAA,EAAe,QAAQC,EAAa,CAAC,GAAG,WAAWF,EAAS,SAAS,CAAC,GAAG;AAG7E,EAAAC,IAAAA,EAAe,QAAQ,4BAA4B,MAAM;AAE1E,aAAW,CAACE,GAAcC,CAAO,KAAK,OAAO,QAAQJ,CAAQ;AACxC,IAAAC,IAAAA,EAAe,QAAQ,WAAW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,IAAS,MAAML,EAAab,GAAUoC,CAAQ;AAEpD,WAAOL,EAAab,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAAlB;AAAA,MACA,UAAAoC;AAAA,IAAA,CACH;AAAA,EACL;AAAA,EACA,cAAcA,GAAUpC,GAAkB;AAChC,UAAAkB,IAASI,EAAatB,GAAUoC,CAAQ;AAE9C,WAAOL,EAAab,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAUmB,EAAgBrC,CAAQ;AAAA,MAClC,UAAUqC,EAAgBD,CAAQ;AAAA,IAAA,CACrC;AAAA,EACL;AAAA,EACA,cAAcA,GAAUpC,GAAkB;AAChC,UAAAkB,IAASW,EAAa7B,GAAUoC,CAAQ;AAE9C,WAAOL,EAAab,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAUoB,EAAgBtC,CAAQ;AAAA,MAClC,UAAUsC,EAAgBF,CAAQ;AAAA,IAAA,CACrC;AAAA,EAAA;AAET;ACvDO,SAASG,IAAmC;AAC/C,EAAAC,EAAO,OAAOL,CAAQ;AAC1B;"}
1
+ {"version":3,"file":"testing.js","sources":["../src/testing/helpers.ts","../src/testing/vitest/matchers.ts","../src/testing/vitest/index.ts","../src/testing/chai/assertions.ts","../src/testing/chai/index.ts"],"sourcesContent":["import { JSError, arrayRemove, pull, stringMatchAll } from '@noeldemartin/utils';\nimport type { Quad, Quad_Object } from '@rdfjs/types';\n\nimport {\n jsonldToQuads,\n quadToTurtle,\n quadsToTurtle,\n sparqlToQuadsSync,\n turtleToQuadsSync,\n} from '@noeldemartin/solid-utils/helpers/io';\nimport type { JsonLD } from '@noeldemartin/solid-utils/helpers/jsonld';\n\nlet patternsRegExpsIndex: Record<string, RegExp> = {};\nconst builtInPatterns: Record<string, string> = {\n '%uuid%': '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',\n};\n\nclass ExpectedQuadAssertionError extends JSError {\n\n constructor(public readonly expectedQuad: Quad) {\n super(`Couldn't find the following triple: ${quadToTurtle(expectedQuad)}`);\n }\n\n}\n\nfunction assertExpectedQuadsExist(expectedQuads: Quad[], actualQuads: Quad[]): void {\n for (const expectedQuad of expectedQuads) {\n const matchingQuad = actualQuads.find((actualQuad) => quadEquals(expectedQuad, actualQuad));\n\n if (!matchingQuad) throw new ExpectedQuadAssertionError(expectedQuad);\n\n arrayRemove(actualQuads, matchingQuad);\n }\n}\n\nfunction containsPatterns(value: string): boolean {\n return /\\[\\[(.*\\]\\[)?([^\\]]+)\\]\\]/.test(value);\n}\n\nfunction createPatternRegexp(expected: string): RegExp {\n const patternAliases = [];\n const patternMatches = stringMatchAll<4, 1 | 2>(expected, /\\[\\[((.*?)\\]\\[)?([^\\]]+)\\]\\]/g);\n const patterns: string[] = [];\n let expectedRegExp = expected;\n\n for (const patternMatch of patternMatches) {\n patternMatch[2] && patternAliases.push(patternMatch[2]);\n\n patterns.push(patternMatch[3]);\n\n expectedRegExp = expectedRegExp.replace(patternMatch[0], `%PATTERN${patterns.length - 1}%`);\n }\n\n expectedRegExp = expectedRegExp.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\n\n for (const [patternIndex, pattern] of Object.entries(patterns)) {\n expectedRegExp = expectedRegExp.replace(`%PATTERN${patternIndex}%`, builtInPatterns[pattern] ?? pattern);\n }\n\n return new RegExp(expectedRegExp);\n}\n\nfunction quadValueEquals(expected: string, actual: string): boolean {\n return containsPatterns(expected)\n ? (patternsRegExpsIndex[expected] ??= createPatternRegexp(expected)).test(actual)\n : expected === actual;\n}\n\nfunction quadObjectEquals(expected: Quad_Object, actual: Quad_Object): boolean {\n if (expected.termType !== actual.termType) return false;\n\n if (expected.termType === 'Literal' && actual.termType === 'Literal') {\n if (expected.datatype.value !== actual.datatype.value) return false;\n\n if (!containsPatterns(expected.value))\n return expected.datatype.value === 'http://www.w3.org/2001/XMLSchema#dateTime'\n ? new Date(expected.value).getTime() === new Date(actual.value).getTime()\n : expected.value === actual.value;\n }\n\n return quadValueEquals(expected.value, actual.value);\n}\n\nfunction quadEquals(expected: Quad, actual: Quad): boolean {\n return (\n quadObjectEquals(expected.object, actual.object) &&\n quadValueEquals(expected.subject.value, actual.subject.value) &&\n quadValueEquals(expected.predicate.value, actual.predicate.value)\n );\n}\n\nfunction resetPatterns(): void {\n patternsRegExpsIndex = {};\n}\n\nexport interface EqualityResult {\n success: boolean;\n message: string;\n expected: string;\n actual: string;\n}\n\nexport async function jsonldEquals(expected: JsonLD, actual: JsonLD): Promise<EqualityResult> {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedQuads = await jsonldToQuads(expected);\n const actualQuads = await jsonldToQuads(actual);\n const expectedTurtle = quadsToTurtle(expectedQuads);\n const actualTurtle = quadsToTurtle(actualQuads);\n const result = (success: boolean, message: string) => ({\n success,\n message,\n expected: expectedTurtle,\n actual: actualTurtle,\n });\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(false, error.message);\n }\n\n return result(true, 'jsonld matches');\n}\n\nexport function sparqlEquals(expected: string, actual: string): EqualityResult {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedOperations = sparqlToQuadsSync(expected, { normalizeBlankNodes: true });\n const actualOperations = sparqlToQuadsSync(actual, { normalizeBlankNodes: true });\n const result = (success: boolean, message: string) => ({ success, message, expected, actual });\n\n for (const operation of Object.keys(expectedOperations)) {\n if (!(operation in actualOperations)) return result(false, `Couldn't find expected ${operation} operation.`);\n\n const expectedQuads = pull(expectedOperations, operation);\n const actualQuads = pull(actualOperations, operation);\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} ${operation} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(\n false,\n `Couldn't find the following ${operation} triple: ${quadToTurtle(error.expectedQuad)}`,\n );\n }\n }\n\n const unexpectedOperation = Object.keys(actualOperations)[0] ?? null;\n if (unexpectedOperation) return result(false, `Did not expect to find ${unexpectedOperation} triples.`);\n\n return result(true, 'sparql matches');\n}\n\nexport function turtleEquals(expected: string, actual: string): EqualityResult {\n // TODO catch parsing errors and improve message.\n resetPatterns();\n\n const expectedQuads = turtleToQuadsSync(expected, { normalizeBlankNodes: true });\n const actualQuads = turtleToQuadsSync(actual, { normalizeBlankNodes: true });\n const result = (success: boolean, message: string) => ({ success, message, expected, actual });\n\n if (expectedQuads.length !== actualQuads.length)\n return result(false, `Expected ${expectedQuads.length} triples, found ${actualQuads.length}.`);\n\n try {\n assertExpectedQuadsExist(expectedQuads, actualQuads);\n } catch (error) {\n if (!(error instanceof ExpectedQuadAssertionError)) throw error;\n\n return result(false, error.message);\n }\n\n return result(true, 'turtle matches');\n}\n","import type { MatcherState, MatchersObject } from '@vitest/expect';\n\nimport { normalizeSparql, normalizeTurtle } from '@noeldemartin/solid-utils/helpers/io';\nimport { jsonldEquals, sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { JsonLD } from '@noeldemartin/solid-utils/helpers';\n\ninterface FormatResultOptions {\n state: MatcherState;\n hint: string;\n expected: unknown;\n received: unknown;\n}\n\nfunction formatResult(result: EqualityResult, options: FormatResultOptions) {\n const pass = result.success;\n const utils = options.state.utils;\n const message = pass\n ? () => [result.message, utils.matcherHint(options.hint)].join('\\n\\n')\n : () =>\n [\n result.message,\n utils.matcherHint(options.hint),\n [\n `Expected: not ${utils.printExpected(options.expected)}`,\n `Received: ${utils.printReceived(options.received)}`,\n ].join('\\n'),\n ].join('\\n\\n');\n\n return { pass, message };\n}\n\nexport function defineMatchers<T extends MatchersObject>(matchers: T): T {\n return matchers;\n}\n\nexport default defineMatchers({\n async toEqualJsonLD(received, expected: JsonLD) {\n const result = await jsonldEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualJsonLD',\n expected,\n received,\n });\n },\n toEqualSparql(received, expected: string) {\n const result = sparqlEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualSparql',\n expected: normalizeSparql(expected),\n received: normalizeSparql(received),\n });\n },\n toEqualTurtle(received, expected: string) {\n const result = turtleEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualTurtle',\n expected: normalizeTurtle(expected),\n received: normalizeTurtle(received),\n });\n },\n});\n","import { expect } from 'vitest';\n\nimport matchers from './matchers';\n\nexport type VitestSolidMatchers<R = unknown> = {\n [K in keyof typeof matchers]: (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Parameters<(typeof matchers)[K]> extends [any, ...infer Rest] ? Rest : never\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => ReturnType<(typeof matchers)[K]> extends Promise<any> ? Promise<R> : R;\n};\n\nexport function installVitestSolidMatchers(): void {\n expect.extend(matchers);\n}\n\ndeclare module '@vitest/expect' {\n interface Assertion<T> extends VitestSolidMatchers<T> {}\n interface AsymmetricMatchersContaining extends VitestSolidMatchers {}\n}\n","import { sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';\n\nexport function defineChaiAssertions<T extends Record<string, (this: Chai.AssertionStatic, ...args: any[]) => void>>(\n assertions: T): T {\n return assertions;\n}\n\nexport default defineChaiAssertions({\n turtle(graph: string): void {\n const self = this as unknown as Chai.AssertionStatic;\n const actual = self._obj as string;\n const assert = self.assert.bind(this);\n const expected = graph;\n const result = turtleEquals(expected, actual);\n\n assert(result.success, result.message, '', result.expected, result.actual);\n },\n sparql(query: string): void {\n const self = this as unknown as Chai.AssertionStatic;\n const actual = self._obj as string;\n const assert = self.assert.bind(this);\n const expected = query;\n const result = sparqlEquals(expected, actual);\n\n assert(result.success, result.message, '', result.expected, result.actual);\n },\n equalityResult(): void {\n const self = this as unknown as Chai.AssertionStatic;\n const result = self._obj as EqualityResult;\n const assert = self.assert.bind(this);\n\n assert(result.success, result.message, '', result.expected, result.actual);\n },\n});\n","import assertions from './assertions';\n\nexport type ChaiSolidAssertions = {\n [assertion in keyof typeof assertions]: (typeof assertions)[assertion];\n};\n\nexport function installChaiPlugin(): void {\n (globalThis as { chai?: Chai.ChaiStatic }).chai?.use((_chai) => {\n return Object.entries(assertions).forEach(([name, method]) => _chai.Assertion.addMethod(name, method));\n });\n}\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Chai {\n interface Assertion extends ChaiSolidAssertions {}\n interface Include extends ChaiSolidAssertions {}\n }\n}\n"],"names":["patternsRegExpsIndex","builtInPatterns","ExpectedQuadAssertionError","JSError","expectedQuad","quadToTurtle","assertExpectedQuadsExist","expectedQuads","actualQuads","matchingQuad","actualQuad","quadEquals","arrayRemove","containsPatterns","value","createPatternRegexp","expected","patternAliases","patternMatches","stringMatchAll","patterns","expectedRegExp","patternMatch","patternIndex","pattern","quadValueEquals","actual","quadObjectEquals","resetPatterns","jsonldEquals","jsonldToQuads","expectedTurtle","quadsToTurtle","actualTurtle","result","success","message","error","sparqlEquals","expectedOperations","sparqlToQuadsSync","actualOperations","operation","pull","unexpectedOperation","turtleEquals","turtleToQuadsSync","formatResult","options","pass","utils","matchers","received","normalizeSparql","normalizeTurtle","installVitestSolidMatchers","expect","assertions","graph","self","assert","query","installChaiPlugin","_a","_chai","name","method"],"mappings":";;;AAYA,IAAIA,IAA+C,CAAC;AACpD,MAAMC,IAA0C;AAAA,EAC5C,UAAU;AACd;AAEA,MAAMC,UAAmCC,EAAQ;AAAA,EAE7C,YAA4BC,GAAoB;AAC5C,UAAM,uCAAuCC,EA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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noeldemartin/solid-utils",
3
- "version": "0.6.0-next.70fba2db4562da63a3ae210c80936d148acfc0de",
3
+ "version": "0.6.0-next.851da2f1bc379a62ccbf7fcdef05b34e6e9ea4ae",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -36,9 +36,10 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@noeldemartin/eslint-config-typescript": "^0.1.2",
39
- "@noeldemartin/scripts": "0.3.0-next.07d9b709894cf99f2804349fb22249ae0647578b",
39
+ "@noeldemartin/scripts": "0.3.0-next.2dfd366e59e45ecf5ead1a617e4d0e870dbea507",
40
40
  "@noeldemartin/testing": "0.0.0-next.cd489a93da5eaad3f89a4d9ae3734f7ef911b6f6",
41
41
  "@tsconfig/node22": "^22.0.0",
42
+ "@types/chai": "^5.2.0",
42
43
  "@types/jsonld": "^1.5.15",
43
44
  "@types/md5": "^2.3.5",
44
45
  "@types/n3": "^1.24.1",
@@ -46,7 +47,7 @@
46
47
  "@vitest/expect": "^3.0.9",
47
48
  "typescript": "^5.8.2",
48
49
  "vite": "^6.2.2",
49
- "vite-plugin-dts": "^4.5.3",
50
+ "vite-plugin-dts": "4.5.0",
50
51
  "vitest": "^3.0.9"
51
52
  },
52
53
  "eslintConfig": {
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './errors';
2
2
  export * from './helpers';
3
3
  export * from './models';
4
+ export * from './testing/types';
@@ -0,0 +1,35 @@
1
+ import { sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';
2
+ import type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';
3
+
4
+ export function defineChaiAssertions<T extends Record<string, (this: Chai.AssertionStatic, ...args: any[]) => void>>(
5
+ assertions: T): T {
6
+ return assertions;
7
+ }
8
+
9
+ export default defineChaiAssertions({
10
+ turtle(graph: string): void {
11
+ const self = this as unknown as Chai.AssertionStatic;
12
+ const actual = self._obj as string;
13
+ const assert = self.assert.bind(this);
14
+ const expected = graph;
15
+ const result = turtleEquals(expected, actual);
16
+
17
+ assert(result.success, result.message, '', result.expected, result.actual);
18
+ },
19
+ sparql(query: string): void {
20
+ const self = this as unknown as Chai.AssertionStatic;
21
+ const actual = self._obj as string;
22
+ const assert = self.assert.bind(this);
23
+ const expected = query;
24
+ const result = sparqlEquals(expected, actual);
25
+
26
+ assert(result.success, result.message, '', result.expected, result.actual);
27
+ },
28
+ equalityResult(): void {
29
+ const self = this as unknown as Chai.AssertionStatic;
30
+ const result = self._obj as EqualityResult;
31
+ const assert = self.assert.bind(this);
32
+
33
+ assert(result.success, result.message, '', result.expected, result.actual);
34
+ },
35
+ });
@@ -0,0 +1,19 @@
1
+ import assertions from './assertions';
2
+
3
+ export type ChaiSolidAssertions = {
4
+ [assertion in keyof typeof assertions]: (typeof assertions)[assertion];
5
+ };
6
+
7
+ export function installChaiPlugin(): void {
8
+ (globalThis as { chai?: Chai.ChaiStatic }).chai?.use((_chai) => {
9
+ return Object.entries(assertions).forEach(([name, method]) => _chai.Assertion.addMethod(name, method));
10
+ });
11
+ }
12
+
13
+ declare global {
14
+ // eslint-disable-next-line @typescript-eslint/no-namespace
15
+ namespace Chai {
16
+ interface Assertion extends ChaiSolidAssertions {}
17
+ interface Include extends ChaiSolidAssertions {}
18
+ }
19
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './vitest';
2
2
  export * from './helpers';
3
+ export * from './chai';
@@ -0,0 +1,2 @@
1
+ export type { ChaiSolidAssertions } from '@noeldemartin/solid-utils/testing/chai';
2
+ export type { VitestSolidMatchers } from '@noeldemartin/solid-utils/testing/vitest';
@@ -13,3 +13,8 @@ export type VitestSolidMatchers<R = unknown> = {
13
13
  export function installVitestSolidMatchers(): void {
14
14
  expect.extend(matchers);
15
15
  }
16
+
17
+ declare module '@vitest/expect' {
18
+ interface Assertion<T> extends VitestSolidMatchers<T> {}
19
+ interface AsymmetricMatchersContaining extends VitestSolidMatchers {}
20
+ }