@brillout/test-e2e 0.6.0 → 0.6.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/dist/Logs.d.ts CHANGED
@@ -25,6 +25,14 @@ declare function add({ logSource, logText, loggedAfterExit, }: {
25
25
  logText: string;
26
26
  loggedAfterExit?: boolean;
27
27
  }): void;
28
- declare function expectLog(logText: string, { filter: logFilter }?: {
28
+ /**
29
+ * Expect a log to be printed.
30
+ *
31
+ * @param filter Only search in certain types of logs, e.g. only in browser- or server-side logs.
32
+ *
33
+ * @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.
34
+ */
35
+ declare function expectLog(logText: string, { filter: logFilter, allLogs }?: {
29
36
  filter?: (logEntry: LogEntry) => boolean;
37
+ allLogs?: boolean;
30
38
  }): void;
package/dist/Logs.js CHANGED
@@ -14,6 +14,7 @@ import { logSection } from './logSection.js';
14
14
  import { isTolerateError } from './Logs/isTolerateError.js';
15
15
  import stripAnsi from 'strip-ansi';
16
16
  let logEntries = [];
17
+ const logEntriesAll = [];
17
18
  function hasFailLogs(failOnWarning) {
18
19
  const failLogs = getErrorLogs(failOnWarning);
19
20
  return failLogs.length > 0;
@@ -66,6 +67,7 @@ function add({ logSource, logText, loggedAfterExit = false, }) {
66
67
  loggedAfterExit,
67
68
  };
68
69
  logEntries.push(logEntry);
70
+ logEntriesAll.push(logEntry);
69
71
  if (Logs.logEagerly) {
70
72
  let shouldLog = false;
71
73
  if (Logs.logEagerly === 'all')
@@ -76,8 +78,16 @@ function add({ logSource, logText, loggedAfterExit = false, }) {
76
78
  printLog(logEntry);
77
79
  }
78
80
  }
79
- function expectLog(logText, { filter: logFilter } = {}) {
80
- let logsFound = logEntries.filter((logEntry) => {
81
+ /**
82
+ * Expect a log to be printed.
83
+ *
84
+ * @param filter Only search in certain types of logs, e.g. only in browser- or server-side logs.
85
+ *
86
+ * @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.
87
+ */
88
+ function expectLog(logText, { filter: logFilter, allLogs } = {}) {
89
+ const logList = allLogs ? logEntriesAll : logEntries;
90
+ const logsFound = logList.filter((logEntry) => {
81
91
  if (removeAnsi(logEntry).logText.includes(logText)) {
82
92
  logEntry.isNotFailure = true;
83
93
  return true;
@@ -89,9 +99,10 @@ function expectLog(logText, { filter: logFilter } = {}) {
89
99
  }
90
100
  if (!logFilter)
91
101
  return;
92
- logsFound = logsFound.filter((logEntry) => logFilter(removeAnsi(logEntry)));
93
- if (logsFound.length === 0) {
94
- throw new Error(`The following log was logged as expected, but it didn't match the logFilter() you provided: "${logText}"`);
102
+ const logsFoundAfterFilter = logsFound.filter((logEntry) => logFilter(removeAnsi(logEntry)));
103
+ if (logsFoundAfterFilter.length === 0) {
104
+ console.log(JSON.stringify(logsFound, null, 2));
105
+ throw new Error(`Logs above are matching "${logText}" but don't match the filter you provided.`);
95
106
  }
96
107
  }
97
108
  function removeAnsi(logEntry) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",