@deot/dev-test 2.1.0 → 2.3.0

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 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 = {
@@ -439,8 +443,69 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
439
443
  sleep
440
444
  }, Symbol.toStringTag, { value: 'Module' }));
441
445
 
446
+ let defaultHost = "";
447
+ const host = (force) => {
448
+ if (!force && defaultHost)
449
+ return defaultHost;
450
+ let ips = [];
451
+ let ntwk = os__namespace.networkInterfaces();
452
+ for (let k in ntwk) {
453
+ for (let i = 0; i < ntwk[k].length; i++) {
454
+ let _add = ntwk[k][i].address;
455
+ if (_add && _add.split(".").length == 4 && !ntwk[k][i].internal && ntwk[k][i].family == "IPv4") {
456
+ ips.push(ntwk[k][i].address);
457
+ }
458
+ }
459
+ }
460
+ /* istanbul ignore next -- @preserve */
461
+ return ips[0] || "localhost";
462
+ };
463
+ defaultHost = host();
464
+ const port = (host$ = defaultHost, port$ = 1024) => {
465
+ /* istanbul ignore next -- @preserve */
466
+ if (port$ < 1024)
467
+ throw new Error("port < 1024");
468
+ return new Promise((resolve, reject) => {
469
+ const server = http__namespace.createServer();
470
+ server.unref();
471
+ server.on(
472
+ "error",
473
+ /* istanbul ignore next -- @preserve */
474
+ () => {
475
+ if (port$ >= 65535) {
476
+ reject();
477
+ } else {
478
+ port(host$, port$ + 1).then(resolve).catch(reject);
479
+ }
480
+ }
481
+ );
482
+ server.listen({ host: host$, port: port$ }, () => {
483
+ server.close(() => {
484
+ resolve(port$);
485
+ });
486
+ });
487
+ });
488
+ };
489
+ const available = async () => {
490
+ const host$ = host();
491
+ const port$ = await port(host$);
492
+ return {
493
+ host: host$,
494
+ port: port$,
495
+ baseUrl: `http://${host$}:${port$}`
496
+ };
497
+ };
498
+
499
+ const server = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
500
+ __proto__: null,
501
+ available,
502
+ host,
503
+ port
504
+ }, Symbol.toStringTag, { value: 'Module' }));
505
+
442
506
  exports.Command = Command;
443
507
  exports.E2E = e2e;
444
508
  exports.Launch = Launch;
445
509
  exports.Operater = Operater;
510
+ exports.Server = server;
446
511
  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 = {
@@ -416,4 +418,64 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
416
418
  sleep
417
419
  }, Symbol.toStringTag, { value: 'Module' }));
418
420
 
419
- export { Command, e2e as E2E, Launch, Operater, utils as Utils };
421
+ let defaultHost = "";
422
+ const host = (force) => {
423
+ if (!force && defaultHost)
424
+ return defaultHost;
425
+ let ips = [];
426
+ let ntwk = os.networkInterfaces();
427
+ for (let k in ntwk) {
428
+ for (let i = 0; i < ntwk[k].length; i++) {
429
+ let _add = ntwk[k][i].address;
430
+ if (_add && _add.split(".").length == 4 && !ntwk[k][i].internal && ntwk[k][i].family == "IPv4") {
431
+ ips.push(ntwk[k][i].address);
432
+ }
433
+ }
434
+ }
435
+ /* istanbul ignore next -- @preserve */
436
+ return ips[0] || "localhost";
437
+ };
438
+ defaultHost = host();
439
+ const port = (host$ = defaultHost, port$ = 1024) => {
440
+ /* istanbul ignore next -- @preserve */
441
+ if (port$ < 1024)
442
+ throw new Error("port < 1024");
443
+ return new Promise((resolve, reject) => {
444
+ const server = http.createServer();
445
+ server.unref();
446
+ server.on(
447
+ "error",
448
+ /* istanbul ignore next -- @preserve */
449
+ () => {
450
+ if (port$ >= 65535) {
451
+ reject();
452
+ } else {
453
+ port(host$, port$ + 1).then(resolve).catch(reject);
454
+ }
455
+ }
456
+ );
457
+ server.listen({ host: host$, port: port$ }, () => {
458
+ server.close(() => {
459
+ resolve(port$);
460
+ });
461
+ });
462
+ });
463
+ };
464
+ const available = async () => {
465
+ const host$ = host();
466
+ const port$ = await port(host$);
467
+ return {
468
+ host: host$,
469
+ port: port$,
470
+ baseUrl: `http://${host$}:${port$}`
471
+ };
472
+ };
473
+
474
+ const server = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
475
+ __proto__: null,
476
+ available,
477
+ host,
478
+ port
479
+ }, Symbol.toStringTag, { value: 'Module' }));
480
+
481
+ 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.1.0",
3
+ "version": "2.3.0",
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.1.0",
16
- "puppeteer": "^20.8.0"
15
+ "@deot/dev-shared": "^2.3.0",
16
+ "puppeteer": "^20.9.0"
17
17
  }
18
18
  }