@noeldemartin/solid-utils 0.6.0-next.95fe731be0689c25d9040cc1411e27c49f69901d → 0.6.0-next.cfba421315c47e4aa5a72990714376d9dcd1ffff
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/dist/noeldemartin-solid-utils.d.ts +48 -0
- package/dist/testing.d.ts +29 -1
- package/dist/testing.js +17 -17
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/testing/chai/assertions.ts +5 -14
- package/src/testing/chai/index.ts +13 -1
- package/src/testing/types/index.ts +2 -0
- package/src/testing/vitest/index.ts +5 -0
|
@@ -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,7 +32,7 @@ export declare interface EqualityResult {
|
|
|
22
32
|
actual: string;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
|
-
export declare function
|
|
35
|
+
export declare function installChaiSolidAssertions(): void;
|
|
26
36
|
|
|
27
37
|
export declare function installVitestSolidMatchers(): void;
|
|
28
38
|
|
|
@@ -45,3 +55,21 @@ export declare type VitestSolidMatchers<R = unknown> = {
|
|
|
45
55
|
};
|
|
46
56
|
|
|
47
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,11 +1,11 @@
|
|
|
1
1
|
import { expect as Q } from "vitest";
|
|
2
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
|
|
3
|
+
import { pull as $, arrayRemove as R, JSError as S, stringMatchAll as A } from "@noeldemartin/utils";
|
|
4
4
|
let c = {};
|
|
5
|
-
const
|
|
5
|
+
const O = {
|
|
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 i extends
|
|
8
|
+
class i extends S {
|
|
9
9
|
constructor(e) {
|
|
10
10
|
super(`Couldn't find the following triple: ${b(e)}`), this.expectedQuad = e;
|
|
11
11
|
}
|
|
@@ -20,20 +20,20 @@ function p(t, e) {
|
|
|
20
20
|
function v(t) {
|
|
21
21
|
return /\[\[(.*\]\[)?([^\]]+)\]\]/.test(t);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
const e = [], s =
|
|
23
|
+
function k(t) {
|
|
24
|
+
const e = [], s = A(t, /\[\[((.*?)\]\[)?([^\]]+)\]\]/g), n = [];
|
|
25
25
|
let a = t;
|
|
26
26
|
for (const r of s)
|
|
27
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
29
|
for (const [r, o] of Object.entries(n))
|
|
30
|
-
a = a.replace(`%PATTERN${r}%`,
|
|
30
|
+
a = a.replace(`%PATTERN${r}%`, O[o] ?? o);
|
|
31
31
|
return new RegExp(a);
|
|
32
32
|
}
|
|
33
33
|
function h(t, e) {
|
|
34
|
-
return v(t) ? (c[t] ?? (c[t] =
|
|
34
|
+
return v(t) ? (c[t] ?? (c[t] = k(t))).test(e) : t === e;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
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;
|
|
@@ -43,12 +43,12 @@ function P(t, e) {
|
|
|
43
43
|
return h(t.value, e.value);
|
|
44
44
|
}
|
|
45
45
|
function z(t, e) {
|
|
46
|
-
return
|
|
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
49
|
c = {};
|
|
50
50
|
}
|
|
51
|
-
async function
|
|
51
|
+
async function N(t, e) {
|
|
52
52
|
m();
|
|
53
53
|
const s = await g(t), n = await g(e), a = E(s), r = E(n), o = (u, l) => ({
|
|
54
54
|
success: u,
|
|
@@ -116,9 +116,9 @@ function d(t, e) {
|
|
|
116
116
|
|
|
117
117
|
`) };
|
|
118
118
|
}
|
|
119
|
-
const
|
|
119
|
+
const P = {
|
|
120
120
|
async toEqualJsonLD(t, e) {
|
|
121
|
-
const s = await
|
|
121
|
+
const s = await N(e, t);
|
|
122
122
|
return d(s, {
|
|
123
123
|
state: this,
|
|
124
124
|
hint: "toEqualJsonLD",
|
|
@@ -146,9 +146,9 @@ const N = {
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
function J() {
|
|
149
|
-
Q.extend(
|
|
149
|
+
Q.extend(P);
|
|
150
150
|
}
|
|
151
|
-
const
|
|
151
|
+
const C = {
|
|
152
152
|
turtle(t) {
|
|
153
153
|
const e = this, s = e._obj, n = e.assert.bind(this), r = x(t, s);
|
|
154
154
|
n(r.success, r.message, "", r.expected, r.actual);
|
|
@@ -164,12 +164,12 @@ const D = {
|
|
|
164
164
|
};
|
|
165
165
|
function _() {
|
|
166
166
|
var t;
|
|
167
|
-
(t = globalThis.chai) == null || t.use((e) => Object.entries(
|
|
167
|
+
(t = globalThis.chai) == null || t.use((e) => Object.entries(C).forEach(([s, n]) => e.Assertion.addMethod(s, n)));
|
|
168
168
|
}
|
|
169
169
|
export {
|
|
170
|
-
_ as
|
|
170
|
+
_ as installChaiSolidAssertions,
|
|
171
171
|
J as installVitestSolidMatchers,
|
|
172
|
-
|
|
172
|
+
N as jsonldEquals,
|
|
173
173
|
w as sparqlEquals,
|
|
174
174
|
x as turtleEquals
|
|
175
175
|
};
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","import { sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';\n\ntype CustomAssertions = {\n [assertion in keyof typeof assertions]: (typeof assertions)[assertion];\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Chai {\n interface Assertion extends CustomAssertions {}\n interface Include extends CustomAssertions {}\n }\n}\n\nconst assertions: Record<string, (this: Chai.AssertionStatic, ...args: any[]) => void> = {\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\nexport default assertions;\n","import assertions from './assertions';\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"],"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,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,GAA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AAMC,IAAO,MACPjC,IAASiC,EAAK,MACdC,IAASD,EAAK,OAAO,KAAK,IAAI,GAE9BzB,IAASW,EADEa,GACqBhC,CAAM;AAErC,IAAAkC,EAAA1B,EAAO,SAASA,EAAO,SAAS,IAAIA,EAAO,UAAUA,EAAO,MAAM;AAAA,EAC7E;AAAA,EACA,OAAO2B,GAAqB;AACxB,UAAMF,IAAO,MACPjC,IAASiC,EAAK,MACdC,IAASD,EAAK,OAAO,KAAK,IAAI,GAE9BzB,IAASI,EADEuB,GACqBnC,CAAM;AAErC,IAAAkC,EAAA1B,EAAO,SAASA,EAAO,SAAS,IAAIA,EAAO,UAAUA,EAAO,MAAM;AAAA,EAC7E;AAAA,EACA,iBAAuB;AACnB,UAAMyB,IAAO,MACPzB,IAASyB,EAAK;AAGb,IAFQA,EAAK,OAAO,KAAK,IAAI,EAE7BzB,EAAO,SAASA,EAAO,SAAS,IAAIA,EAAO,UAAUA,EAAO,MAAM;AAAA,EAAA;AAEjF;ACvCO,SAAS4B,IAA0B;;AACrC,GAAAC,IAAA,WAA0C,SAA1C,QAAAA,EAAgD,IAAI,CAACC,MAC3C,OAAO,QAAQP,CAAU,EAAE,QAAQ,CAAC,CAACQ,GAAMC,CAAM,MAAMF,EAAM,UAAU,UAAUC,GAAMC,CAAM,CAAC;AAE7G;"}
|
|
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 installChaiSolidAssertions(): 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","installChaiSolidAssertions","_a","_chai","name","method"],"mappings":";;;AAYA,IAAIA,IAA+C,CAAC;AACpD,MAAMC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P,CAAU,EAAE,QAAQ,CAAC,CAACQ,GAAMC,CAAM,MAAMF,EAAM,UAAU,UAAUC,GAAMC,CAAM,CAAC;AAE7G;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noeldemartin/solid-utils",
|
|
3
|
-
"version": "0.6.0-next.
|
|
3
|
+
"version": "0.6.0-next.cfba421315c47e4aa5a72990714376d9dcd1ffff",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@vitest/expect": "^3.0.9",
|
|
48
48
|
"typescript": "^5.8.2",
|
|
49
49
|
"vite": "^6.2.2",
|
|
50
|
-
"vite-plugin-dts": "
|
|
50
|
+
"vite-plugin-dts": "4.5.0",
|
|
51
51
|
"vitest": "^3.0.9"
|
|
52
52
|
},
|
|
53
53
|
"eslintConfig": {
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';
|
|
2
2
|
import type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
|
-
namespace Chai {
|
|
11
|
-
interface Assertion extends CustomAssertions {}
|
|
12
|
-
interface Include extends CustomAssertions {}
|
|
13
|
-
}
|
|
4
|
+
export function defineChaiAssertions<T extends Record<string, (this: Chai.AssertionStatic, ...args: any[]) => void>>(
|
|
5
|
+
assertions: T): T {
|
|
6
|
+
return assertions;
|
|
14
7
|
}
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
export default defineChaiAssertions({
|
|
17
10
|
turtle(graph: string): void {
|
|
18
11
|
const self = this as unknown as Chai.AssertionStatic;
|
|
19
12
|
const actual = self._obj as string;
|
|
@@ -39,6 +32,4 @@ const assertions: Record<string, (this: Chai.AssertionStatic, ...args: any[]) =>
|
|
|
39
32
|
|
|
40
33
|
assert(result.success, result.message, '', result.expected, result.actual);
|
|
41
34
|
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default assertions;
|
|
35
|
+
});
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import assertions from './assertions';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type ChaiSolidAssertions = {
|
|
4
|
+
[assertion in keyof typeof assertions]: (typeof assertions)[assertion];
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export function installChaiSolidAssertions(): void {
|
|
4
8
|
(globalThis as { chai?: Chai.ChaiStatic }).chai?.use((_chai) => {
|
|
5
9
|
return Object.entries(assertions).forEach(([name, method]) => _chai.Assertion.addMethod(name, method));
|
|
6
10
|
});
|
|
7
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
|
+
}
|
|
@@ -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
|
+
}
|