@brillout/test-e2e 0.4.6 → 0.4.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/logError.d.ts +2 -0
- package/dist/logError.js +9 -0
- package/dist/runTests.d.ts +2 -0
- package/dist/runTests.js +14 -17
- package/dist/setup.js +10 -22
- package/dist/utils/assert.js +26 -8
- package/package.json +1 -1
- package/dist/utils/createErrorWithCleanStackTrace.d.ts +0 -2
- package/dist/utils/createErrorWithCleanStackTrace.js +0 -43
package/dist/logError.js
ADDED
|
@@ -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;
|
package/dist/runTests.d.ts
CHANGED
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
181
|
-
|
|
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
|
-
|
|
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
|
@@ -314,7 +314,7 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
|
|
|
314
314
|
});
|
|
315
315
|
proc.stdout.on('data', (chunk) => {
|
|
316
316
|
const data = String(chunk);
|
|
317
|
-
assertNotExited(data)
|
|
317
|
+
// assertNotExited(data)
|
|
318
318
|
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
319
319
|
Logs_1.Logs.add({
|
|
320
320
|
logSource: 'stdout',
|
|
@@ -324,7 +324,7 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
|
|
|
324
324
|
});
|
|
325
325
|
proc.stderr.on('data', async (chunk) => {
|
|
326
326
|
const data = String(chunk);
|
|
327
|
-
assertNotExited(data)
|
|
327
|
+
// assertNotExited(data)
|
|
328
328
|
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
329
329
|
Logs_1.Logs.add({
|
|
330
330
|
logSource: 'stderr',
|
|
@@ -359,14 +359,15 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
|
|
|
359
359
|
exitPromiseResolve();
|
|
360
360
|
});
|
|
361
361
|
return { terminate, processHasExited };
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
362
|
+
/* Node.js seems to occasionally emit 'data' events after having the emitted 'exit' event, for example:
|
|
363
|
+
* - `{"data":"[0] npm run serve:cdn exited with code SIGTERM\n","dataLength":48}`.
|
|
364
|
+
function assertNotExited(data: string) {
|
|
365
|
+
if (!procExited) return
|
|
366
|
+
// Sometimes, a single white space is emitted after 'exit' has been emitted.
|
|
367
|
+
if (data.trim().length === 0) return
|
|
368
|
+
assert(false, { data, dataLength: data.length })
|
|
369
369
|
}
|
|
370
|
+
*/
|
|
370
371
|
function processHasExited() {
|
|
371
372
|
return procExited;
|
|
372
373
|
}
|
|
@@ -493,16 +494,3 @@ function getPort() {
|
|
|
493
494
|
(0, utils_2.assert)(/\d+/.test(port), { serverUrl });
|
|
494
495
|
return port;
|
|
495
496
|
}
|
|
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('data.length', data.length);
|
|
506
|
-
console.log('process.platform', process.platform);
|
|
507
|
-
console.log('^^^^^ DEBUG INFO ^^^^^');
|
|
508
|
-
}
|
package/dist/utils/assert.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
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
|
|
4
|
+
const runTests_1 = require("../runTests");
|
|
5
5
|
const projectInfo_1 = require("./projectInfo");
|
|
6
|
+
const Logs_1 = require("../Logs");
|
|
7
|
+
const getCurrentTest_1 = require("../getCurrentTest");
|
|
8
|
+
const logSection_1 = require("../logSection");
|
|
9
|
+
const logError_1 = require("../logError");
|
|
6
10
|
const errorPrefix = `[${projectInfo_1.projectInfo.npmPackageName}]`;
|
|
7
11
|
exports.projectErrorPrefix = errorPrefix;
|
|
8
12
|
const internalErrorPrefix = `${errorPrefix}[Bug]`;
|
|
@@ -21,14 +25,19 @@ function assert(condition, debugInfo) {
|
|
|
21
25
|
const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : '`' + JSON.stringify(debugInfo) + '`';
|
|
22
26
|
return `Debug info (this is for the ${projectInfo_1.projectInfo.projectName} maintainers; you can ignore this): ${debugInfoSerialized}.`;
|
|
23
27
|
})();
|
|
24
|
-
const internalError =
|
|
28
|
+
const internalError = new Error([
|
|
25
29
|
`${internalErrorPrefix} You stumbled upon a bug in ${projectInfo_1.projectInfo.projectName}'s source code.`,
|
|
26
30
|
`Reach out at ${projectInfo_1.projectInfo.githubRepository}/issues/new and include this error stack (the error stack is usually enough to fix the problem).`,
|
|
27
31
|
'A maintainer will fix the bug (usually under 24 hours).',
|
|
28
32
|
`Do not hesitate to reach out as it makes ${projectInfo_1.projectInfo.projectName} more robust.`,
|
|
29
33
|
debugStr,
|
|
30
|
-
].join(' ')
|
|
31
|
-
|
|
34
|
+
].join(' '));
|
|
35
|
+
(0, runTests_1.logFailure)('a bug occurred in @brillout/test-e2e');
|
|
36
|
+
(0, logError_1.logError)(internalError, 'BUG');
|
|
37
|
+
logDebugInfo();
|
|
38
|
+
Logs_1.Logs.logErrors(true);
|
|
39
|
+
Logs_1.Logs.flushLogs();
|
|
40
|
+
throw new Error('Bug. See messages above.');
|
|
32
41
|
}
|
|
33
42
|
exports.assert = assert;
|
|
34
43
|
function assertUsage(condition, errorMessage) {
|
|
@@ -36,13 +45,12 @@ function assertUsage(condition, errorMessage) {
|
|
|
36
45
|
return;
|
|
37
46
|
}
|
|
38
47
|
const whiteSpace = errorMessage.startsWith('[') ? '' : ' ';
|
|
39
|
-
|
|
40
|
-
throw usageError;
|
|
48
|
+
throw new Error(`${usageErrorPrefix}${whiteSpace}${errorMessage}`);
|
|
41
49
|
}
|
|
42
50
|
exports.assertUsage = assertUsage;
|
|
43
51
|
function getProjectError(errorMessage) {
|
|
44
|
-
const
|
|
45
|
-
return
|
|
52
|
+
const projectError = new Error(`${errorPrefix} ${errorMessage}`);
|
|
53
|
+
return projectError;
|
|
46
54
|
}
|
|
47
55
|
exports.getProjectError = getProjectError;
|
|
48
56
|
let loggedWarnings = new Set();
|
|
@@ -70,3 +78,13 @@ function assertInfo(condition, errorMessage) {
|
|
|
70
78
|
console.warn(`${infoPrefix} ${errorMessage}`);
|
|
71
79
|
}
|
|
72
80
|
exports.assertInfo = assertInfo;
|
|
81
|
+
function logDebugInfo() {
|
|
82
|
+
(0, logSection_1.logSection)('DEBUG INFO');
|
|
83
|
+
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
84
|
+
console.log('testInfo.hasStartedRunning', testInfo.hasStartedRunning);
|
|
85
|
+
console.log('testInfo.skipped', testInfo.skipped);
|
|
86
|
+
console.log('testInfo.runInfo', testInfo.runInfo);
|
|
87
|
+
console.log('testInfo.testFile', testInfo.testFile);
|
|
88
|
+
console.log('testInfo.testName', testInfo.testName);
|
|
89
|
+
console.log('process.platform', process.platform);
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createErrorWithCleanStackTrace = void 0;
|
|
4
|
-
function createErrorWithCleanStackTrace(errorMessage, numberOfStackTraceLinesToRemove) {
|
|
5
|
-
let err;
|
|
6
|
-
{
|
|
7
|
-
var stackTraceLimit__original = Error.stackTraceLimit;
|
|
8
|
-
Error.stackTraceLimit = Infinity;
|
|
9
|
-
err = new Error(errorMessage);
|
|
10
|
-
Error.stackTraceLimit = stackTraceLimit__original;
|
|
11
|
-
}
|
|
12
|
-
err.stack = clean(err.stack, numberOfStackTraceLinesToRemove);
|
|
13
|
-
return err;
|
|
14
|
-
}
|
|
15
|
-
exports.createErrorWithCleanStackTrace = createErrorWithCleanStackTrace;
|
|
16
|
-
function clean(errStack, numberOfStackTraceLinesToRemove) {
|
|
17
|
-
if (!errStack) {
|
|
18
|
-
return errStack;
|
|
19
|
-
}
|
|
20
|
-
const stackLines = splitByLine(errStack);
|
|
21
|
-
let linesRemoved = 0;
|
|
22
|
-
const stackLine__cleaned = stackLines
|
|
23
|
-
.filter((line) => {
|
|
24
|
-
// Remove internal stack traces
|
|
25
|
-
if (line.includes(' (internal/') || line.includes(' (node:internal')) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
if (linesRemoved < numberOfStackTraceLinesToRemove && isStackTraceLine(line)) {
|
|
29
|
-
linesRemoved++;
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
})
|
|
34
|
-
.join('\n');
|
|
35
|
-
return stackLine__cleaned;
|
|
36
|
-
}
|
|
37
|
-
function isStackTraceLine(line) {
|
|
38
|
-
return line.startsWith(' at ');
|
|
39
|
-
}
|
|
40
|
-
function splitByLine(str) {
|
|
41
|
-
// https://stackoverflow.com/questions/21895233/how-in-node-to-split-string-by-newline-n
|
|
42
|
-
return str.split(/\r?\n/);
|
|
43
|
-
}
|