@deot/dev-test 2.2.0 → 2.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/index.cjs.js +67 -8
- package/dist/index.d.ts +19 -0
- package/dist/index.es.js +65 -9
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const devShared = require('@deot/dev-shared');
|
|
6
6
|
const childProcess = require('child_process');
|
|
7
7
|
const puppeteer = require('puppeteer');
|
|
8
|
+
const http = require('http');
|
|
9
|
+
const os = require('os');
|
|
8
10
|
|
|
9
11
|
function _interopNamespaceDefault(e) {
|
|
10
12
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
@@ -24,6 +26,8 @@ function _interopNamespaceDefault(e) {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
|
|
29
|
+
const http__namespace = /*#__PURE__*/_interopNamespaceDefault(http);
|
|
30
|
+
const os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
|
|
27
31
|
|
|
28
32
|
const { LOCAL_COMMAND_MAP } = devShared.Shell;
|
|
29
33
|
const KEY_MAP = {
|
|
@@ -356,14 +360,8 @@ class Launch {
|
|
|
356
360
|
"console",
|
|
357
361
|
/* istanbul ignore next */
|
|
358
362
|
(e) => {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
console.error(
|
|
362
|
-
`Error from Puppeteer-loaded page:
|
|
363
|
-
`,
|
|
364
|
-
err.remoteObject().description
|
|
365
|
-
);
|
|
366
|
-
}
|
|
363
|
+
const key = e.type();
|
|
364
|
+
console[key].call(console[key], `${key} from puppeteer: `, ...e.args().map((i) => i.remoteObject()));
|
|
367
365
|
}
|
|
368
366
|
);
|
|
369
367
|
this.page = page;
|
|
@@ -439,8 +437,69 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
439
437
|
sleep
|
|
440
438
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
441
439
|
|
|
440
|
+
let defaultHost = "";
|
|
441
|
+
const host = (force) => {
|
|
442
|
+
if (!force && defaultHost)
|
|
443
|
+
return defaultHost;
|
|
444
|
+
let ips = [];
|
|
445
|
+
let ntwk = os__namespace.networkInterfaces();
|
|
446
|
+
for (let k in ntwk) {
|
|
447
|
+
for (let i = 0; i < ntwk[k].length; i++) {
|
|
448
|
+
let _add = ntwk[k][i].address;
|
|
449
|
+
if (_add && _add.split(".").length == 4 && !ntwk[k][i].internal && ntwk[k][i].family == "IPv4") {
|
|
450
|
+
ips.push(ntwk[k][i].address);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/* istanbul ignore next -- @preserve */
|
|
455
|
+
return ips[0] || "localhost";
|
|
456
|
+
};
|
|
457
|
+
defaultHost = host();
|
|
458
|
+
const port = (host$ = defaultHost, port$ = 1024) => {
|
|
459
|
+
/* istanbul ignore next -- @preserve */
|
|
460
|
+
if (port$ < 1024)
|
|
461
|
+
throw new Error("port < 1024");
|
|
462
|
+
return new Promise((resolve, reject) => {
|
|
463
|
+
const server = http__namespace.createServer();
|
|
464
|
+
server.unref();
|
|
465
|
+
server.on(
|
|
466
|
+
"error",
|
|
467
|
+
/* istanbul ignore next -- @preserve */
|
|
468
|
+
() => {
|
|
469
|
+
if (port$ >= 65535) {
|
|
470
|
+
reject();
|
|
471
|
+
} else {
|
|
472
|
+
port(host$, port$ + 1).then(resolve).catch(reject);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
);
|
|
476
|
+
server.listen({ host: host$, port: port$ }, () => {
|
|
477
|
+
server.close(() => {
|
|
478
|
+
resolve(port$);
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
};
|
|
483
|
+
const available = async () => {
|
|
484
|
+
const host$ = host();
|
|
485
|
+
const port$ = await port(host$);
|
|
486
|
+
return {
|
|
487
|
+
host: host$,
|
|
488
|
+
port: port$,
|
|
489
|
+
baseUrl: `http://${host$}:${port$}`
|
|
490
|
+
};
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const server = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
494
|
+
__proto__: null,
|
|
495
|
+
available,
|
|
496
|
+
host,
|
|
497
|
+
port
|
|
498
|
+
}, Symbol.toStringTag, { value: 'Module' }));
|
|
499
|
+
|
|
442
500
|
exports.Command = Command;
|
|
443
501
|
exports.E2E = e2e;
|
|
444
502
|
exports.Launch = Launch;
|
|
445
503
|
exports.Operater = Operater;
|
|
504
|
+
exports.Server = server;
|
|
446
505
|
exports.Utils = utils;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ import type { Nullable } from '@deot/dev-shared';
|
|
|
7
7
|
import type { Page } from 'puppeteer';
|
|
8
8
|
import type { PuppeteerLaunchOptions } from 'puppeteer';
|
|
9
9
|
|
|
10
|
+
declare const available: () => Promise<{
|
|
11
|
+
host: string;
|
|
12
|
+
port: unknown;
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
10
16
|
export declare class Command {
|
|
11
17
|
target: Promise<any>;
|
|
12
18
|
code: Nullable<any>;
|
|
@@ -46,6 +52,8 @@ declare interface ExpectByPollingOptions {
|
|
|
46
52
|
to?: string;
|
|
47
53
|
}
|
|
48
54
|
|
|
55
|
+
declare const host: (force?: boolean) => string;
|
|
56
|
+
|
|
49
57
|
declare const impl: () => Launch;
|
|
50
58
|
|
|
51
59
|
export declare class Launch {
|
|
@@ -81,6 +89,17 @@ export declare class Operater {
|
|
|
81
89
|
nextFrame(): Promise<unknown>;
|
|
82
90
|
}
|
|
83
91
|
|
|
92
|
+
declare const port: (host$?: string, port$?: number) => Promise<unknown>;
|
|
93
|
+
|
|
94
|
+
declare namespace Server {
|
|
95
|
+
export {
|
|
96
|
+
host,
|
|
97
|
+
port,
|
|
98
|
+
available
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export { Server }
|
|
102
|
+
|
|
84
103
|
declare const sleep: (s?: number) => Promise<unknown>;
|
|
85
104
|
|
|
86
105
|
declare const TIME_OUT: number;
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Shell } from '@deot/dev-shared';
|
|
2
2
|
import * as childProcess from 'child_process';
|
|
3
3
|
import puppeteer from 'puppeteer';
|
|
4
|
+
import * as http from 'http';
|
|
5
|
+
import * as os from 'os';
|
|
4
6
|
|
|
5
7
|
const { LOCAL_COMMAND_MAP } = Shell;
|
|
6
8
|
const KEY_MAP = {
|
|
@@ -333,14 +335,8 @@ class Launch {
|
|
|
333
335
|
"console",
|
|
334
336
|
/* istanbul ignore next */
|
|
335
337
|
(e) => {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
console.error(
|
|
339
|
-
`Error from Puppeteer-loaded page:
|
|
340
|
-
`,
|
|
341
|
-
err.remoteObject().description
|
|
342
|
-
);
|
|
343
|
-
}
|
|
338
|
+
const key = e.type();
|
|
339
|
+
console[key].call(console[key], `${key} from puppeteer: `, ...e.args().map((i) => i.remoteObject()));
|
|
344
340
|
}
|
|
345
341
|
);
|
|
346
342
|
this.page = page;
|
|
@@ -416,4 +412,64 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
416
412
|
sleep
|
|
417
413
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
418
414
|
|
|
419
|
-
|
|
415
|
+
let defaultHost = "";
|
|
416
|
+
const host = (force) => {
|
|
417
|
+
if (!force && defaultHost)
|
|
418
|
+
return defaultHost;
|
|
419
|
+
let ips = [];
|
|
420
|
+
let ntwk = os.networkInterfaces();
|
|
421
|
+
for (let k in ntwk) {
|
|
422
|
+
for (let i = 0; i < ntwk[k].length; i++) {
|
|
423
|
+
let _add = ntwk[k][i].address;
|
|
424
|
+
if (_add && _add.split(".").length == 4 && !ntwk[k][i].internal && ntwk[k][i].family == "IPv4") {
|
|
425
|
+
ips.push(ntwk[k][i].address);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/* istanbul ignore next -- @preserve */
|
|
430
|
+
return ips[0] || "localhost";
|
|
431
|
+
};
|
|
432
|
+
defaultHost = host();
|
|
433
|
+
const port = (host$ = defaultHost, port$ = 1024) => {
|
|
434
|
+
/* istanbul ignore next -- @preserve */
|
|
435
|
+
if (port$ < 1024)
|
|
436
|
+
throw new Error("port < 1024");
|
|
437
|
+
return new Promise((resolve, reject) => {
|
|
438
|
+
const server = http.createServer();
|
|
439
|
+
server.unref();
|
|
440
|
+
server.on(
|
|
441
|
+
"error",
|
|
442
|
+
/* istanbul ignore next -- @preserve */
|
|
443
|
+
() => {
|
|
444
|
+
if (port$ >= 65535) {
|
|
445
|
+
reject();
|
|
446
|
+
} else {
|
|
447
|
+
port(host$, port$ + 1).then(resolve).catch(reject);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
|
+
server.listen({ host: host$, port: port$ }, () => {
|
|
452
|
+
server.close(() => {
|
|
453
|
+
resolve(port$);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
};
|
|
458
|
+
const available = async () => {
|
|
459
|
+
const host$ = host();
|
|
460
|
+
const port$ = await port(host$);
|
|
461
|
+
return {
|
|
462
|
+
host: host$,
|
|
463
|
+
port: port$,
|
|
464
|
+
baseUrl: `http://${host$}:${port$}`
|
|
465
|
+
};
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const server = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
469
|
+
__proto__: null,
|
|
470
|
+
available,
|
|
471
|
+
host,
|
|
472
|
+
port
|
|
473
|
+
}, Symbol.toStringTag, { value: 'Module' }));
|
|
474
|
+
|
|
475
|
+
export { Command, e2e as E2E, Launch, Operater, server as Server, utils as Utils };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-test",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"main": "dist/index.es.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@deot/dev-shared": "^2.
|
|
16
|
-
"puppeteer": "^20.
|
|
15
|
+
"@deot/dev-shared": "^2.3.0",
|
|
16
|
+
"puppeteer": "^20.9.0"
|
|
17
17
|
}
|
|
18
18
|
}
|