@logtape/testing 2.3.0-dev.815 → 2.3.0-dev.816

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.
@@ -0,0 +1,153 @@
1
+ import { LogLevel, LogRecord, Sink } from "@logtape/logtape";
2
+
3
+ //#region src/recorder.d.ts
4
+
5
+ /**
6
+ * A predicate that matches log record properties.
7
+ *
8
+ * The first argument is the resolved properties object. The second argument
9
+ * is the full log record for cases where the predicate needs category, level,
10
+ * or message context.
11
+ *
12
+ * @since 2.2.0
13
+ */
14
+ type PropertyMatcher = (properties: Readonly<Record<string, unknown>>, record: LogRecord) => boolean;
15
+ /**
16
+ * A matcher for records collected by a {@link LogRecorder}.
17
+ *
18
+ * Object property matching is shallow: every own string key in the matcher
19
+ * must exist on the record properties and match by value. Most values are
20
+ * compared with `Object.is()`, `Date` values are compared by timestamp, and
21
+ * regular expression matcher values match string property values. Use a
22
+ * {@link PropertyMatcher} when a test needs absence checks or deeper matching.
23
+ *
24
+ * @since 2.2.0
25
+ */
26
+ interface LogRecordMatch {
27
+ /**
28
+ * Exact category matcher. A string is matched against the dot-joined
29
+ * category, while an array is matched segment by segment. A regular
30
+ * expression is tested against the dot-joined category.
31
+ */
32
+ readonly category?: string | readonly string[] | RegExp;
33
+ /**
34
+ * Category prefix matcher. A string is split on dots, while an array is
35
+ * matched segment by segment.
36
+ */
37
+ readonly categoryPrefix?: string | readonly string[];
38
+ /**
39
+ * Exact severity level matcher.
40
+ */
41
+ readonly level?: LogLevel;
42
+ /**
43
+ * Rendered message matcher. String and regular expression matchers are
44
+ * applied to the rendered message, using the same value rendering as
45
+ * LogTape's default text formatter. A predicate receives the full record.
46
+ */
47
+ readonly message?: string | RegExp | ((record: LogRecord) => boolean);
48
+ /**
49
+ * Raw message matcher. A string record is matched directly. A tagged
50
+ * template record is matched against the concatenated template strings.
51
+ */
52
+ readonly rawMessage?: string | RegExp;
53
+ /**
54
+ * Shallow property matcher or predicate.
55
+ */
56
+ readonly properties?: Readonly<Record<string, unknown>> | PropertyMatcher;
57
+ /**
58
+ * Full-record predicate for custom checks.
59
+ */
60
+ readonly predicate?: (record: LogRecord) => boolean;
61
+ }
62
+ /**
63
+ * A test recorder for LogTape records.
64
+ *
65
+ * @since 2.2.0
66
+ */
67
+ interface LogRecorder {
68
+ /**
69
+ * A sink that appends each received record to {@link LogRecorder.records}.
70
+ */
71
+ readonly sink: Sink;
72
+ /**
73
+ * A snapshot of records collected so far, in sink call order.
74
+ */
75
+ readonly records: readonly LogRecord[];
76
+ /**
77
+ * Removes all collected records.
78
+ */
79
+ clear(): void;
80
+ /**
81
+ * Returns collected records and clears the recorder.
82
+ */
83
+ take(): readonly LogRecord[];
84
+ /**
85
+ * Finds the first collected record matching the given matcher.
86
+ *
87
+ * @param match The matcher to apply.
88
+ * @returns The first matching record, or `undefined`.
89
+ */
90
+ find(match: LogRecordMatch): LogRecord | undefined;
91
+ /**
92
+ * Finds all collected records matching the given matcher.
93
+ *
94
+ * @param match The matcher to apply.
95
+ * @returns All matching records in collection order.
96
+ */
97
+ filter(match: LogRecordMatch): readonly LogRecord[];
98
+ /**
99
+ * Asserts that at least one collected record matches the given matcher.
100
+ *
101
+ * @param match The matcher to apply.
102
+ * @throws {Error} If no matching record exists.
103
+ */
104
+ assertLogged(match: LogRecordMatch): void;
105
+ /**
106
+ * Asserts that no collected record matches the given matcher.
107
+ *
108
+ * @param match The matcher to apply.
109
+ * @throws {Error} If a matching record exists.
110
+ */
111
+ assertNotLogged(match: LogRecordMatch): void;
112
+ }
113
+ /**
114
+ * Creates a LogTape test recorder.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { configure, getLogger, reset } from "@logtape/logtape";
119
+ * import { createLogRecorder } from "@logtape/testing/recorder";
120
+ *
121
+ * const recorder = createLogRecorder();
122
+ *
123
+ * try {
124
+ * await configure({
125
+ * sinks: { recorder: recorder.sink },
126
+ * loggers: [
127
+ * { category: ["my-lib"], lowestLevel: "debug", sinks: ["recorder"] },
128
+ * ],
129
+ * });
130
+ *
131
+ * getLogger(["my-lib"]).info("User {userId} logged in.", {
132
+ * userId: 123,
133
+ * });
134
+ *
135
+ * recorder.assertLogged({
136
+ * category: ["my-lib"],
137
+ * level: "info",
138
+ * message: "User 123 logged in.",
139
+ * properties: { userId: 123 },
140
+ * });
141
+ * } finally {
142
+ * await reset();
143
+ * }
144
+ * ```
145
+ *
146
+ * @returns A recorder with a sink and assertion helpers.
147
+ * @since 2.2.0
148
+ */
149
+ declare function createLogRecorder(): LogRecorder;
150
+ //# sourceMappingURL=recorder.d.ts.map
151
+ //#endregion
152
+ export { LogRecordMatch, LogRecorder, PropertyMatcher, createLogRecorder };
153
+ //# sourceMappingURL=recorder.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recorder.d.cts","names":[],"sources":["../src/recorder.ts"],"sourcesContent":[],"mappings":";;;;;;AAyBA;;;;;AAEmB;AAcnB;AAA+B,KAhBnB,eAAA,GAgBmB,CAAA,UAAA,EAfjB,QAeiB,CAfR,MAeQ,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,EAAA,MAAA,EAdrB,SAcqB,EAAA,GAAA,OAAA;;;;;;;;;;AAwCU;AAQzC;AAA4B,UAhDX,cAAA,CAgDW;EAAA;;;;;EA2BY,SAQxB,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA,MAAA,EAAA,GA7EmC,MA6EnC;EAAc;;;AAgBS;EAuCvB,SAAA,cAAiB,CAAA,EAAA,MAAI,GAAA,SAAW,MAAA,EAAA;;;;mBAzH7B;;;;;;8BAOW,mBAAmB;;;;;iCAMhB;;;;wBAKT,SAAS,2BAA2B;;;;gCAK5B;;;;;;;UAQf,WAAA;;;;iBAIA;;;;6BAKY;;;;;;;;mBAUV;;;;;;;cAQL,iBAAiB;;;;;;;gBAQf,0BAA0B;;;;;;;sBAQpB;;;;;;;yBAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuCT,iBAAA,CAAA,GAAqB"}
@@ -0,0 +1,153 @@
1
+ import { LogLevel, LogRecord, Sink } from "@logtape/logtape";
2
+
3
+ //#region src/recorder.d.ts
4
+
5
+ /**
6
+ * A predicate that matches log record properties.
7
+ *
8
+ * The first argument is the resolved properties object. The second argument
9
+ * is the full log record for cases where the predicate needs category, level,
10
+ * or message context.
11
+ *
12
+ * @since 2.2.0
13
+ */
14
+ type PropertyMatcher = (properties: Readonly<Record<string, unknown>>, record: LogRecord) => boolean;
15
+ /**
16
+ * A matcher for records collected by a {@link LogRecorder}.
17
+ *
18
+ * Object property matching is shallow: every own string key in the matcher
19
+ * must exist on the record properties and match by value. Most values are
20
+ * compared with `Object.is()`, `Date` values are compared by timestamp, and
21
+ * regular expression matcher values match string property values. Use a
22
+ * {@link PropertyMatcher} when a test needs absence checks or deeper matching.
23
+ *
24
+ * @since 2.2.0
25
+ */
26
+ interface LogRecordMatch {
27
+ /**
28
+ * Exact category matcher. A string is matched against the dot-joined
29
+ * category, while an array is matched segment by segment. A regular
30
+ * expression is tested against the dot-joined category.
31
+ */
32
+ readonly category?: string | readonly string[] | RegExp;
33
+ /**
34
+ * Category prefix matcher. A string is split on dots, while an array is
35
+ * matched segment by segment.
36
+ */
37
+ readonly categoryPrefix?: string | readonly string[];
38
+ /**
39
+ * Exact severity level matcher.
40
+ */
41
+ readonly level?: LogLevel;
42
+ /**
43
+ * Rendered message matcher. String and regular expression matchers are
44
+ * applied to the rendered message, using the same value rendering as
45
+ * LogTape's default text formatter. A predicate receives the full record.
46
+ */
47
+ readonly message?: string | RegExp | ((record: LogRecord) => boolean);
48
+ /**
49
+ * Raw message matcher. A string record is matched directly. A tagged
50
+ * template record is matched against the concatenated template strings.
51
+ */
52
+ readonly rawMessage?: string | RegExp;
53
+ /**
54
+ * Shallow property matcher or predicate.
55
+ */
56
+ readonly properties?: Readonly<Record<string, unknown>> | PropertyMatcher;
57
+ /**
58
+ * Full-record predicate for custom checks.
59
+ */
60
+ readonly predicate?: (record: LogRecord) => boolean;
61
+ }
62
+ /**
63
+ * A test recorder for LogTape records.
64
+ *
65
+ * @since 2.2.0
66
+ */
67
+ interface LogRecorder {
68
+ /**
69
+ * A sink that appends each received record to {@link LogRecorder.records}.
70
+ */
71
+ readonly sink: Sink;
72
+ /**
73
+ * A snapshot of records collected so far, in sink call order.
74
+ */
75
+ readonly records: readonly LogRecord[];
76
+ /**
77
+ * Removes all collected records.
78
+ */
79
+ clear(): void;
80
+ /**
81
+ * Returns collected records and clears the recorder.
82
+ */
83
+ take(): readonly LogRecord[];
84
+ /**
85
+ * Finds the first collected record matching the given matcher.
86
+ *
87
+ * @param match The matcher to apply.
88
+ * @returns The first matching record, or `undefined`.
89
+ */
90
+ find(match: LogRecordMatch): LogRecord | undefined;
91
+ /**
92
+ * Finds all collected records matching the given matcher.
93
+ *
94
+ * @param match The matcher to apply.
95
+ * @returns All matching records in collection order.
96
+ */
97
+ filter(match: LogRecordMatch): readonly LogRecord[];
98
+ /**
99
+ * Asserts that at least one collected record matches the given matcher.
100
+ *
101
+ * @param match The matcher to apply.
102
+ * @throws {Error} If no matching record exists.
103
+ */
104
+ assertLogged(match: LogRecordMatch): void;
105
+ /**
106
+ * Asserts that no collected record matches the given matcher.
107
+ *
108
+ * @param match The matcher to apply.
109
+ * @throws {Error} If a matching record exists.
110
+ */
111
+ assertNotLogged(match: LogRecordMatch): void;
112
+ }
113
+ /**
114
+ * Creates a LogTape test recorder.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { configure, getLogger, reset } from "@logtape/logtape";
119
+ * import { createLogRecorder } from "@logtape/testing/recorder";
120
+ *
121
+ * const recorder = createLogRecorder();
122
+ *
123
+ * try {
124
+ * await configure({
125
+ * sinks: { recorder: recorder.sink },
126
+ * loggers: [
127
+ * { category: ["my-lib"], lowestLevel: "debug", sinks: ["recorder"] },
128
+ * ],
129
+ * });
130
+ *
131
+ * getLogger(["my-lib"]).info("User {userId} logged in.", {
132
+ * userId: 123,
133
+ * });
134
+ *
135
+ * recorder.assertLogged({
136
+ * category: ["my-lib"],
137
+ * level: "info",
138
+ * message: "User 123 logged in.",
139
+ * properties: { userId: 123 },
140
+ * });
141
+ * } finally {
142
+ * await reset();
143
+ * }
144
+ * ```
145
+ *
146
+ * @returns A recorder with a sink and assertion helpers.
147
+ * @since 2.2.0
148
+ */
149
+ declare function createLogRecorder(): LogRecorder;
150
+ //# sourceMappingURL=recorder.d.ts.map
151
+ //#endregion
152
+ export { LogRecordMatch, LogRecorder, PropertyMatcher, createLogRecorder };
153
+ //# sourceMappingURL=recorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recorder.d.ts","names":[],"sources":["../src/recorder.ts"],"sourcesContent":[],"mappings":";;;;;;AAyBA;;;;;AAEmB;AAcnB;AAA+B,KAhBnB,eAAA,GAgBmB,CAAA,UAAA,EAfjB,QAeiB,CAfR,MAeQ,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,EAAA,MAAA,EAdrB,SAcqB,EAAA,GAAA,OAAA;;;;;;;;;;AAwCU;AAQzC;AAA4B,UAhDX,cAAA,CAgDW;EAAA;;;;;EA2BY,SAQxB,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA,MAAA,EAAA,GA7EmC,MA6EnC;EAAc;;;AAgBS;EAuCvB,SAAA,cAAiB,CAAA,EAAA,MAAI,GAAA,SAAW,MAAA,EAAA;;;;mBAzH7B;;;;;;8BAOW,mBAAmB;;;;;iCAMhB;;;;wBAKT,SAAS,2BAA2B;;;;gCAK5B;;;;;;;UAQf,WAAA;;;;iBAIA;;;;6BAKY;;;;;;;;mBAUV;;;;;;;cAQL,iBAAiB;;;;;;;gBAQf,0BAA0B;;;;;;;sBAQpB;;;;;;;yBAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuCT,iBAAA,CAAA,GAAqB"}
@@ -0,0 +1,282 @@
1
+ import { materializeLogRecord } from "./snapshot.js";
2
+ import { getTextFormatter } from "@logtape/logtape";
3
+
4
+ //#region src/recorder.ts
5
+ const messageFormatter = getTextFormatter({
6
+ format: ({ message }) => message,
7
+ lineEnding: "lf",
8
+ timestamp: "none"
9
+ });
10
+ /**
11
+ * Creates a LogTape test recorder.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { configure, getLogger, reset } from "@logtape/logtape";
16
+ * import { createLogRecorder } from "@logtape/testing/recorder";
17
+ *
18
+ * const recorder = createLogRecorder();
19
+ *
20
+ * try {
21
+ * await configure({
22
+ * sinks: { recorder: recorder.sink },
23
+ * loggers: [
24
+ * { category: ["my-lib"], lowestLevel: "debug", sinks: ["recorder"] },
25
+ * ],
26
+ * });
27
+ *
28
+ * getLogger(["my-lib"]).info("User {userId} logged in.", {
29
+ * userId: 123,
30
+ * });
31
+ *
32
+ * recorder.assertLogged({
33
+ * category: ["my-lib"],
34
+ * level: "info",
35
+ * message: "User 123 logged in.",
36
+ * properties: { userId: 123 },
37
+ * });
38
+ * } finally {
39
+ * await reset();
40
+ * }
41
+ * ```
42
+ *
43
+ * @returns A recorder with a sink and assertion helpers.
44
+ * @since 2.2.0
45
+ */
46
+ function createLogRecorder() {
47
+ const records = [];
48
+ const sink = (record) => {
49
+ records.push(materializeLogRecord(record));
50
+ };
51
+ return {
52
+ sink,
53
+ get records() {
54
+ return records.slice();
55
+ },
56
+ clear() {
57
+ records.length = 0;
58
+ },
59
+ take() {
60
+ return records.splice(0);
61
+ },
62
+ find(match) {
63
+ return records.find((record) => matchesLogRecord(record, match));
64
+ },
65
+ filter(match) {
66
+ return records.filter((record) => matchesLogRecord(record, match));
67
+ },
68
+ assertLogged(match) {
69
+ if (records.some((record) => matchesLogRecord(record, match))) return;
70
+ throw new Error([
71
+ "Expected a LogTape record matching:",
72
+ formatMatcher(match),
73
+ "",
74
+ `Recorded ${formatCount(records.length, "record")}:`,
75
+ formatRecords(records)
76
+ ].join("\n"));
77
+ },
78
+ assertNotLogged(match) {
79
+ const matching = records.filter((record) => matchesLogRecord(record, match));
80
+ if (matching.length < 1) return;
81
+ throw new Error([
82
+ "Expected no LogTape record matching:",
83
+ formatMatcher(match),
84
+ "",
85
+ `Found ${formatCount(matching.length, "matching record")}:`,
86
+ formatRecords(matching)
87
+ ].join("\n"));
88
+ }
89
+ };
90
+ }
91
+ function matchesLogRecord(record, match) {
92
+ if (match.category != null && !matchesCategory(record.category, match.category)) return false;
93
+ if (match.categoryPrefix != null && !matchesCategoryPrefix(record.category, match.categoryPrefix)) return false;
94
+ if (match.level != null && record.level !== match.level) return false;
95
+ if (match.message != null && !matchesMessage(record, match.message)) return false;
96
+ if (match.rawMessage != null && !matchesText(renderRawMessage(record.rawMessage), match.rawMessage)) return false;
97
+ if (match.properties != null && !matchesProperties(record.properties, record, match.properties)) return false;
98
+ if (match.predicate != null && !match.predicate(record)) return false;
99
+ return true;
100
+ }
101
+ function matchesCategory(category, expected) {
102
+ const joinedCategory = category.join(".");
103
+ if (expected instanceof RegExp) return testRegExp(expected, joinedCategory);
104
+ if (typeof expected === "string") return joinedCategory === expected;
105
+ const expectedCategory = parseCategory(expected);
106
+ return category.length === expectedCategory.length && category.every((part, index) => part === expectedCategory[index]);
107
+ }
108
+ function matchesCategoryPrefix(category, prefix) {
109
+ const expectedPrefix = parseCategory(prefix);
110
+ return expectedPrefix.length <= category.length && expectedPrefix.every((part, index) => part === category[index]);
111
+ }
112
+ function parseCategory(category) {
113
+ if (typeof category !== "string") return category;
114
+ return category === "" ? [] : category.split(".");
115
+ }
116
+ function matchesMessage(record, matcher) {
117
+ if (typeof matcher === "function") return matcher(record);
118
+ return matchesText(renderMessage(record), matcher);
119
+ }
120
+ function matchesText(text, matcher) {
121
+ return typeof matcher === "string" ? text === matcher : testRegExp(matcher, text);
122
+ }
123
+ function matchesProperties(properties, record, matcher) {
124
+ const props = properties ?? {};
125
+ if (typeof matcher === "function") return matcher(props, record);
126
+ for (const key of Object.keys(matcher)) {
127
+ if (!Object.prototype.hasOwnProperty.call(props, key)) return false;
128
+ if (!matchesPropertyValue(props[key], matcher[key])) return false;
129
+ }
130
+ return true;
131
+ }
132
+ function matchesPropertyValue(actual, expected) {
133
+ if (actual instanceof Date && expected instanceof Date) return Object.is(actual.getTime(), expected.getTime());
134
+ if (typeof actual === "string" && expected instanceof RegExp) return testRegExp(expected, actual);
135
+ return Object.is(actual, expected);
136
+ }
137
+ function testRegExp(pattern, text) {
138
+ if (!pattern.global && !pattern.sticky) return pattern.test(text);
139
+ const clone = new RegExp(pattern.source, pattern.flags);
140
+ return clone.test(text);
141
+ }
142
+ function renderRawMessage(rawMessage) {
143
+ return typeof rawMessage === "string" ? rawMessage : rawMessage.join("");
144
+ }
145
+ function renderMessage(record) {
146
+ return messageFormatter(record).slice(0, -1);
147
+ }
148
+ function formatMatcher(match) {
149
+ const lines = [];
150
+ if (match.category != null) lines.push(` category: ${formatCategoryMatcher(match.category)}`);
151
+ if (match.categoryPrefix != null) lines.push(` categoryPrefix: ${formatCategoryValue(parseCategory(match.categoryPrefix))}`);
152
+ if (match.level != null) lines.push(` level: ${formatValue(match.level)}`);
153
+ if (match.message != null) lines.push(` message: ${formatMessageMatcher(match.message)}`);
154
+ if (match.rawMessage != null) lines.push(` rawMessage: ${formatTextMatcher(match.rawMessage)}`);
155
+ if (match.properties != null) lines.push(...formatPropertiesMatcher(match.properties));
156
+ if (match.predicate != null) lines.push(" predicate: <predicate>");
157
+ return lines.length < 1 ? " <any record>" : lines.join("\n");
158
+ }
159
+ function formatCategoryMatcher(category) {
160
+ return category instanceof RegExp ? String(category) : typeof category === "string" ? formatValue(category) : formatCategoryValue(category);
161
+ }
162
+ function formatCategoryValue(category) {
163
+ return `[${category.map((part) => formatValue(part)).join(", ")}]`;
164
+ }
165
+ function formatMessageMatcher(matcher) {
166
+ return typeof matcher === "function" ? "<predicate>" : formatTextMatcher(matcher);
167
+ }
168
+ function formatTextMatcher(matcher) {
169
+ return typeof matcher === "string" ? formatValue(matcher) : String(matcher);
170
+ }
171
+ function formatPropertiesMatcher(matcher) {
172
+ if (typeof matcher === "function") return [" properties: <predicate>"];
173
+ const lines = Object.keys(matcher).map((key) => ` properties.${key}: ${formatPropertyValue(matcher, key)}`);
174
+ return lines.length < 1 ? [" properties: {}"] : lines;
175
+ }
176
+ function formatRecords(records) {
177
+ if (records.length < 1) return " <none>";
178
+ const lines = records.slice(0, 3).map(formatRecord);
179
+ if (records.length > 3) lines.push(` ... ${records.length - 3} more`);
180
+ return lines.join("\n");
181
+ }
182
+ function formatRecord(record) {
183
+ const category = formatCategory(record.category);
184
+ return ` [${record.level}] ${category}: ${formatMessage(record)}${formatProperties(record.properties)}`;
185
+ }
186
+ function formatMessage(record) {
187
+ try {
188
+ return renderMessage(record);
189
+ } catch (error) {
190
+ return formatAccessError(error);
191
+ }
192
+ }
193
+ function formatCategory(category) {
194
+ return category.length < 1 ? "<root>" : category.join(".");
195
+ }
196
+ function formatProperties(properties) {
197
+ const props = properties ?? {};
198
+ const entries = Object.keys(props);
199
+ if (entries.length < 1) return "";
200
+ const summary = entries.slice(0, 3).map((key) => `${key}: ${formatPropertyValue(props, key)}`);
201
+ if (entries.length > 3) summary.push(`... ${entries.length - 3} more`);
202
+ return ` {${summary.join(", ")}}`;
203
+ }
204
+ function formatPropertyValue(properties, key) {
205
+ try {
206
+ return formatValue(properties[key]);
207
+ } catch (error) {
208
+ return formatAccessError(error);
209
+ }
210
+ }
211
+ function formatAccessError(error) {
212
+ return `<error: ${error instanceof Error ? error.message : safeString(error)}>`;
213
+ }
214
+ function formatCount(count, noun) {
215
+ return `${count} ${noun}${count === 1 ? "" : "s"}`;
216
+ }
217
+ function formatValue(value) {
218
+ if (typeof value === "string") return JSON.stringify(value);
219
+ if (typeof value === "number" && !Number.isFinite(value)) return String(value);
220
+ if (typeof value === "bigint") return `${value}n`;
221
+ if (typeof value === "symbol") return String(value);
222
+ if (value instanceof RegExp) return String(value);
223
+ if (value instanceof Error) return `${value.name}: ${value.message}`;
224
+ if (value instanceof Map) return formatMap(value);
225
+ if (value instanceof Set) return formatSet(value);
226
+ try {
227
+ return safeJsonStringify(value) ?? safeString(value);
228
+ } catch {
229
+ return safeString(value);
230
+ }
231
+ }
232
+ function formatMap(value) {
233
+ const label = `Map(${value.size})`;
234
+ try {
235
+ const contents = formatMapContents(value);
236
+ return `${label} ${safeJsonStringify(contents) ?? safeString(contents)}`;
237
+ } catch {
238
+ return label;
239
+ }
240
+ }
241
+ function formatSet(value) {
242
+ const label = `Set(${value.size})`;
243
+ try {
244
+ const contents = Array.from(value);
245
+ return `${label} ${safeJsonStringify(contents) ?? safeString(contents)}`;
246
+ } catch {
247
+ return label;
248
+ }
249
+ }
250
+ function safeJsonStringify(value) {
251
+ const ancestors = [];
252
+ return JSON.stringify(value, function(_key, item) {
253
+ if (typeof item === "bigint") return `${item}n`;
254
+ if (item instanceof RegExp) return String(item);
255
+ if (item instanceof Error) return `${item.name}: ${item.message}`;
256
+ if (typeof item === "object" && item != null) {
257
+ while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) ancestors.pop();
258
+ if (ancestors.includes(item)) return "[Circular]";
259
+ ancestors.push(item);
260
+ if (item instanceof Map) return formatMapContents(item);
261
+ if (item instanceof Set) return Array.from(item);
262
+ }
263
+ return item;
264
+ });
265
+ }
266
+ function formatMapContents(value) {
267
+ const entries = Array.from(value, ([key, entryValue]) => [safeString(key), entryValue]);
268
+ const keys = entries.map(([key]) => key);
269
+ const uniqueKeys = new Set(keys);
270
+ return uniqueKeys.size === keys.length ? Object.fromEntries(entries) : entries;
271
+ }
272
+ function safeString(value) {
273
+ try {
274
+ return String(value);
275
+ } catch {
276
+ return Object.prototype.toString.call(value);
277
+ }
278
+ }
279
+
280
+ //#endregion
281
+ export { createLogRecorder };
282
+ //# sourceMappingURL=recorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recorder.js","names":["messageFormatter: TextFormatter","records: LogRecord[]","sink: Sink","record: LogRecord","match: LogRecordMatch","category: readonly string[]","expected: string | readonly string[] | RegExp","prefix: string | readonly string[]","category: string | readonly string[]","matcher: string | RegExp | ((record: LogRecord) => boolean)","text: string","matcher: string | RegExp","properties: Readonly<Record<string, unknown>> | null | undefined","matcher: Readonly<Record<string, unknown>> | PropertyMatcher","props: Readonly<Record<string, unknown>>","actual: unknown","expected: unknown","pattern: RegExp","rawMessage: string | TemplateStringsArray","lines: string[]","category: string | readonly string[] | RegExp","records: readonly LogRecord[]","properties: Readonly<Record<string, unknown>>","key: string","error: unknown","count: number","noun: string","value: unknown","value: ReadonlyMap<unknown, unknown>","value: ReadonlySet<unknown>","ancestors: object[]","_key: string","item: unknown"],"sources":["../src/recorder.ts"],"sourcesContent":["import {\n getTextFormatter,\n type LogLevel,\n type LogRecord,\n type Sink,\n type TextFormatter,\n} from \"@logtape/logtape\";\n\nimport { materializeLogRecord } from \"./snapshot.ts\";\n\nconst messageFormatter: TextFormatter = getTextFormatter({\n format: ({ message }) => message,\n lineEnding: \"lf\",\n timestamp: \"none\",\n});\n\n/**\n * A predicate that matches log record properties.\n *\n * The first argument is the resolved properties object. The second argument\n * is the full log record for cases where the predicate needs category, level,\n * or message context.\n *\n * @since 2.2.0\n */\nexport type PropertyMatcher = (\n properties: Readonly<Record<string, unknown>>,\n record: LogRecord,\n) => boolean;\n\n/**\n * A matcher for records collected by a {@link LogRecorder}.\n *\n * Object property matching is shallow: every own string key in the matcher\n * must exist on the record properties and match by value. Most values are\n * compared with `Object.is()`, `Date` values are compared by timestamp, and\n * regular expression matcher values match string property values. Use a\n * {@link PropertyMatcher} when a test needs absence checks or deeper matching.\n *\n * @since 2.2.0\n */\nexport interface LogRecordMatch {\n /**\n * Exact category matcher. A string is matched against the dot-joined\n * category, while an array is matched segment by segment. A regular\n * expression is tested against the dot-joined category.\n */\n readonly category?: string | readonly string[] | RegExp;\n\n /**\n * Category prefix matcher. A string is split on dots, while an array is\n * matched segment by segment.\n */\n readonly categoryPrefix?: string | readonly string[];\n\n /**\n * Exact severity level matcher.\n */\n readonly level?: LogLevel;\n\n /**\n * Rendered message matcher. String and regular expression matchers are\n * applied to the rendered message, using the same value rendering as\n * LogTape's default text formatter. A predicate receives the full record.\n */\n readonly message?: string | RegExp | ((record: LogRecord) => boolean);\n\n /**\n * Raw message matcher. A string record is matched directly. A tagged\n * template record is matched against the concatenated template strings.\n */\n readonly rawMessage?: string | RegExp;\n\n /**\n * Shallow property matcher or predicate.\n */\n readonly properties?: Readonly<Record<string, unknown>> | PropertyMatcher;\n\n /**\n * Full-record predicate for custom checks.\n */\n readonly predicate?: (record: LogRecord) => boolean;\n}\n\n/**\n * A test recorder for LogTape records.\n *\n * @since 2.2.0\n */\nexport interface LogRecorder {\n /**\n * A sink that appends each received record to {@link LogRecorder.records}.\n */\n readonly sink: Sink;\n\n /**\n * A snapshot of records collected so far, in sink call order.\n */\n readonly records: readonly LogRecord[];\n\n /**\n * Removes all collected records.\n */\n clear(): void;\n\n /**\n * Returns collected records and clears the recorder.\n */\n take(): readonly LogRecord[];\n\n /**\n * Finds the first collected record matching the given matcher.\n *\n * @param match The matcher to apply.\n * @returns The first matching record, or `undefined`.\n */\n find(match: LogRecordMatch): LogRecord | undefined;\n\n /**\n * Finds all collected records matching the given matcher.\n *\n * @param match The matcher to apply.\n * @returns All matching records in collection order.\n */\n filter(match: LogRecordMatch): readonly LogRecord[];\n\n /**\n * Asserts that at least one collected record matches the given matcher.\n *\n * @param match The matcher to apply.\n * @throws {Error} If no matching record exists.\n */\n assertLogged(match: LogRecordMatch): void;\n\n /**\n * Asserts that no collected record matches the given matcher.\n *\n * @param match The matcher to apply.\n * @throws {Error} If a matching record exists.\n */\n assertNotLogged(match: LogRecordMatch): void;\n}\n\n/**\n * Creates a LogTape test recorder.\n *\n * @example\n * ```ts\n * import { configure, getLogger, reset } from \"@logtape/logtape\";\n * import { createLogRecorder } from \"@logtape/testing/recorder\";\n *\n * const recorder = createLogRecorder();\n *\n * try {\n * await configure({\n * sinks: { recorder: recorder.sink },\n * loggers: [\n * { category: [\"my-lib\"], lowestLevel: \"debug\", sinks: [\"recorder\"] },\n * ],\n * });\n *\n * getLogger([\"my-lib\"]).info(\"User {userId} logged in.\", {\n * userId: 123,\n * });\n *\n * recorder.assertLogged({\n * category: [\"my-lib\"],\n * level: \"info\",\n * message: \"User 123 logged in.\",\n * properties: { userId: 123 },\n * });\n * } finally {\n * await reset();\n * }\n * ```\n *\n * @returns A recorder with a sink and assertion helpers.\n * @since 2.2.0\n */\nexport function createLogRecorder(): LogRecorder {\n const records: LogRecord[] = [];\n const sink: Sink = (record: LogRecord): void => {\n records.push(materializeLogRecord(record));\n };\n\n return {\n sink,\n get records(): readonly LogRecord[] {\n return records.slice();\n },\n clear(): void {\n records.length = 0;\n },\n take(): readonly LogRecord[] {\n return records.splice(0);\n },\n find(match: LogRecordMatch): LogRecord | undefined {\n return records.find((record) => matchesLogRecord(record, match));\n },\n filter(match: LogRecordMatch): readonly LogRecord[] {\n return records.filter((record) => matchesLogRecord(record, match));\n },\n assertLogged(match: LogRecordMatch): void {\n if (records.some((record) => matchesLogRecord(record, match))) return;\n\n throw new Error(\n [\n \"Expected a LogTape record matching:\",\n formatMatcher(match),\n \"\",\n `Recorded ${formatCount(records.length, \"record\")}:`,\n formatRecords(records),\n ].join(\"\\n\"),\n );\n },\n assertNotLogged(match: LogRecordMatch): void {\n const matching = records.filter((record) =>\n matchesLogRecord(record, match)\n );\n if (matching.length < 1) return;\n\n throw new Error(\n [\n \"Expected no LogTape record matching:\",\n formatMatcher(match),\n \"\",\n `Found ${formatCount(matching.length, \"matching record\")}:`,\n formatRecords(matching),\n ].join(\"\\n\"),\n );\n },\n };\n}\n\nfunction matchesLogRecord(record: LogRecord, match: LogRecordMatch): boolean {\n if (\n match.category != null &&\n !matchesCategory(record.category, match.category)\n ) {\n return false;\n }\n if (\n match.categoryPrefix != null &&\n !matchesCategoryPrefix(record.category, match.categoryPrefix)\n ) {\n return false;\n }\n if (match.level != null && record.level !== match.level) return false;\n if (\n match.message != null &&\n !matchesMessage(record, match.message)\n ) {\n return false;\n }\n if (\n match.rawMessage != null &&\n !matchesText(renderRawMessage(record.rawMessage), match.rawMessage)\n ) {\n return false;\n }\n if (\n match.properties != null &&\n !matchesProperties(record.properties, record, match.properties)\n ) {\n return false;\n }\n if (match.predicate != null && !match.predicate(record)) return false;\n return true;\n}\n\nfunction matchesCategory(\n category: readonly string[],\n expected: string | readonly string[] | RegExp,\n): boolean {\n const joinedCategory = category.join(\".\");\n if (expected instanceof RegExp) {\n return testRegExp(expected, joinedCategory);\n }\n if (typeof expected === \"string\") {\n return joinedCategory === expected;\n }\n const expectedCategory = parseCategory(expected);\n return category.length === expectedCategory.length &&\n category.every((part, index) => part === expectedCategory[index]);\n}\n\nfunction matchesCategoryPrefix(\n category: readonly string[],\n prefix: string | readonly string[],\n): boolean {\n const expectedPrefix = parseCategory(prefix);\n return expectedPrefix.length <= category.length &&\n expectedPrefix.every((part, index) => part === category[index]);\n}\n\nfunction parseCategory(\n category: string | readonly string[],\n): readonly string[] {\n if (typeof category !== \"string\") return category;\n return category === \"\" ? [] : category.split(\".\");\n}\n\nfunction matchesMessage(\n record: LogRecord,\n matcher: string | RegExp | ((record: LogRecord) => boolean),\n): boolean {\n if (typeof matcher === \"function\") return matcher(record);\n return matchesText(renderMessage(record), matcher);\n}\n\nfunction matchesText(text: string, matcher: string | RegExp): boolean {\n return typeof matcher === \"string\"\n ? text === matcher\n : testRegExp(matcher, text);\n}\n\nfunction matchesProperties(\n properties: Readonly<Record<string, unknown>> | null | undefined,\n record: LogRecord,\n matcher: Readonly<Record<string, unknown>> | PropertyMatcher,\n): boolean {\n const props: Readonly<Record<string, unknown>> = properties ?? {};\n if (typeof matcher === \"function\") return matcher(props, record);\n for (const key of Object.keys(matcher)) {\n if (!Object.prototype.hasOwnProperty.call(props, key)) return false;\n if (!matchesPropertyValue(props[key], matcher[key])) return false;\n }\n return true;\n}\n\nfunction matchesPropertyValue(actual: unknown, expected: unknown): boolean {\n if (actual instanceof Date && expected instanceof Date) {\n return Object.is(actual.getTime(), expected.getTime());\n }\n if (typeof actual === \"string\" && expected instanceof RegExp) {\n return testRegExp(expected, actual);\n }\n return Object.is(actual, expected);\n}\n\nfunction testRegExp(pattern: RegExp, text: string): boolean {\n if (!pattern.global && !pattern.sticky) {\n return pattern.test(text);\n }\n const clone = new RegExp(pattern.source, pattern.flags);\n return clone.test(text);\n}\n\nfunction renderRawMessage(rawMessage: string | TemplateStringsArray): string {\n return typeof rawMessage === \"string\" ? rawMessage : rawMessage.join(\"\");\n}\n\nfunction renderMessage(record: LogRecord): string {\n return messageFormatter(record).slice(0, -1);\n}\n\nfunction formatMatcher(match: LogRecordMatch): string {\n const lines: string[] = [];\n if (match.category != null) {\n lines.push(` category: ${formatCategoryMatcher(match.category)}`);\n }\n if (match.categoryPrefix != null) {\n lines.push(\n ` categoryPrefix: ${\n formatCategoryValue(parseCategory(match.categoryPrefix))\n }`,\n );\n }\n if (match.level != null) lines.push(` level: ${formatValue(match.level)}`);\n if (match.message != null) {\n lines.push(` message: ${formatMessageMatcher(match.message)}`);\n }\n if (match.rawMessage != null) {\n lines.push(` rawMessage: ${formatTextMatcher(match.rawMessage)}`);\n }\n if (match.properties != null) {\n lines.push(...formatPropertiesMatcher(match.properties));\n }\n if (match.predicate != null) lines.push(\" predicate: <predicate>\");\n return lines.length < 1 ? \" <any record>\" : lines.join(\"\\n\");\n}\n\nfunction formatCategoryMatcher(\n category: string | readonly string[] | RegExp,\n): string {\n return category instanceof RegExp\n ? String(category)\n : typeof category === \"string\"\n ? formatValue(category)\n : formatCategoryValue(category);\n}\n\nfunction formatCategoryValue(category: readonly string[]): string {\n return `[${category.map((part) => formatValue(part)).join(\", \")}]`;\n}\n\nfunction formatMessageMatcher(\n matcher: string | RegExp | ((record: LogRecord) => boolean),\n): string {\n return typeof matcher === \"function\" ? \"<predicate>\" : formatTextMatcher(\n matcher,\n );\n}\n\nfunction formatTextMatcher(matcher: string | RegExp): string {\n return typeof matcher === \"string\" ? formatValue(matcher) : String(matcher);\n}\n\nfunction formatPropertiesMatcher(\n matcher: Readonly<Record<string, unknown>> | PropertyMatcher,\n): string[] {\n if (typeof matcher === \"function\") return [\" properties: <predicate>\"];\n const lines = Object.keys(matcher).map((key) =>\n ` properties.${key}: ${formatPropertyValue(matcher, key)}`\n );\n return lines.length < 1 ? [\" properties: {}\"] : lines;\n}\n\nfunction formatRecords(records: readonly LogRecord[]): string {\n if (records.length < 1) return \" <none>\";\n const lines = records.slice(0, 3).map(formatRecord);\n if (records.length > 3) {\n lines.push(` ... ${records.length - 3} more`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction formatRecord(record: LogRecord): string {\n const category = formatCategory(record.category);\n return ` [${record.level}] ${category}: ${formatMessage(record)}${\n formatProperties(record.properties)\n }`;\n}\n\nfunction formatMessage(record: LogRecord): string {\n try {\n return renderMessage(record);\n } catch (error) {\n return formatAccessError(error);\n }\n}\n\nfunction formatCategory(category: readonly string[]): string {\n return category.length < 1 ? \"<root>\" : category.join(\".\");\n}\n\nfunction formatProperties(\n properties: Readonly<Record<string, unknown>> | null | undefined,\n): string {\n const props: Readonly<Record<string, unknown>> = properties ?? {};\n const entries = Object.keys(props);\n if (entries.length < 1) return \"\";\n const summary = entries.slice(0, 3).map((key) =>\n `${key}: ${formatPropertyValue(props, key)}`\n );\n if (entries.length > 3) summary.push(`... ${entries.length - 3} more`);\n return ` {${summary.join(\", \")}}`;\n}\n\nfunction formatPropertyValue(\n properties: Readonly<Record<string, unknown>>,\n key: string,\n): string {\n try {\n return formatValue(properties[key]);\n } catch (error) {\n return formatAccessError(error);\n }\n}\n\nfunction formatAccessError(error: unknown): string {\n return `<error: ${\n error instanceof Error ? error.message : safeString(error)\n }>`;\n}\n\nfunction formatCount(count: number, noun: string): string {\n return `${count} ${noun}${count === 1 ? \"\" : \"s\"}`;\n}\n\nfunction formatValue(value: unknown): string {\n if (typeof value === \"string\") return JSON.stringify(value);\n if (typeof value === \"number\" && !Number.isFinite(value)) {\n return String(value);\n }\n if (typeof value === \"bigint\") return `${value}n`;\n if (typeof value === \"symbol\") return String(value);\n if (value instanceof RegExp) return String(value);\n if (value instanceof Error) {\n return `${value.name}: ${value.message}`;\n }\n if (value instanceof Map) return formatMap(value);\n if (value instanceof Set) return formatSet(value);\n try {\n return safeJsonStringify(value) ?? safeString(value);\n } catch {\n return safeString(value);\n }\n}\n\nfunction formatMap(value: ReadonlyMap<unknown, unknown>): string {\n const label = `Map(${value.size})`;\n try {\n const contents = formatMapContents(value);\n return `${label} ${safeJsonStringify(contents) ?? safeString(contents)}`;\n } catch {\n return label;\n }\n}\n\nfunction formatSet(value: ReadonlySet<unknown>): string {\n const label = `Set(${value.size})`;\n try {\n const contents = Array.from(value);\n return `${label} ${safeJsonStringify(contents) ?? safeString(contents)}`;\n } catch {\n return label;\n }\n}\n\nfunction safeJsonStringify(value: unknown): string | undefined {\n const ancestors: object[] = [];\n return JSON.stringify(value, function (\n this: unknown,\n _key: string,\n item: unknown,\n ): unknown {\n if (typeof item === \"bigint\") return `${item}n`;\n if (item instanceof RegExp) return String(item);\n if (item instanceof Error) return `${item.name}: ${item.message}`;\n if (typeof item === \"object\" && item != null) {\n while (\n ancestors.length > 0 &&\n ancestors[ancestors.length - 1] !== this\n ) {\n ancestors.pop();\n }\n if (ancestors.includes(item)) return \"[Circular]\";\n ancestors.push(item);\n if (item instanceof Map) return formatMapContents(item);\n if (item instanceof Set) return Array.from(item);\n }\n return item;\n });\n}\n\nfunction formatMapContents(\n value: ReadonlyMap<unknown, unknown>,\n): Readonly<Record<string, unknown>> | readonly (readonly [string, unknown])[] {\n const entries = Array.from(\n value,\n ([key, entryValue]) => [safeString(key), entryValue] as const,\n );\n const keys = entries.map(([key]) => key);\n const uniqueKeys = new Set(keys);\n return uniqueKeys.size === keys.length\n ? Object.fromEntries(entries)\n : entries;\n}\n\nfunction safeString(value: unknown): string {\n try {\n return String(value);\n } catch {\n return Object.prototype.toString.call(value);\n }\n}\n"],"mappings":";;;;AAUA,MAAMA,mBAAkC,iBAAiB;CACvD,QAAQ,CAAC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