@strivacity/sdk-core 4.0.0-beta.1 → 4.0.0-beta.2
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/README.md +228 -87
- package/dist/assets/oidc.cjs +1 -1
- package/dist/assets/oidc.cjs.map +1 -1
- package/dist/assets/oidc.mjs +1 -1
- package/dist/assets/oidc.mjs.map +1 -1
- package/dist/assets/server.cjs +1 -1
- package/dist/assets/server.cjs.map +1 -1
- package/dist/assets/server.mjs +1 -1
- package/dist/assets/server.mjs.map +1 -1
- package/dist/flows/base.cjs +1 -1
- package/dist/flows/base.cjs.map +1 -1
- package/dist/flows/base.d.ts +4 -2
- package/dist/flows/base.mjs +1 -1
- package/dist/flows/base.mjs.map +1 -1
- package/dist/flows/popup.cjs +1 -1
- package/dist/flows/popup.cjs.map +1 -1
- package/dist/flows/popup.mjs +1 -1
- package/dist/flows/popup.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/server/base.cjs +1 -1
- package/dist/server/base.cjs.map +1 -1
- package/dist/server/base.d.ts +2 -4
- package/dist/server/base.mjs +1 -1
- package/dist/server/base.mjs.map +1 -1
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.mjs +1 -1
- package/dist/storages/cache.cjs.map +1 -1
- package/dist/storages/cache.d.ts +1 -1
- package/dist/storages/cache.mjs.map +1 -1
- package/dist/storages/index.cjs +1 -1
- package/dist/storages/index.mjs +1 -1
- package/dist/storages/server.cjs +1 -1
- package/dist/storages/server.d.ts +29 -1
- package/dist/storages/server.mjs +1 -1
- package/dist/storages/worker.cjs.map +1 -1
- package/dist/storages/worker.d.ts +1 -1
- package/dist/storages/worker.mjs.map +1 -1
- package/dist/types/native.d.ts +67 -2
- package/dist/types/oidc.cjs.map +1 -1
- package/dist/types/oidc.d.ts +41 -6
- package/dist/types/oidc.mjs.map +1 -1
- package/dist/types/popup.d.ts +1 -1
- package/dist/types/server.d.ts +21 -9
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/native-login.cjs +2 -0
- package/dist/utils/native-login.cjs.map +1 -0
- package/dist/utils/native-login.d.ts +13 -0
- package/dist/utils/native-login.mjs +2 -0
- package/dist/utils/native-login.mjs.map +1 -0
- package/dist/utils/oidc.d.ts +3 -4
- package/dist/utils/path.cjs +2 -0
- package/dist/utils/path.cjs.map +1 -0
- package/dist/utils/path.d.ts +16 -0
- package/dist/utils/path.mjs +2 -0
- package/dist/utils/path.mjs.map +1 -0
- package/dist/utils/server.d.ts +5 -4
- package/dist/utils/session.cjs +1 -1
- package/dist/utils/session.cjs.map +1 -1
- package/dist/utils/session.d.ts +9 -1
- package/dist/utils/session.mjs +1 -1
- package/dist/utils/session.mjs.map +1 -1
- package/package.json +1 -1
- package/testing/tests/flows/base.spec.ts +0 -1030
- package/testing/tests/flows/embedded.spec.ts +0 -443
- package/testing/tests/flows/index.spec.ts +0 -8
- package/testing/tests/flows/native.spec.ts +0 -487
- package/testing/tests/flows/popup.spec.ts +0 -400
- package/testing/tests/flows/redirect.spec.ts +0 -369
- package/testing/tests/handlers/embedded.spec.ts +0 -199
- package/testing/tests/handlers/index.spec.ts +0 -8
- package/testing/tests/handlers/native.spec.ts +0 -283
- package/testing/tests/handlers/popup.spec.ts +0 -206
- package/testing/tests/handlers/redirect.spec.ts +0 -70
- package/testing/tests/index.spec.ts +0 -78
- package/testing/tests/server/base.spec.ts +0 -846
- package/testing/tests/server/index.spec.ts +0 -15
- package/testing/tests/storages/cache.spec.ts +0 -107
- package/testing/tests/storages/index.spec.ts +0 -22
- package/testing/tests/storages/indexeddb.spec.ts +0 -113
- package/testing/tests/storages/local.spec.ts +0 -46
- package/testing/tests/storages/memory.spec.ts +0 -51
- package/testing/tests/storages/server.spec.ts +0 -435
- package/testing/tests/storages/session.spec.ts +0 -46
- package/testing/tests/storages/worker.spec.ts +0 -106
- package/testing/tests/utils/common.spec.ts +0 -77
- package/testing/tests/utils/credentials.spec.ts +0 -195
- package/testing/tests/utils/dom.spec.ts +0 -37
- package/testing/tests/utils/index.spec.ts +0 -71
- package/testing/tests/utils/logging.spec.ts +0 -82
- package/testing/tests/utils/oidc.spec.ts +0 -745
- package/testing/tests/utils/server.spec.ts +0 -235
- package/testing/tests/utils/session.spec.ts +0 -87
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import { describe, test, expect, afterEach } from 'vitest';
|
|
4
|
-
import { createWebAuthnCredential, assertWebAuthnCredential } from '../../../src/utils/credentials';
|
|
5
|
-
import { ProtocolError } from '../../../src/utils/errors';
|
|
6
|
-
import { encodeBase64URL } from '../../../src/utils/base64url';
|
|
7
|
-
import { creationOptions, fromBuffer, mockCredentials, requestOptions, toBuffer } from '@strivacity/testing/mocks/credentials';
|
|
8
|
-
|
|
9
|
-
describe('createWebAuthnCredential', () => {
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
delete (navigator as any).credentials;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('decodes the challenge, user id and excludeCredentials ids, and returns the formatted registration response', async () => {
|
|
15
|
-
let capturedPublicKey: any;
|
|
16
|
-
|
|
17
|
-
mockCredentials({
|
|
18
|
-
create: (options) => {
|
|
19
|
-
capturedPublicKey = options.publicKey;
|
|
20
|
-
return Promise.resolve({
|
|
21
|
-
id: 'credential-id',
|
|
22
|
-
rawId: toBuffer('raw-id'),
|
|
23
|
-
type: 'public-key',
|
|
24
|
-
authenticatorAttachment: 'platform',
|
|
25
|
-
response: {
|
|
26
|
-
clientDataJSON: toBuffer('client-data'),
|
|
27
|
-
attestationObject: toBuffer('attestation'),
|
|
28
|
-
getTransports: () => ['internal'],
|
|
29
|
-
},
|
|
30
|
-
getClientExtensionResults: () => ({ foo: 'bar' }),
|
|
31
|
-
});
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const result = await createWebAuthnCredential(
|
|
36
|
-
creationOptions({ excludeCredentials: [{ id: encodeBase64URL(toBuffer('exclude-1')), type: 'public-key' }] }),
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
expect(fromBuffer(capturedPublicKey.challenge)).toBe('challenge');
|
|
40
|
-
expect(fromBuffer(capturedPublicKey.user.id)).toBe('user-1');
|
|
41
|
-
expect(fromBuffer(capturedPublicKey.excludeCredentials[0].id)).toBe('exclude-1');
|
|
42
|
-
|
|
43
|
-
expect(result).toEqual({
|
|
44
|
-
id: 'credential-id',
|
|
45
|
-
rawId: encodeBase64URL(toBuffer('raw-id')),
|
|
46
|
-
response: {
|
|
47
|
-
clientDataJSON: encodeBase64URL(toBuffer('client-data')),
|
|
48
|
-
attestationObject: encodeBase64URL(toBuffer('attestation')),
|
|
49
|
-
transports: ['internal'],
|
|
50
|
-
},
|
|
51
|
-
authenticatorAttachment: 'platform',
|
|
52
|
-
clientExtensionResults: { foo: 'bar' },
|
|
53
|
-
type: 'public-key',
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('defaults excludeCredentials to an empty array when not provided', async () => {
|
|
58
|
-
let capturedPublicKey: any;
|
|
59
|
-
|
|
60
|
-
mockCredentials({
|
|
61
|
-
create: (options) => {
|
|
62
|
-
capturedPublicKey = options.publicKey;
|
|
63
|
-
return Promise.resolve({
|
|
64
|
-
type: 'public-key',
|
|
65
|
-
rawId: toBuffer('raw-id'),
|
|
66
|
-
response: { clientDataJSON: toBuffer(''), attestationObject: toBuffer('') },
|
|
67
|
-
getClientExtensionResults: () => ({}),
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
await createWebAuthnCredential(creationOptions());
|
|
73
|
-
|
|
74
|
-
expect(capturedPublicKey.excludeCredentials).toEqual([]);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('defaults transports to an empty array when the response has no getTransports', async () => {
|
|
78
|
-
mockCredentials({
|
|
79
|
-
create: () =>
|
|
80
|
-
Promise.resolve({
|
|
81
|
-
type: 'public-key',
|
|
82
|
-
rawId: toBuffer('raw-id'),
|
|
83
|
-
response: { clientDataJSON: toBuffer(''), attestationObject: toBuffer('') },
|
|
84
|
-
getClientExtensionResults: () => ({}),
|
|
85
|
-
}),
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const result = await createWebAuthnCredential(creationOptions());
|
|
89
|
-
|
|
90
|
-
expect(result.response.transports).toEqual([]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('forwards the provided AbortController signal to navigator.credentials.create', async () => {
|
|
94
|
-
let capturedSignal: AbortSignal | undefined;
|
|
95
|
-
const abortController = new AbortController();
|
|
96
|
-
|
|
97
|
-
mockCredentials({
|
|
98
|
-
create: (options) => {
|
|
99
|
-
capturedSignal = options.signal;
|
|
100
|
-
return Promise.resolve({
|
|
101
|
-
type: 'public-key',
|
|
102
|
-
rawId: toBuffer('raw-id'),
|
|
103
|
-
response: { clientDataJSON: toBuffer(''), attestationObject: toBuffer('') },
|
|
104
|
-
getClientExtensionResults: () => ({}),
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
await createWebAuthnCredential(creationOptions(), abortController);
|
|
110
|
-
|
|
111
|
-
expect(capturedSignal).toBe(abortController.signal);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('throws a ProtocolError when the created credential is not a public-key credential', async () => {
|
|
115
|
-
mockCredentials({ create: () => Promise.resolve({ type: 'other', response: {} }) });
|
|
116
|
-
|
|
117
|
-
await expect(createWebAuthnCredential(creationOptions())).rejects.toThrow(new ProtocolError('Not a public key'));
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('assertWebAuthnCredential', () => {
|
|
122
|
-
afterEach(() => {
|
|
123
|
-
delete (navigator as any).credentials;
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('decodes the challenge and allowCredentials ids, and returns credential.toJSON()', async () => {
|
|
127
|
-
let capturedPublicKey: any;
|
|
128
|
-
const toJSONResult = { id: 'credential-id' };
|
|
129
|
-
|
|
130
|
-
mockCredentials({
|
|
131
|
-
get: (options) => {
|
|
132
|
-
capturedPublicKey = options.publicKey;
|
|
133
|
-
return Promise.resolve({ type: 'public-key', toJSON: () => toJSONResult });
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const result = await assertWebAuthnCredential(requestOptions({ allowCredentials: [{ id: encodeBase64URL(toBuffer('allow-1')), type: 'public-key' }] }));
|
|
138
|
-
|
|
139
|
-
expect(fromBuffer(capturedPublicKey.challenge)).toBe('challenge');
|
|
140
|
-
expect(fromBuffer(capturedPublicKey.allowCredentials[0].id)).toBe('allow-1');
|
|
141
|
-
expect(result).toBe(toJSONResult);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('defaults allowCredentials to an empty array when not provided', async () => {
|
|
145
|
-
let capturedPublicKey: any;
|
|
146
|
-
|
|
147
|
-
mockCredentials({
|
|
148
|
-
get: (options) => {
|
|
149
|
-
capturedPublicKey = options.publicKey;
|
|
150
|
-
return Promise.resolve({ type: 'public-key', toJSON: () => ({}) });
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
await assertWebAuthnCredential(requestOptions());
|
|
155
|
-
|
|
156
|
-
expect(capturedPublicKey.allowCredentials).toEqual([]);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test('defaults the mediation requirement to "optional"', async () => {
|
|
160
|
-
let capturedMediation;
|
|
161
|
-
|
|
162
|
-
mockCredentials({
|
|
163
|
-
get: (options) => {
|
|
164
|
-
capturedMediation = options.mediation;
|
|
165
|
-
return Promise.resolve({ type: 'public-key', toJSON: () => ({}) });
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
await assertWebAuthnCredential(requestOptions());
|
|
170
|
-
|
|
171
|
-
expect(capturedMediation).toBe('optional');
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('uses the provided mediation requirement', async () => {
|
|
175
|
-
let capturedMediation;
|
|
176
|
-
|
|
177
|
-
mockCredentials({
|
|
178
|
-
get: (options) => {
|
|
179
|
-
capturedMediation = options.mediation;
|
|
180
|
-
|
|
181
|
-
return Promise.resolve({ type: 'public-key', toJSON: () => ({}) });
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
await assertWebAuthnCredential(requestOptions(), 'conditional');
|
|
186
|
-
|
|
187
|
-
expect(capturedMediation).toBe('conditional');
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test('throws a ProtocolError when the retrieved credential is not a public-key credential', async () => {
|
|
191
|
-
mockCredentials({ get: () => Promise.resolve({ type: 'other', toJSON: () => ({}) }) });
|
|
192
|
-
|
|
193
|
-
await expect(assertWebAuthnCredential(requestOptions())).rejects.toThrow(new ProtocolError('Not a public key'));
|
|
194
|
-
});
|
|
195
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, vi, afterEach } from 'vitest';
|
|
2
|
-
import { injectScript } from '../../../src/utils/dom';
|
|
3
|
-
|
|
4
|
-
describe('injectScript', () => {
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
vi.unstubAllGlobals();
|
|
7
|
-
document.getElementById('script-id')?.remove();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('appends a script element with the given id, src, async and module type', () => {
|
|
11
|
-
injectScript('script-id', 'https://brandtegrity.io/script.js');
|
|
12
|
-
|
|
13
|
-
const script = document.getElementById('script-id') as HTMLScriptElement;
|
|
14
|
-
|
|
15
|
-
expect(script).not.toBeNull();
|
|
16
|
-
expect(script.src).toBe('https://brandtegrity.io/script.js');
|
|
17
|
-
expect(script.async).toBe(true);
|
|
18
|
-
expect(script.type).toBe('module');
|
|
19
|
-
expect(script.parentElement).toBe(document.body);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('does not inject a second script when an element with the same id already exists', () => {
|
|
23
|
-
injectScript('script-id', 'https://brandtegrity.io/first.js');
|
|
24
|
-
injectScript('script-id', 'https://brandtegrity.io/second.js');
|
|
25
|
-
|
|
26
|
-
const script = document.getElementById('script-id') as HTMLScriptElement;
|
|
27
|
-
|
|
28
|
-
expect(script.src).toBe('https://brandtegrity.io/first.js');
|
|
29
|
-
expect(document.querySelectorAll('#script-id').length).toBe(1);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('is a no-op when document is unavailable', () => {
|
|
33
|
-
vi.stubGlobal('document', undefined);
|
|
34
|
-
|
|
35
|
-
expect(() => injectScript('script-id', 'https://brandtegrity.io/script.js')).not.toThrow();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { test, expect } from 'vitest';
|
|
2
|
-
import * as index from '../../../src/utils';
|
|
3
|
-
|
|
4
|
-
test('should export the correct things', () => {
|
|
5
|
-
const expectedExports = [
|
|
6
|
-
'encodeBase64URL',
|
|
7
|
-
'decodeBase64URL',
|
|
8
|
-
'timestamp',
|
|
9
|
-
'unflattenObject',
|
|
10
|
-
'buildCookieString',
|
|
11
|
-
'createWebAuthnCredential',
|
|
12
|
-
'assertWebAuthnCredential',
|
|
13
|
-
'encryptString',
|
|
14
|
-
'decryptString',
|
|
15
|
-
'injectScript',
|
|
16
|
-
'FallbackError',
|
|
17
|
-
'PopupBlockedError',
|
|
18
|
-
'PopupClosedError',
|
|
19
|
-
'UnsupportedFlowError',
|
|
20
|
-
'SessionExpiredError',
|
|
21
|
-
'NetworkError',
|
|
22
|
-
'ServerError',
|
|
23
|
-
'OidcError',
|
|
24
|
-
'ProtocolError',
|
|
25
|
-
'ConfigurationError',
|
|
26
|
-
'InternalError',
|
|
27
|
-
'throwTokenEndpointError',
|
|
28
|
-
'throwHttpError',
|
|
29
|
-
'createHttpClient',
|
|
30
|
-
'createDefaultLogging',
|
|
31
|
-
'getDefaultFlowState',
|
|
32
|
-
'defaultOptions',
|
|
33
|
-
'getDiscoveryDocument',
|
|
34
|
-
'getSDKOptions',
|
|
35
|
-
'generateCodeVerifier',
|
|
36
|
-
'generateCodeChallenge',
|
|
37
|
-
'generateRandomHex',
|
|
38
|
-
'decodeJwt',
|
|
39
|
-
'verifyJwt',
|
|
40
|
-
'generateJwt',
|
|
41
|
-
'verifyIdToken',
|
|
42
|
-
'buildAuthorizationUrl',
|
|
43
|
-
'buildEndSessionUrl',
|
|
44
|
-
'exchangeCode',
|
|
45
|
-
'refreshToken',
|
|
46
|
-
'revokeToken',
|
|
47
|
-
'fetchFlowEntry',
|
|
48
|
-
'finalizeLoginSession',
|
|
49
|
-
'submitLoginForm',
|
|
50
|
-
'DISALLOWED_PROXY_HEADERS',
|
|
51
|
-
'RETURN_TO_COOKIE',
|
|
52
|
-
'BACKCHANNEL_LOGOUT_EVENT',
|
|
53
|
-
'DEFAULT_COOKIE_MAX_AGE',
|
|
54
|
-
'getServerSDKOptions',
|
|
55
|
-
'parseCookieHeader',
|
|
56
|
-
'serializeCookie',
|
|
57
|
-
'pushSetCookie',
|
|
58
|
-
'flushSetCookies',
|
|
59
|
-
'proxyResponse',
|
|
60
|
-
'toSafeRedirect',
|
|
61
|
-
'createSession',
|
|
62
|
-
'loadSession',
|
|
63
|
-
'serializeSession',
|
|
64
|
-
'isSessionExpired',
|
|
65
|
-
'createState',
|
|
66
|
-
'parseState',
|
|
67
|
-
'serializeState',
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
expect(Object.keys(index)).toEqual(expectedExports);
|
|
71
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, vi } from 'vitest';
|
|
2
|
-
import { createDefaultLogging } from '../../../src/utils/logging';
|
|
3
|
-
|
|
4
|
-
describe('createDefaultLogging', () => {
|
|
5
|
-
test('logs debug messages via console.log without an xEventId prefix', () => {
|
|
6
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
7
|
-
const logging = createDefaultLogging();
|
|
8
|
-
|
|
9
|
-
logging.debug('hello');
|
|
10
|
-
|
|
11
|
-
expect(logSpy).toHaveBeenCalledWith('hello');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('prefixes debug messages with the xEventId when set', () => {
|
|
15
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
16
|
-
const logging = createDefaultLogging();
|
|
17
|
-
logging.xEventId = 'event-1';
|
|
18
|
-
|
|
19
|
-
logging.debug('hello');
|
|
20
|
-
|
|
21
|
-
expect(logSpy).toHaveBeenCalledWith('(event-1) hello');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('logs info messages via console.info', () => {
|
|
25
|
-
const infoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
|
|
26
|
-
const logging = createDefaultLogging();
|
|
27
|
-
|
|
28
|
-
logging.info('hello');
|
|
29
|
-
|
|
30
|
-
expect(infoSpy).toHaveBeenCalledWith('hello');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('prefixes info messages with the xEventId when set', () => {
|
|
34
|
-
const infoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
|
|
35
|
-
const logging = createDefaultLogging();
|
|
36
|
-
logging.xEventId = 'event-1';
|
|
37
|
-
|
|
38
|
-
logging.info('hello');
|
|
39
|
-
|
|
40
|
-
expect(infoSpy).toHaveBeenCalledWith('(event-1) hello');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('logs warn messages via console.warn', () => {
|
|
44
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
45
|
-
const logging = createDefaultLogging();
|
|
46
|
-
|
|
47
|
-
logging.warn('hello');
|
|
48
|
-
|
|
49
|
-
expect(warnSpy).toHaveBeenCalledWith('hello');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('prefixes warn messages with the xEventId when set', () => {
|
|
53
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
54
|
-
const logging = createDefaultLogging();
|
|
55
|
-
logging.xEventId = 'event-1';
|
|
56
|
-
|
|
57
|
-
logging.warn('hello');
|
|
58
|
-
|
|
59
|
-
expect(warnSpy).toHaveBeenCalledWith('(event-1) hello');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('logs error messages via console.error including the error', () => {
|
|
63
|
-
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
64
|
-
const logging = createDefaultLogging();
|
|
65
|
-
const error = new Error('boom');
|
|
66
|
-
|
|
67
|
-
logging.error('hello', error);
|
|
68
|
-
|
|
69
|
-
expect(errorSpy).toHaveBeenCalledWith(`hello - ${error}`);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('prefixes error messages with the xEventId when set', () => {
|
|
73
|
-
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
74
|
-
const logging = createDefaultLogging();
|
|
75
|
-
logging.xEventId = 'event-1';
|
|
76
|
-
const error = new Error('boom');
|
|
77
|
-
|
|
78
|
-
logging.error('hello', error);
|
|
79
|
-
|
|
80
|
-
expect(errorSpy).toHaveBeenCalledWith(`(event-1) hello - ${error}`);
|
|
81
|
-
});
|
|
82
|
-
});
|