@brillout/test-e2e 0.6.18 → 0.6.20

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.
Files changed (3) hide show
  1. package/dist/Logs.js +30 -25
  2. package/dist/run.js +23 -17
  3. package/package.json +1 -1
package/dist/Logs.js CHANGED
@@ -20,31 +20,32 @@ function hasFailureLog({ includeBrowserWarnings, includeStderr, }) {
20
20
  return failLogs.length > 0;
21
21
  }
22
22
  function getErrorLogs({ includeBrowserWarnings, includeStderr, }) {
23
- const errorLogs = logEntries.filter((logEntry) => {
24
- if (logEntry.isNotFailure) {
25
- return false;
26
- }
27
- const { logSource } = logEntry;
28
- // taskkill makes process exit with exit code `1` which makes npm emit logs on stderr
29
- if (logEntry.loggedAfterExit && isWindows() && logSource === 'stderr') {
30
- return false;
31
- }
32
- if (logSource === 'run() failure') {
33
- return true;
34
- }
35
- if (logSource === 'Browser Warning' && includeBrowserWarnings) {
36
- return true;
37
- }
38
- if (logSource === 'stderr' && includeStderr) {
39
- return true;
40
- }
41
- if (logSource === 'Browser Error') {
42
- return true;
43
- }
44
- return false;
45
- });
23
+ const errorLogs = logEntries.filter((logEntry) => isErrorLog(logEntry, { includeBrowserWarnings, includeStderr }));
46
24
  return errorLogs;
47
25
  }
26
+ function isErrorLog(logEntry, { includeBrowserWarnings = true, includeStderr = true, } = {}) {
27
+ if (logEntry.isNotFailure) {
28
+ return false;
29
+ }
30
+ const { logSource } = logEntry;
31
+ // taskkill makes process exit with exit code `1` which makes npm emit logs on stderr
32
+ if (logEntry.loggedAfterExit && isWindows() && logSource === 'stderr') {
33
+ return false;
34
+ }
35
+ if (logSource === 'run() failure') {
36
+ return true;
37
+ }
38
+ if (logSource === 'Browser Warning' && includeBrowserWarnings) {
39
+ return true;
40
+ }
41
+ if (logSource === 'stderr' && includeStderr) {
42
+ return true;
43
+ }
44
+ if (logSource === 'Browser Error') {
45
+ return true;
46
+ }
47
+ return false;
48
+ }
48
49
  function clearLogs() {
49
50
  logEntries = [];
50
51
  }
@@ -153,24 +154,28 @@ function getTimestamp() {
153
154
  return timestamp;
154
155
  }
155
156
  function printLog(logEntry) {
156
- const { logSource, logText, logTimestamp } = logEntry;
157
- let logSourceLabel = colorize(logSource);
157
+ const { logSource, logText, logTimestamp, logInfo } = logEntry;
158
158
  const testInfo = getCurrentTestOptional();
159
159
  // See https://github.com/nodejs/node/issues/8033#issuecomment-388323687
160
160
  if (!ensureNewTerminalLine()) {
161
161
  console.log('');
162
162
  }
163
+ // msg
163
164
  let msg = logText;
164
165
  // I don't know why but sometimes `logText` is `undefined`
165
166
  if (msg === undefined)
166
167
  msg = '';
167
168
  // Some logs seem have a trailing new line
168
169
  msg = msg.trim();
170
+ if (logInfo && isErrorLog(logEntry))
171
+ msg += '\n' + logInfo.trim();
172
+ // testInfoLabels
169
173
  let testInfoLabels = '';
170
174
  if (testInfo) {
171
175
  assert(testInfo.runInfo, testInfo);
172
176
  testInfoLabels = `[${testInfo.testName}][${testInfo.runInfo.cmd}]`;
173
177
  }
178
+ const logSourceLabel = colorize(logSource);
174
179
  console.log(`[${logTimestamp}]${testInfoLabels}[${logSourceLabel}] ${msg}`);
175
180
  }
176
181
  function colorize(logSource) {
package/dist/run.js CHANGED
@@ -71,30 +71,36 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
71
71
  // Also called when the page throws an error or a warning
72
72
  function onConsole(msg) {
73
73
  const type = msg.type();
74
+ let showType = false;
75
+ const logSource = (() => {
76
+ if (type === 'error') {
77
+ return 'Browser Error';
78
+ }
79
+ if (type === 'warning') {
80
+ return 'Browser Warning';
81
+ }
82
+ showType = true;
83
+ return 'Browser Log';
84
+ })();
85
+ const logInfo = {
86
+ location: msg.location(),
87
+ args: msg.args(),
88
+ };
89
+ if (showType)
90
+ Object.assign(logInfo, { type });
74
91
  Logs.add({
75
- logSource: (() => {
76
- if (type === 'error') {
77
- return 'Browser Error';
78
- }
79
- if (type === 'warning') {
80
- return 'Browser Warning';
81
- }
82
- return 'Browser Log';
83
- })(),
92
+ logSource,
84
93
  logText: msg.text(),
85
- logInfo: JSON.stringify({
86
- type,
87
- location: msg.location(),
88
- args: msg.args(),
89
- }, null, 2),
94
+ logInfo: JSON.stringify(logInfo, null, 2),
90
95
  });
91
96
  }
92
97
  // For uncaught exceptions
93
98
  function onPageError(err) {
99
+ const logText = err.stack || err.message;
100
+ assert(logText.includes(err.message));
94
101
  Logs.add({
95
102
  logSource: 'Browser Error',
96
- logText: err.stack || err.message,
97
- logInfo: JSON.stringify({ errorMessage: err.message }, null, 2),
103
+ logText,
98
104
  });
99
105
  }
100
106
  }
@@ -108,7 +114,7 @@ async function startProcess({ serverIsReadyMessage, serverIsReadyDelay, addition
108
114
  // npm package `serve`
109
115
  log.includes('Accepting connections at') ||
110
116
  // Vite
111
- (log.includes('Local:') && log.includes('http://localhost:3000/'));
117
+ (log.includes('Local:') && log.includes('http://localhost:3000'));
112
118
  return serverIsReady;
113
119
  };
114
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.6.18",
3
+ "version": "0.6.20",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",