@brillout/test-e2e 0.4.5 → 0.4.7

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
@@ -5,7 +5,7 @@ export declare const Logs: {
5
5
  logErrors: typeof logErrors;
6
6
  clearLogs: typeof clearLogs;
7
7
  hasErrorLogs: typeof hasErrorLogs;
8
- flushEagerly: boolean;
8
+ logEagerly: boolean;
9
9
  };
10
10
  declare type LogSource = 'stdout' | 'stderr' | 'Browser Error' | 'Browser Warning' | 'Browser Log' | 'Playwright' | 'run()' | 'run() failure' | 'test()' | 'Connection Error';
11
11
  declare type LogEntry = {
package/dist/Logs.js CHANGED
@@ -10,7 +10,7 @@ exports.Logs = {
10
10
  logErrors,
11
11
  clearLogs,
12
12
  hasErrorLogs,
13
- flushEagerly: false,
13
+ logEagerly: false,
14
14
  };
15
15
  const utils_1 = require("./utils");
16
16
  const picocolors_1 = __importDefault(require("picocolors"));
@@ -74,8 +74,8 @@ function add({ logSource, logText }) {
74
74
  isNotFailure,
75
75
  };
76
76
  logEntries.push(logEntry);
77
- if (exports.Logs.flushEagerly) {
78
- flushLogs();
77
+ if (exports.Logs.logEagerly) {
78
+ printLog(logEntry);
79
79
  }
80
80
  }
81
81
  function expectError(logFilter) {
@@ -0,0 +1,2 @@
1
+ export { logError };
2
+ declare function logError(err: unknown, sectionTitle?: string): void;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logError = void 0;
4
+ const logSection_1 = require("./logSection");
5
+ function logError(err, sectionTitle = 'ERROR') {
6
+ (0, logSection_1.logSection)(sectionTitle);
7
+ console.log(err);
8
+ }
9
+ exports.logError = logError;
@@ -1,3 +1,5 @@
1
1
  export { runTests };
2
+ export { logFailure };
2
3
  import { type FindFilter } from './utils';
3
4
  declare function runTests(filter: null | FindFilter): Promise<void>;
5
+ declare function logFailure(reason: string): void;
package/dist/runTests.js CHANGED
@@ -3,19 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runTests = void 0;
6
+ exports.logFailure = exports.runTests = void 0;
7
7
  const getCurrentTest_1 = require("./getCurrentTest");
8
8
  const Logs_1 = require("./Logs");
9
9
  const utils_1 = require("./utils");
10
10
  const utils_2 = require("./utils");
11
11
  const picocolors_1 = __importDefault(require("picocolors"));
12
12
  const github_action_1 = require("./github-action");
13
- const logSection_1 = require("./logSection");
14
13
  const getCurrentTest_2 = require("./getCurrentTest");
15
14
  const getBrowser_1 = require("./getBrowser");
16
15
  const buildTs_1 = require("./buildTs");
17
16
  const findTestFiles_1 = require("./findTestFiles");
18
17
  const getConfig_1 = require("./getConfig");
18
+ const logError_1 = require("./logError");
19
19
  async function runTests(filter) {
20
20
  await (0, getConfig_1.loadConfig)();
21
21
  const testFiles = await (0, findTestFiles_1.findTestFiles)(filter);
@@ -48,7 +48,7 @@ async function runTestFile(browser) {
48
48
  testInfo.page = page;
49
49
  // Set when user calls `skip()`
50
50
  if (testInfo.skipped) {
51
- logResult(false);
51
+ logTestStatus(false);
52
52
  (0, utils_1.assertUsage)(!testInfo.runInfo, 'You cannot call `run()` after calling `skip()`');
53
53
  (0, utils_1.assertUsage)(testInfo.tests === undefined, 'You cannot call `test()` after calling `skip()`');
54
54
  return;
@@ -73,8 +73,8 @@ async function runTestFile(browser) {
73
73
  await testInfo.startServer();
74
74
  }
75
75
  catch (err) {
76
- logFailureReason('an error occurred while starting the server');
77
- logError(err);
76
+ logFailure('an error occurred while starting the server');
77
+ (0, logError_1.logError)(err);
78
78
  Logs_1.Logs.flushLogs();
79
79
  await abort();
80
80
  return;
@@ -100,11 +100,11 @@ async function runTestFile(browser) {
100
100
  const isFailure = err || hasErrorLog;
101
101
  if (isFailure) {
102
102
  if (err) {
103
- logFailureReason(`the test "${testDesc}" threw an error`);
104
- logError(err);
103
+ logFailure(`the test "${testDesc}" threw an error`);
104
+ (0, logError_1.logError)(err);
105
105
  }
106
106
  else if (hasErrorLog) {
107
- logFailureReason(`${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`);
107
+ logFailure(`${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`);
108
108
  }
109
109
  else {
110
110
  (0, utils_1.assert)(false);
@@ -124,7 +124,7 @@ async function runTestFile(browser) {
124
124
  if (Logs_1.Logs.hasErrorLogs(failOnWarning) &&
125
125
  // See comments about taskkill in src/setup.ts
126
126
  !(0, utils_1.isWindows)()) {
127
- logFailureReason(`${getErrorType(failOnWarning)} occurred during server termination`);
127
+ logFailure(`${getErrorType(failOnWarning)} occurred during server termination`);
128
128
  Logs_1.Logs.logErrors(failOnWarning);
129
129
  Logs_1.Logs.flushLogs();
130
130
  await abort();
@@ -132,7 +132,7 @@ async function runTestFile(browser) {
132
132
  }
133
133
  }
134
134
  Logs_1.Logs.clearLogs();
135
- logResult(true);
135
+ logTestStatus(true);
136
136
  }
137
137
  function getErrorType(failOnWarning) {
138
138
  return !failOnWarning ? 'error(s)' : 'error(s)/warning(s)';
@@ -162,7 +162,7 @@ function runTest(testFn, testFunctionTimeout) {
162
162
  })();
163
163
  return promise;
164
164
  }
165
- function logResult(success) {
165
+ function logTestStatus(success) {
166
166
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
167
167
  const { PASS, FAIL, WARN } = getStatusTags();
168
168
  if (success) {
@@ -177,17 +177,14 @@ function logResult(success) {
177
177
  console.log(`${FAIL} ${testInfo.testFile}`);
178
178
  }
179
179
  }
180
- function logFailureReason(reason) {
181
- logResult(false);
180
+ function logFailure(reason) {
181
+ logTestStatus(false);
182
182
  const { FAIL } = getStatusTags();
183
183
  const color = (s) => picocolors_1.default.red(picocolors_1.default.bold(s));
184
184
  const msg = `Test ${FAIL} because ${reason}, see below.`;
185
185
  console.log(color(msg));
186
186
  }
187
- function logError(err) {
188
- (0, logSection_1.logSection)('ERROR');
189
- console.log(err);
190
- }
187
+ exports.logFailure = logFailure;
191
188
  function getStatusTags() {
192
189
  const PASS = picocolors_1.default.bold(picocolors_1.default.bgGreen(picocolors_1.default.white(' PASS ')));
193
190
  const FAIL = picocolors_1.default.bold(picocolors_1.default.bgRed(picocolors_1.default.white(' FAIL ')));
package/dist/setup.js CHANGED
@@ -51,7 +51,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
51
51
  serverUrl,
52
52
  };
53
53
  if (inspect) {
54
- Logs_1.Logs.flushEagerly = true;
54
+ Logs_1.Logs.logEagerly = true;
55
55
  }
56
56
  let runProcess = null;
57
57
  testInfo.startServer = async () => {
@@ -362,10 +362,10 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
362
362
  function assertNotExited(data) {
363
363
  if (!procExited)
364
364
  return;
365
- Logs_1.Logs.logErrors(true);
366
- Logs_1.Logs.flushLogs();
367
- logDebugInfo(data);
368
- (0, utils_2.assert)(false);
365
+ // Sometimes, a single white space is emitted after 'exit' has been emitted.
366
+ if (data.trim().length === 0)
367
+ return;
368
+ (0, utils_2.assert)(false, { data: data, dataLength: data.length });
369
369
  }
370
370
  function processHasExited() {
371
371
  return procExited;
@@ -493,15 +493,3 @@ function getPort() {
493
493
  (0, utils_2.assert)(/\d+/.test(port), { serverUrl });
494
494
  return port;
495
495
  }
496
- function logDebugInfo(data) {
497
- console.log('vvvvv DEBUG INFO vvvvv');
498
- const testInfo = (0, getCurrentTest_1.getCurrentTest)();
499
- console.log('testInfo.hasStartedRunning', testInfo.hasStartedRunning);
500
- console.log('testInfo.skipped', testInfo.skipped);
501
- console.log('testInfo.runInfo', testInfo.runInfo);
502
- console.log('testInfo.testFile', testInfo.testFile);
503
- console.log('testInfo.testName', testInfo.testName);
504
- console.log('data', data);
505
- console.log('process.platform', process.platform);
506
- console.log('^^^^^ DEBUG INFO ^^^^^');
507
- }
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.projectErrorPrefix = exports.getProjectError = exports.assertInfo = exports.assertWarning = exports.assertUsage = exports.assert = void 0;
4
+ const runTests_1 = require("../runTests");
4
5
  const createErrorWithCleanStackTrace_1 = require("./createErrorWithCleanStackTrace");
5
6
  const projectInfo_1 = require("./projectInfo");
7
+ const Logs_1 = require("../Logs");
8
+ const getCurrentTest_1 = require("../getCurrentTest");
9
+ const logSection_1 = require("../logSection");
10
+ const logError_1 = require("../logError");
6
11
  const errorPrefix = `[${projectInfo_1.projectInfo.npmPackageName}]`;
7
12
  exports.projectErrorPrefix = errorPrefix;
8
13
  const internalErrorPrefix = `${errorPrefix}[Bug]`;
@@ -28,7 +33,12 @@ function assert(condition, debugInfo) {
28
33
  `Do not hesitate to reach out as it makes ${projectInfo_1.projectInfo.projectName} more robust.`,
29
34
  debugStr,
30
35
  ].join(' '), numberOfStackTraceLinesToRemove);
31
- throw internalError;
36
+ (0, runTests_1.logFailure)('a bug occurred in @brillout/test-e2e');
37
+ (0, logError_1.logError)(internalError, 'BUG');
38
+ logDebugInfo();
39
+ Logs_1.Logs.logErrors(true);
40
+ Logs_1.Logs.flushLogs();
41
+ throw new Error('Bug. See messages above.');
32
42
  }
33
43
  exports.assert = assert;
34
44
  function assertUsage(condition, errorMessage) {
@@ -70,3 +80,13 @@ function assertInfo(condition, errorMessage) {
70
80
  console.warn(`${infoPrefix} ${errorMessage}`);
71
81
  }
72
82
  exports.assertInfo = assertInfo;
83
+ function logDebugInfo() {
84
+ (0, logSection_1.logSection)('DEBUG INFO');
85
+ const testInfo = (0, getCurrentTest_1.getCurrentTest)();
86
+ console.log('testInfo.hasStartedRunning', testInfo.hasStartedRunning);
87
+ console.log('testInfo.skipped', testInfo.skipped);
88
+ console.log('testInfo.runInfo', testInfo.runInfo);
89
+ console.log('testInfo.testFile', testInfo.testFile);
90
+ console.log('testInfo.testName', testInfo.testName);
91
+ console.log('process.platform', process.platform);
92
+ }
@@ -4,5 +4,6 @@ exports.cliConfig = void 0;
4
4
  const cliArgs = process.argv.slice(2);
5
5
  exports.cliConfig = {
6
6
  debugEsbuild: cliArgs.includes('--debug-esbuild'),
7
- inspect: cliArgs.includes('--inspect'),
7
+ // To inspect a specific test: `$ touch examples/some-example/INSPECT`
8
+ inspect: cliArgs.includes('--inspect') || !!process.env.TEST_INSPECT,
8
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {