@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.
- package/dist/io-CMHtz5bu.js +401 -0
- package/dist/io-CMHtz5bu.js.map +1 -0
- package/dist/noeldemartin-solid-utils.d.ts +48 -0
- package/dist/noeldemartin-solid-utils.js +165 -531
- package/dist/noeldemartin-solid-utils.js.map +1 -1
- package/dist/testing.d.ts +75 -0
- package/dist/testing.js +176 -0
- package/dist/testing.js.map +1 -0
- package/package.json +14 -10
- package/src/errors/UnauthorizedError.ts +1 -3
- package/src/errors/UnsuccessfulNetworkRequestError.ts +2 -2
- package/src/helpers/identifiers.ts +13 -16
- package/src/helpers/io.ts +1 -1
- package/src/helpers/jsonld.ts +1 -1
- package/src/helpers/vocabs.ts +3 -6
- package/src/index.ts +1 -0
- package/src/testing/chai/assertions.ts +35 -0
- package/src/testing/chai/index.ts +19 -0
- package/src/testing/helpers.ts +187 -0
- package/src/testing/hepers.test.ts +329 -0
- package/src/testing/index.ts +3 -0
- package/src/testing/types/index.ts +2 -0
- package/src/testing/vitest/index.ts +20 -0
- package/src/testing/vitest/matchers.ts +68 -0
- package/src/types/n3.d.ts +0 -2
|
@@ -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
|
+
});
|