@brillout/test-e2e 0.3.6 → 0.3.8

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
@@ -2,6 +2,7 @@ export { expectError };
2
2
  export declare const Logs: {
3
3
  add: typeof add;
4
4
  flushLogs: typeof flushLogs;
5
+ logErrors: typeof logErrors;
5
6
  clearLogs: typeof clearLogs;
6
7
  hasErrorLogs: typeof hasErrorLogs;
7
8
  flushEagerly: boolean;
@@ -13,8 +14,9 @@ declare type LogEntry = {
13
14
  logTimestamp: string;
14
15
  isNotFailure: boolean;
15
16
  };
16
- declare function hasErrorLogs(doNotFailOnWarning?: boolean): boolean;
17
+ declare function hasErrorLogs(treatWarningAsError: boolean): boolean;
17
18
  declare function clearLogs(): void;
19
+ declare function logErrors(treatWarningAsError: boolean): void;
18
20
  declare function flushLogs(): void;
19
21
  declare function add({ logSource, logText }: {
20
22
  logSource: LogSource;
package/dist/Logs.js CHANGED
@@ -7,6 +7,7 @@ exports.Logs = exports.expectError = void 0;
7
7
  exports.Logs = {
8
8
  add,
9
9
  flushLogs,
10
+ logErrors,
10
11
  clearLogs,
11
12
  hasErrorLogs,
12
13
  flushEagerly: false,
@@ -16,15 +17,19 @@ const picocolors_1 = __importDefault(require("picocolors"));
16
17
  const getCurrentTest_1 = require("./getCurrentTest");
17
18
  const getConfig_1 = require("./getConfig");
18
19
  let logEntries = [];
19
- function hasErrorLogs(doNotFailOnWarning = false) {
20
- const logErrors = logEntries.filter(({ logSource, isNotFailure }) => {
20
+ function hasErrorLogs(treatWarningAsError) {
21
+ const errorLogs = getErrorLogs(treatWarningAsError);
22
+ return errorLogs.length > 0;
23
+ }
24
+ function getErrorLogs(treatWarningAsError) {
25
+ const errorLogs = logEntries.filter(({ logSource, isNotFailure }) => {
21
26
  if (isNotFailure) {
22
27
  return;
23
28
  }
24
29
  if (logSource === 'run() failure') {
25
30
  return true;
26
31
  }
27
- if (!doNotFailOnWarning && (logSource === 'Browser Warning' || logSource === 'stderr')) {
32
+ if (treatWarningAsError && (logSource === 'Browser Warning' || logSource === 'stderr')) {
28
33
  return true;
29
34
  }
30
35
  if (logSource === 'Browser Error') {
@@ -32,11 +37,15 @@ function hasErrorLogs(doNotFailOnWarning = false) {
32
37
  }
33
38
  return false;
34
39
  });
35
- return logErrors.length > 0;
40
+ return errorLogs;
36
41
  }
37
42
  function clearLogs() {
38
43
  logEntries = [];
39
44
  }
45
+ function logErrors(treatWarningAsError) {
46
+ const errorLogs = getErrorLogs(treatWarningAsError);
47
+ errorLogs.forEach((logEntry) => printLog(logEntry));
48
+ }
40
49
  function flushLogs() {
41
50
  logEntries.forEach((logEntry) => printLog(logEntry));
42
51
  logEntries = [];
package/dist/runTests.js CHANGED
@@ -8,7 +8,6 @@ const getCurrentTest_1 = require("./getCurrentTest");
8
8
  const Logs_1 = require("./Logs");
9
9
  const utils_1 = require("./utils");
10
10
  const picocolors_1 = __importDefault(require("picocolors"));
11
- const logsContainError_errMsg = (isTermination) => [picocolors_1.default.bold('Encountered an error or warning'), !isTermination ? '' : ' during termination', ', see logs below.'].join('');
12
11
  async function runTests(browser) {
13
12
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
14
13
  if (utils_1.isTTY) {
@@ -56,7 +55,8 @@ async function runTests(browser) {
56
55
  }
57
56
  done(!!err);
58
57
  testInfo.afterEach(!!err);
59
- const hasErrorLog = Logs_1.Logs.hasErrorLogs(testInfo.runInfo.doNotFailOnWarning);
58
+ const { doNotFailOnWarning } = testInfo.runInfo;
59
+ const hasErrorLog = Logs_1.Logs.hasErrorLogs(!doNotFailOnWarning);
60
60
  const isFailure = err || hasErrorLog;
61
61
  if (isFailure) {
62
62
  logTestsResult(false);
@@ -64,7 +64,10 @@ async function runTests(browser) {
64
64
  console.error(err);
65
65
  }
66
66
  if (hasErrorLog) {
67
- console.log(logsContainError_errMsg(false));
67
+ logIsFailure(false, !doNotFailOnWarning);
68
+ console.log(picocolors_1.default.bold('vvvv FAIL LOGS vvvv'));
69
+ Logs_1.Logs.logErrors(!doNotFailOnWarning);
70
+ console.log(picocolors_1.default.bold('vvvv ALL LOGS vvvv'));
68
71
  }
69
72
  Logs_1.Logs.flushLogs();
70
73
  process.exit(1);
@@ -76,13 +79,13 @@ async function runTests(browser) {
76
79
  await testInfo.terminateServer();
77
80
  await page.close();
78
81
  // Handle case that an error occured during `terminateServer()`
79
- if (Logs_1.Logs.hasErrorLogs()) {
82
+ if (Logs_1.Logs.hasErrorLogs(true)) {
80
83
  if ((0, utils_1.isWindows)()) {
81
84
  // On Windows, the sever sometimes terminates with an exit code of `1`. I don't know why.
82
85
  Logs_1.Logs.clearLogs();
83
86
  }
84
87
  else {
85
- console.log(logsContainError_errMsg(true));
88
+ logIsFailure(true, false);
86
89
  Logs_1.Logs.flushLogs();
87
90
  process.exit(1);
88
91
  }
@@ -132,3 +135,11 @@ function logTestsResult(success) {
132
135
  console.log(`${failStyle(' FAIL ')} ${testInfo.testFile}`);
133
136
  }
134
137
  }
138
+ function logIsFailure(isTermination, canBeAWarning) {
139
+ console.log(picocolors_1.default.red(picocolors_1.default.bold([
140
+ 'Test FAIL because encountered an error',
141
+ !canBeAWarning ? '' : ' or warning',
142
+ !isTermination ? '' : ' during termination',
143
+ ', see logs below.',
144
+ ].join(''))));
145
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {