@brillout/test-e2e 0.6.20 → 0.6.21

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/Logs.d.ts CHANGED
@@ -33,11 +33,13 @@ declare function add({ logSource, logText, logInfo, loggedAfterExit, }: {
33
33
  /**
34
34
  * Expect a log to be printed.
35
35
  *
36
+ * @param pattern String or RegExp to search for in logs.
37
+ *
36
38
  * @param filter Only search in certain types of logs, e.g. only in browser- or server-side logs.
37
39
  *
38
40
  * @param allLogs Search in all logs, including the logs of previous tests as well as the logs of the setup/prepare scripts. Usually used in combination with the `filter` parameter.
39
41
  */
40
- declare function expectLog(logText: string, { filter: logFilter, allLogs }?: {
42
+ declare function expectLog(pattern: string | RegExp, { filter: logFilter, allLogs }?: {
41
43
  filter?: (logEntry: LogEntry) => boolean;
42
44
  allLogs?: boolean;
43
45
  }): void;
package/dist/Logs.js CHANGED
@@ -115,28 +115,34 @@ async function terminateUponErrorLog(logSource) {
115
115
  /**
116
116
  * Expect a log to be printed.
117
117
  *
118
+ * @param pattern String or RegExp to search for in logs.
119
+ *
118
120
  * @param filter Only search in certain types of logs, e.g. only in browser- or server-side logs.
119
121
  *
120
122
  * @param allLogs Search in all logs, including the logs of previous tests as well as the logs of the setup/prepare scripts. Usually used in combination with the `filter` parameter.
121
123
  */
122
- function expectLog(logText, { filter: logFilter, allLogs } = {}) {
124
+ function expectLog(pattern, { filter: logFilter, allLogs } = {}) {
123
125
  const logList = allLogs ? logEntriesAll : logEntries;
126
+ const isRegex = pattern instanceof RegExp;
127
+ const patternStr = isRegex ? pattern.toString() : `"${pattern}"`;
124
128
  const logsFound = logList.filter((logEntry) => {
125
- if (removeAnsi(logEntry).logText.includes(logText)) {
129
+ const logText = removeAnsi(logEntry).logText;
130
+ const matches = isRegex ? pattern.test(logText) : logText.includes(pattern);
131
+ if (matches) {
126
132
  logEntry.isNotFailure = true;
127
133
  return true;
128
134
  }
129
135
  return false;
130
136
  });
131
137
  if (logsFound.length === 0) {
132
- throw new Error(`The following log is expected but it wasn't logged: "${logText}"`);
138
+ throw new Error(`The following log is expected but it wasn't logged: ${patternStr}`);
133
139
  }
134
140
  if (!logFilter)
135
141
  return;
136
142
  const logsFoundAfterFilter = logsFound.filter((logEntry) => logFilter(removeAnsi(logEntry)));
137
143
  if (logsFoundAfterFilter.length === 0) {
138
144
  console.log(JSON.stringify(logsFound, null, 2));
139
- throw new Error(`Logs above are matching "${logText}" but don't match the filter you provided.`);
145
+ throw new Error(`Logs above are matching ${patternStr} but don't match the filter you provided.`);
140
146
  }
141
147
  }
142
148
  function removeAnsi(logEntry) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.6.20",
3
+ "version": "0.6.21",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",