@brillout/test-e2e 0.2.2 → 0.3.1
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/buildTs.js +1 -1
- package/dist/cli.js +7 -0
- package/dist/getCurrentTest.d.ts +2 -1
- package/dist/runTests.js +1 -1
- package/dist/setup.d.ts +5 -4
- package/dist/setup.js +28 -14
- package/dist/utils/isCallable.d.ts +1 -1
- package/dist/utils/runCommand.d.ts +2 -2
- package/dist/utils/runCommand.js +1 -1
- package/package.json +2 -2
package/dist/buildTs.js
CHANGED
package/dist/cli.js
CHANGED
|
@@ -7,8 +7,10 @@ const source_map_support_1 = __importDefault(require("source-map-support"));
|
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const runTestSuites_1 = require("./runTestSuites");
|
|
9
9
|
const buildTs_1 = require("./buildTs");
|
|
10
|
+
const Logs_1 = require("./Logs");
|
|
10
11
|
initSourceMap();
|
|
11
12
|
initPromiseRejectionHandler();
|
|
13
|
+
initUserExitHandler();
|
|
12
14
|
cli();
|
|
13
15
|
function cli() {
|
|
14
16
|
const filter = (0, utils_1.findFilesParseCliArgs)();
|
|
@@ -20,6 +22,11 @@ function initPromiseRejectionHandler() {
|
|
|
20
22
|
process.exit(1);
|
|
21
23
|
});
|
|
22
24
|
}
|
|
25
|
+
function initUserExitHandler() {
|
|
26
|
+
process.on('SIGINT', function () {
|
|
27
|
+
Logs_1.Logs.flushLogs();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
23
30
|
function initSourceMap() {
|
|
24
31
|
source_map_support_1.default.install({
|
|
25
32
|
retrieveSourceMap: function (source) {
|
package/dist/getCurrentTest.d.ts
CHANGED
|
@@ -14,10 +14,11 @@ declare type TestInfo = {
|
|
|
14
14
|
cwd: string;
|
|
15
15
|
testFunctionTimeout: number;
|
|
16
16
|
additionalTimeout: number;
|
|
17
|
-
serverIsReadyMessage?: string;
|
|
17
|
+
serverIsReadyMessage?: string | ((log: string) => boolean);
|
|
18
18
|
serverIsReadyDelay: number;
|
|
19
19
|
inspect: boolean;
|
|
20
20
|
doNotFailOnWarning: boolean;
|
|
21
|
+
serverUrl: string;
|
|
21
22
|
};
|
|
22
23
|
hasStartedRunning?: boolean;
|
|
23
24
|
skipped?: string;
|
package/dist/runTests.js
CHANGED
|
@@ -8,7 +8,7 @@ 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('
|
|
11
|
+
const logsContainError_errMsg = (isTermination) => [picocolors_1.default.bold('Encountered an error or warning'), !isTermination ? '' : ' during termination', ', see logs below.'].join('');
|
|
12
12
|
async function runTests(browser) {
|
|
13
13
|
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
14
14
|
if (utils_1.isTTY) {
|
package/dist/setup.d.ts
CHANGED
|
@@ -13,17 +13,17 @@ export { isLinux };
|
|
|
13
13
|
export { isWindows };
|
|
14
14
|
export { isMac };
|
|
15
15
|
export { sleep };
|
|
16
|
-
export
|
|
17
|
-
export declare const urlBaseChange: (url: string) => string;
|
|
16
|
+
export { getServerUrl };
|
|
18
17
|
export { editFile, editFileRevert } from './editFile';
|
|
19
18
|
declare function skip(reason: string): void;
|
|
20
|
-
declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, doNotFailOnWarning, }?: {
|
|
19
|
+
declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, doNotFailOnWarning, serverUrl, }?: {
|
|
21
20
|
additionalTimeout?: number;
|
|
22
|
-
serverIsReadyMessage?: string;
|
|
21
|
+
serverIsReadyMessage?: string | ((log: string) => boolean);
|
|
23
22
|
serverIsReadyDelay?: number;
|
|
24
23
|
inspect?: boolean;
|
|
25
24
|
cwd?: string;
|
|
26
25
|
doNotFailOnWarning?: boolean;
|
|
26
|
+
serverUrl?: string;
|
|
27
27
|
}): void;
|
|
28
28
|
declare function autoRetry(test: () => void | Promise<void>, { timeout }?: {
|
|
29
29
|
timeout?: number;
|
|
@@ -31,3 +31,4 @@ declare function autoRetry(test: () => void | Promise<void>, { timeout }?: {
|
|
|
31
31
|
declare function fetchHtml(pathname: string): Promise<string>;
|
|
32
32
|
declare function fetch(...args: Parameters<typeof fetch_>): Promise<import("node-fetch").Response>;
|
|
33
33
|
declare function isMinNodeVersion(minNodeVersion: 14): boolean;
|
|
34
|
+
declare function getServerUrl(): string;
|
package/dist/setup.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.editFileRevert = exports.editFile = exports.
|
|
6
|
+
exports.editFileRevert = exports.editFile = exports.getServerUrl = exports.sleep = exports.isMac = exports.isWindows = exports.isLinux = exports.isGithubAction = exports.isMinNodeVersion = exports.skip = exports.run = exports.expectError = exports.fetch = exports.fetchHtml = exports.autoRetry = exports.partRegex = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
@@ -23,12 +23,10 @@ var part_regex_1 = require("@brillout/part-regex");
|
|
|
23
23
|
Object.defineProperty(exports, "partRegex", { enumerable: true, get: function () { return part_regex_1.partRegex; } });
|
|
24
24
|
var Logs_2 = require("./Logs");
|
|
25
25
|
Object.defineProperty(exports, "expectError", { enumerable: true, get: function () { return Logs_2.expectError; } });
|
|
26
|
-
exports.urlBase = 'http://localhost:3000';
|
|
27
|
-
const urlBaseChange = (url) => (exports.urlBase = url);
|
|
28
|
-
exports.urlBaseChange = urlBaseChange;
|
|
29
26
|
var editFile_2 = require("./editFile");
|
|
30
27
|
Object.defineProperty(exports, "editFile", { enumerable: true, get: function () { return editFile_2.editFile; } });
|
|
31
28
|
Object.defineProperty(exports, "editFileRevert", { enumerable: true, get: function () { return editFile_2.editFileRevert; } });
|
|
29
|
+
const serverUrlDefault = 'http://localhost:3000';
|
|
32
30
|
const TIMEOUT_NPM_SCRIPT = 2 * 60 * 1000;
|
|
33
31
|
const TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!(0, utils_1.isGithubAction)() ? 1 : (0, utils_1.isWindows)() ? 5 : 3);
|
|
34
32
|
const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!(0, utils_1.isGithubAction)() ? 1 : (0, utils_1.isLinux)() ? 1 : 4);
|
|
@@ -41,7 +39,7 @@ function skip(reason) {
|
|
|
41
39
|
exports.skip = skip;
|
|
42
40
|
function run(cmd, {
|
|
43
41
|
//baseUrl = '',
|
|
44
|
-
additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = utils_1.cliConfig.inspect, cwd, doNotFailOnWarning = false, } = {}) {
|
|
42
|
+
additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = utils_1.cliConfig.inspect, cwd, doNotFailOnWarning = false, serverUrl = serverUrlDefault, } = {}) {
|
|
45
43
|
additionalTimeout += serverIsReadyDelay;
|
|
46
44
|
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
47
45
|
testInfo.runInfo = {
|
|
@@ -53,6 +51,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
|
|
|
53
51
|
serverIsReadyDelay,
|
|
54
52
|
inspect,
|
|
55
53
|
doNotFailOnWarning,
|
|
54
|
+
serverUrl,
|
|
56
55
|
};
|
|
57
56
|
if (inspect) {
|
|
58
57
|
Logs_1.Logs.flushEagerly = true;
|
|
@@ -68,7 +67,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
|
|
|
68
67
|
/*
|
|
69
68
|
await bailOnTimeout(
|
|
70
69
|
async () => {
|
|
71
|
-
await page.goto(
|
|
70
|
+
await page.goto(getServerUrl() + baseUrl)
|
|
72
71
|
},
|
|
73
72
|
{ timeout: TIMEOUT_PAGE_LOAD + additionalTimeout },
|
|
74
73
|
)
|
|
@@ -176,9 +175,11 @@ async function start() {
|
|
|
176
175
|
await terminate();
|
|
177
176
|
rejectServerStart(new Error(errMsg));
|
|
178
177
|
}, timeoutTotal);
|
|
179
|
-
// Kill any process that listens to port
|
|
178
|
+
// Kill any process that listens to the server port
|
|
180
179
|
if (!process.env.CI && (0, utils_1.isLinux)()) {
|
|
181
|
-
|
|
180
|
+
const port = getPort();
|
|
181
|
+
(0, utils_2.assert)(/\d+/.test(port));
|
|
182
|
+
await (0, utils_1.runCommand)(`fuser -k ${port}/tcp`, { swallowError: true, timeout: 10 * 1000 });
|
|
182
183
|
}
|
|
183
184
|
const { terminate, processHasExited } = execRunScript({
|
|
184
185
|
async onFailure(err) {
|
|
@@ -191,16 +192,17 @@ async function start() {
|
|
|
191
192
|
return exitIsPossible;
|
|
192
193
|
},
|
|
193
194
|
async onStdout(data) {
|
|
194
|
-
const
|
|
195
|
+
const log = (0, strip_ansi_1.default)(data);
|
|
195
196
|
const isServerReady =
|
|
196
197
|
// Custom
|
|
197
|
-
(serverIsReadyMessage &&
|
|
198
|
+
(typeof serverIsReadyMessage === 'string' && log.includes(serverIsReadyMessage)) ||
|
|
199
|
+
((0, utils_1.isCallable)(serverIsReadyMessage) && serverIsReadyMessage(log)) ||
|
|
198
200
|
// Express.js server
|
|
199
|
-
|
|
201
|
+
log.includes('Server running at') ||
|
|
200
202
|
// npm package `serve`
|
|
201
|
-
|
|
203
|
+
log.includes('Accepting connections at') ||
|
|
202
204
|
// Vite
|
|
203
|
-
(
|
|
205
|
+
(log.includes('Local:') && log.includes('http://localhost:3000/'));
|
|
204
206
|
if (isServerReady) {
|
|
205
207
|
(0, utils_2.assert)(serverIsReadyDelay);
|
|
206
208
|
await (0, utils_1.sleep)(serverIsReadyDelay);
|
|
@@ -401,7 +403,7 @@ async function autoRetry(test, { timeout = TIMEOUT_AUTORETRY } = {}) {
|
|
|
401
403
|
}
|
|
402
404
|
exports.autoRetry = autoRetry;
|
|
403
405
|
async function fetchHtml(pathname) {
|
|
404
|
-
const response = await fetch(
|
|
406
|
+
const response = await fetch(getServerUrl() + pathname);
|
|
405
407
|
const html = await response.text();
|
|
406
408
|
return html;
|
|
407
409
|
}
|
|
@@ -453,3 +455,15 @@ function getCwd() {
|
|
|
453
455
|
const cwd = (0, path_1.dirname)(testFile);
|
|
454
456
|
return cwd;
|
|
455
457
|
}
|
|
458
|
+
function getServerUrl() {
|
|
459
|
+
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
460
|
+
const serverUrl = testInfo.runInfo?.serverUrl;
|
|
461
|
+
return serverUrl;
|
|
462
|
+
}
|
|
463
|
+
exports.getServerUrl = getServerUrl;
|
|
464
|
+
function getPort() {
|
|
465
|
+
const serverUrl = getServerUrl();
|
|
466
|
+
const port = serverUrl.split(':').slice(-1)[0].split('/')[0];
|
|
467
|
+
(0, utils_2.assert)(/\d+/.test(port), { serverUrl });
|
|
468
|
+
return port;
|
|
469
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isCallable
|
|
1
|
+
export declare function isCallable(thing: unknown): thing is Function;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { runCommand };
|
|
2
|
-
declare function runCommand(cmd: string, { swallowError, timeout, cwd }?: {
|
|
3
|
-
swallowError?:
|
|
2
|
+
declare function runCommand(cmd: string, { swallowError, timeout, cwd, }?: {
|
|
3
|
+
swallowError?: boolean;
|
|
4
4
|
timeout?: number;
|
|
5
5
|
cwd?: string;
|
|
6
6
|
}): Promise<string>;
|
package/dist/utils/runCommand.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runCommand = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
|
-
function runCommand(cmd, { swallowError, timeout = 5000, cwd } = {}) {
|
|
5
|
+
function runCommand(cmd, { swallowError = false, timeout = 5000, cwd = process.cwd(), } = {}) {
|
|
6
6
|
const { promise, resolvePromise } = genPromise();
|
|
7
7
|
const t = setTimeout(() => {
|
|
8
8
|
console.error(`Command call \`${cmd}\` timeout [${timeout / 1000} seconds][${cwd}].`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brillout/test-e2e",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"bin": "./bin.js",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@brillout/part-regex": "^0.1.2",
|
|
17
17
|
"chai": "^4.3.6",
|
|
18
|
-
"esbuild": "^0.
|
|
18
|
+
"esbuild": "^0.16.5",
|
|
19
19
|
"fast-glob": "^3.2.12",
|
|
20
20
|
"node-fetch": "^2.6.1",
|
|
21
21
|
"picocolors": "^1.0.0",
|