@noeldemartin/solid-utils 0.5.0 → 0.6.0-next.3e3ceb79b047f4ec87a416c2f920a13eda7a0df1
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 +13 -65
- package/dist/noeldemartin-solid-utils.js +224 -0
- package/dist/noeldemartin-solid-utils.js.map +1 -0
- package/dist/testing.d.ts +45 -0
- package/dist/testing.js +157 -0
- package/dist/testing.js.map +1 -0
- package/package.json +61 -63
- package/src/errors/UnauthorizedError.ts +1 -3
- package/src/errors/UnsuccessfulNetworkRequestError.ts +2 -2
- package/src/helpers/auth.test.ts +221 -0
- package/src/helpers/auth.ts +28 -27
- package/src/helpers/identifiers.test.ts +76 -0
- package/src/helpers/identifiers.ts +14 -17
- package/src/helpers/index.ts +0 -1
- package/src/helpers/interop.ts +23 -16
- package/src/helpers/io.test.ts +228 -0
- package/src/helpers/io.ts +57 -77
- package/src/helpers/jsonld.ts +6 -6
- package/src/helpers/vocabs.ts +3 -6
- package/src/helpers/wac.test.ts +64 -0
- package/src/helpers/wac.ts +10 -6
- package/src/index.ts +3 -0
- package/src/models/SolidDocument.test.ts +77 -0
- package/src/models/SolidDocument.ts +14 -18
- package/src/models/SolidStore.ts +22 -12
- package/src/models/SolidThing.ts +5 -7
- package/src/models/index.ts +2 -0
- package/src/{helpers/testing.ts → testing/helpers.ts} +24 -27
- package/src/testing/hepers.test.ts +329 -0
- package/src/testing/index.ts +2 -2
- package/src/testing/vitest/index.ts +13 -0
- package/src/testing/vitest/matchers.ts +68 -0
- package/src/types/n3.d.ts +0 -2
- package/.github/workflows/ci.yml +0 -16
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -70
- package/dist/noeldemartin-solid-utils.cjs.js +0 -2
- package/dist/noeldemartin-solid-utils.cjs.js.map +0 -1
- package/dist/noeldemartin-solid-utils.esm.js +0 -2
- package/dist/noeldemartin-solid-utils.esm.js.map +0 -1
- package/dist/noeldemartin-solid-utils.umd.js +0 -90
- package/dist/noeldemartin-solid-utils.umd.js.map +0 -1
- package/noeldemartin.config.js +0 -9
- package/src/main.ts +0 -5
- package/src/plugins/chai/assertions.ts +0 -40
- package/src/plugins/chai/index.ts +0 -5
- package/src/plugins/cypress/types.d.ts +0 -15
- package/src/plugins/index.ts +0 -2
- package/src/plugins/jest/index.ts +0 -5
- package/src/plugins/jest/matchers.ts +0 -65
- package/src/plugins/jest/types.d.ts +0 -14
- package/src/testing/ResponseStub.ts +0 -46
- package/src/testing/mocking.ts +0 -33
package/noeldemartin.config.js
DELETED
package/src/main.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { sparqlEquals, turtleEquals } from '@/helpers/testing';
|
|
2
|
-
|
|
3
|
-
type CustomAssertions = {
|
|
4
|
-
[assertion in keyof typeof assertions]: typeof assertions[assertion];
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
declare global {
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
|
-
namespace Chai {
|
|
11
|
-
|
|
12
|
-
interface Assertion extends CustomAssertions {}
|
|
13
|
-
interface Include extends CustomAssertions {}
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const assertions: Record<string, (this: Chai.AssertionStatic, ...args: any[]) => void> = {
|
|
20
|
-
turtle(graph: string): void {
|
|
21
|
-
const self = this as unknown as Chai.AssertionStatic;
|
|
22
|
-
const actual = self._obj;
|
|
23
|
-
const assert = self.assert.bind(this);
|
|
24
|
-
const expected = graph;
|
|
25
|
-
const result = turtleEquals(expected, actual);
|
|
26
|
-
|
|
27
|
-
assert(result.success, result.message, '', result.expected, result.actual);
|
|
28
|
-
},
|
|
29
|
-
sparql(query: string): void {
|
|
30
|
-
const self = this as unknown as Chai.AssertionStatic;
|
|
31
|
-
const actual = self._obj;
|
|
32
|
-
const assert = self.assert.bind(this);
|
|
33
|
-
const expected = query;
|
|
34
|
-
const result = sparqlEquals(expected, actual);
|
|
35
|
-
|
|
36
|
-
assert(result.success, result.message, '', result.expected, result.actual);
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export default assertions;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="cypress" />
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
|
|
5
|
-
namespace Cypress {
|
|
6
|
-
|
|
7
|
-
// TODO generate automatically
|
|
8
|
-
interface Chainer<Subject> {
|
|
9
|
-
(chainer: 'be.sparql', update: string): Cypress.Chainable<Subject>;
|
|
10
|
-
(chainer: 'be.turtle', graph: string): Cypress.Chainable<Subject>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
}
|
package/src/plugins/index.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { normalizeSparql, normalizeTurtle } from '@/helpers/io';
|
|
2
|
-
import { jsonldEquals, sparqlEquals, turtleEquals } from '@/helpers/testing';
|
|
3
|
-
import type { EqualityResult } from '@/helpers/testing';
|
|
4
|
-
|
|
5
|
-
interface FormatResultOptions {
|
|
6
|
-
context: jest.MatcherContext;
|
|
7
|
-
hint: string;
|
|
8
|
-
expected: unknown;
|
|
9
|
-
received: unknown;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function formatResult(result: EqualityResult, options: FormatResultOptions) {
|
|
13
|
-
const pass = result.success;
|
|
14
|
-
const utils = options.context.utils;
|
|
15
|
-
const message = pass
|
|
16
|
-
? () => [
|
|
17
|
-
result.message,
|
|
18
|
-
utils.matcherHint(options.hint),
|
|
19
|
-
].join('\n\n')
|
|
20
|
-
: () => [
|
|
21
|
-
result.message,
|
|
22
|
-
utils.matcherHint(options.hint),
|
|
23
|
-
[
|
|
24
|
-
`Expected: not ${utils.printExpected(options.expected)}`,
|
|
25
|
-
`Received: ${utils.printReceived(options.received)}`,
|
|
26
|
-
].join('\n'),
|
|
27
|
-
].join('\n\n');
|
|
28
|
-
|
|
29
|
-
return { pass, message };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const matchers: jest.ExpectExtendMap = {
|
|
33
|
-
async toEqualJsonLD(received, expected) {
|
|
34
|
-
const result = await jsonldEquals(expected, received);
|
|
35
|
-
|
|
36
|
-
return formatResult(result, {
|
|
37
|
-
context: this,
|
|
38
|
-
hint: 'toEqualJsonLD',
|
|
39
|
-
expected,
|
|
40
|
-
received,
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
toEqualSparql(received, expected) {
|
|
44
|
-
const result = sparqlEquals(expected, received);
|
|
45
|
-
|
|
46
|
-
return formatResult(result, {
|
|
47
|
-
context: this,
|
|
48
|
-
hint: 'toEqualSparql',
|
|
49
|
-
expected: normalizeSparql(expected),
|
|
50
|
-
received: normalizeSparql(received),
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
toEqualTurtle(received, expected) {
|
|
54
|
-
const result = turtleEquals(expected, received);
|
|
55
|
-
|
|
56
|
-
return formatResult(result, {
|
|
57
|
-
context: this,
|
|
58
|
-
hint: 'toEqualTurtle',
|
|
59
|
-
expected: normalizeTurtle(expected),
|
|
60
|
-
received: normalizeTurtle(received),
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export default matchers;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export default class ResponseStub implements Response {
|
|
2
|
-
|
|
3
|
-
private rawBody: string;
|
|
4
|
-
|
|
5
|
-
public readonly body!: ReadableStream<Uint8Array> | null;
|
|
6
|
-
public readonly bodyUsed!: boolean;
|
|
7
|
-
public readonly headers: Headers;
|
|
8
|
-
public readonly ok!: boolean;
|
|
9
|
-
public readonly redirected!: boolean;
|
|
10
|
-
public readonly status: number;
|
|
11
|
-
public readonly statusText!: string;
|
|
12
|
-
public readonly trailer!: Promise<Headers>;
|
|
13
|
-
public readonly type!: ResponseType;
|
|
14
|
-
public readonly url!: string;
|
|
15
|
-
|
|
16
|
-
public constructor(rawBody: string = '', headers: Record<string, string> = {}, status: number = 200) {
|
|
17
|
-
this.rawBody = rawBody;
|
|
18
|
-
this.headers = new Headers(headers);
|
|
19
|
-
this.status = status;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public async arrayBuffer(): Promise<ArrayBuffer> {
|
|
23
|
-
throw new Error('ResponseStub.arrayBuffer is not implemented');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public async blob(): Promise<Blob> {
|
|
27
|
-
throw new Error('ResponseStub.blob is not implemented');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public async formData(): Promise<FormData> {
|
|
31
|
-
throw new Error('ResponseStub.formData is not implemented');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public async json(): Promise<unknown> {
|
|
35
|
-
return JSON.parse(this.rawBody);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public async text(): Promise<string> {
|
|
39
|
-
return this.rawBody;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public clone(): Response {
|
|
43
|
-
return { ...this };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
package/src/testing/mocking.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { fail } from '@noeldemartin/utils';
|
|
2
|
-
import type { GetClosureArgs } from '@noeldemartin/utils';
|
|
3
|
-
|
|
4
|
-
import type { Fetch } from '@/helpers/io';
|
|
5
|
-
|
|
6
|
-
import ResponseStub from './ResponseStub';
|
|
7
|
-
|
|
8
|
-
export interface FetchMockMethods {
|
|
9
|
-
mockResponse(body?: string, headers?: Record<string, string>, status?: number): void;
|
|
10
|
-
mockNotFoundResponse(): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
export function mockFetch<T = any>(): T {
|
|
15
|
-
const responses: ResponseStub[] = [];
|
|
16
|
-
const methods: FetchMockMethods = {
|
|
17
|
-
mockResponse(body, headers, status) {
|
|
18
|
-
responses.push(new ResponseStub(body, headers, status));
|
|
19
|
-
},
|
|
20
|
-
mockNotFoundResponse() {
|
|
21
|
-
responses.push(new ResponseStub('', {}, 404));
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
|
-
const fetchMock = jest.fn(async (...args: GetClosureArgs<Fetch>) => {
|
|
27
|
-
return responses.shift() ?? fail<Response>('fetch mock called without response');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
Object.assign(fetchMock, methods);
|
|
31
|
-
|
|
32
|
-
return fetchMock as unknown as T;
|
|
33
|
-
}
|