@deot/dev-test 2.8.1 → 2.9.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 +42 -26
- package/dist/index.d.ts +24 -19
- package/dist/index.js +42 -26
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -123,8 +123,7 @@ class Command {
|
|
|
123
123
|
return response;
|
|
124
124
|
}
|
|
125
125
|
async press(key, timeout = 200) {
|
|
126
|
-
if (!key || this.isClose)
|
|
127
|
-
return;
|
|
126
|
+
if (!key || this.isClose) return;
|
|
128
127
|
await this.schedule.target;
|
|
129
128
|
this.schedule.target = new Promise((resolve) => {
|
|
130
129
|
this.schedule.complete = resolve;
|
|
@@ -331,7 +330,7 @@ class Launch {
|
|
|
331
330
|
}
|
|
332
331
|
this._browser = puppeteer.launch({
|
|
333
332
|
...this.puppeteerOptions,
|
|
334
|
-
headless:
|
|
333
|
+
headless: true
|
|
335
334
|
});
|
|
336
335
|
this._browser.then((browser) => {
|
|
337
336
|
this.browser = browser;
|
|
@@ -371,36 +370,55 @@ class Launch {
|
|
|
371
370
|
}
|
|
372
371
|
}
|
|
373
372
|
|
|
374
|
-
class
|
|
373
|
+
class Interrupter {
|
|
374
|
+
static of(options) {
|
|
375
|
+
return new Interrupter(options);
|
|
376
|
+
}
|
|
377
|
+
options = {};
|
|
375
378
|
_success;
|
|
376
379
|
_fail;
|
|
377
380
|
_task;
|
|
378
381
|
_finish = false;
|
|
379
|
-
constructor() {
|
|
380
|
-
|
|
382
|
+
constructor(options) {
|
|
383
|
+
if (options) {
|
|
384
|
+
this.options = options;
|
|
385
|
+
}
|
|
386
|
+
this._generateTask();
|
|
381
387
|
}
|
|
382
|
-
|
|
388
|
+
_generateTask = () => {
|
|
389
|
+
this._task = new Promise((resolve, reject) => {
|
|
390
|
+
this._success = (value) => {
|
|
391
|
+
this._fail = void 0;
|
|
392
|
+
resolve(value);
|
|
393
|
+
};
|
|
394
|
+
this._fail = (value) => {
|
|
395
|
+
this._success = void 0;
|
|
396
|
+
reject(value);
|
|
397
|
+
};
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
next = async (v) => {
|
|
383
401
|
if (!this._finish) {
|
|
384
402
|
this._success?.(v);
|
|
385
|
-
this._task
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
this._fail = (value) => {
|
|
391
|
-
this._success = void 0;
|
|
392
|
-
reject(value);
|
|
393
|
-
};
|
|
394
|
-
});
|
|
403
|
+
await this._task;
|
|
404
|
+
await Promise.resolve();
|
|
405
|
+
this._generateTask();
|
|
406
|
+
} else {
|
|
407
|
+
await this._task;
|
|
395
408
|
}
|
|
396
|
-
return this;
|
|
397
409
|
};
|
|
398
|
-
nextWithError = (v) => {
|
|
410
|
+
nextWithError = async (v) => {
|
|
399
411
|
if (!this._finish) {
|
|
400
412
|
this._fail?.(v);
|
|
401
|
-
|
|
413
|
+
try {
|
|
414
|
+
await this._task;
|
|
415
|
+
} catch {
|
|
416
|
+
await Promise.resolve();
|
|
417
|
+
this._generateTask();
|
|
418
|
+
}
|
|
419
|
+
} else {
|
|
420
|
+
await this._task;
|
|
402
421
|
}
|
|
403
|
-
return this;
|
|
404
422
|
};
|
|
405
423
|
finish = (v) => {
|
|
406
424
|
this._success?.(v);
|
|
@@ -488,8 +506,7 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
488
506
|
|
|
489
507
|
let defaultHost = "";
|
|
490
508
|
const host = (force) => {
|
|
491
|
-
if (!force && defaultHost)
|
|
492
|
-
return defaultHost;
|
|
509
|
+
if (!force && defaultHost) return defaultHost;
|
|
493
510
|
const ips = [];
|
|
494
511
|
const ntwk = os__namespace.networkInterfaces();
|
|
495
512
|
for (const k in ntwk) {
|
|
@@ -506,8 +523,7 @@ const host = (force) => {
|
|
|
506
523
|
defaultHost = host();
|
|
507
524
|
const port = (host$ = defaultHost, port$ = 1024) => {
|
|
508
525
|
/* istanbul ignore next -- @preserve */
|
|
509
|
-
if (port$ < 1024)
|
|
510
|
-
throw new Error("port < 1024");
|
|
526
|
+
if (port$ < 1024) throw new Error("port < 1024");
|
|
511
527
|
return new Promise((resolve, reject) => {
|
|
512
528
|
const server = http__namespace.createServer();
|
|
513
529
|
server.unref();
|
|
@@ -548,8 +564,8 @@ const server = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
548
564
|
|
|
549
565
|
exports.Command = Command;
|
|
550
566
|
exports.E2E = e2e;
|
|
567
|
+
exports.Interrupter = Interrupter;
|
|
551
568
|
exports.Launch = Launch;
|
|
552
569
|
exports.Operater = Operater;
|
|
553
|
-
exports.Scheduler = Scheduler;
|
|
554
570
|
exports.Server = server;
|
|
555
571
|
exports.Utils = utils;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
1
|
import type { Browser } from 'puppeteer';
|
|
4
2
|
import * as childProcess from 'child_process';
|
|
5
3
|
import type { ClickOptions } from 'puppeteer';
|
|
4
|
+
import type { LaunchOptions } from 'puppeteer';
|
|
6
5
|
import type { Nullable } from '@deot/dev-shared';
|
|
7
6
|
import type { Page } from 'puppeteer';
|
|
8
|
-
import type { PuppeteerLaunchOptions } from 'puppeteer';
|
|
9
7
|
|
|
10
8
|
declare const available: () => Promise<{
|
|
11
9
|
host: string;
|
|
@@ -58,13 +56,35 @@ declare const host: (force?: boolean) => string;
|
|
|
58
56
|
|
|
59
57
|
declare const impl: () => Launch;
|
|
60
58
|
|
|
59
|
+
export declare class Interrupter<T = any> {
|
|
60
|
+
static of(options?: InterrupterOptions): Interrupter<any>;
|
|
61
|
+
options: InterrupterOptions;
|
|
62
|
+
_success?: Func<any>;
|
|
63
|
+
_fail?: Func<any>;
|
|
64
|
+
_task: Promise<any>;
|
|
65
|
+
_finish: boolean;
|
|
66
|
+
constructor(options?: InterrupterOptions);
|
|
67
|
+
_generateTask: () => void;
|
|
68
|
+
next: (v?: T) => Promise<void>;
|
|
69
|
+
nextWithError: (v?: any) => Promise<void>;
|
|
70
|
+
finish: (v?: T) => this;
|
|
71
|
+
finishWithError: (v?: T) => this;
|
|
72
|
+
then(resolve: Func<T>, reject?: Func<T>): Promise<void>;
|
|
73
|
+
catch(callback?: Func<T>): Promise<any>;
|
|
74
|
+
finally(callback?: Func<void>): Promise<any>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare interface InterrupterOptions {
|
|
78
|
+
timeout?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
61
81
|
export declare class Launch {
|
|
62
82
|
browser: Browser;
|
|
63
83
|
page: Page;
|
|
64
84
|
operater: Operater;
|
|
65
85
|
private _browser;
|
|
66
86
|
private _page;
|
|
67
|
-
puppeteerOptions:
|
|
87
|
+
puppeteerOptions: LaunchOptions;
|
|
68
88
|
options: {
|
|
69
89
|
logLevel?: string;
|
|
70
90
|
};
|
|
@@ -96,21 +116,6 @@ export declare class Operater {
|
|
|
96
116
|
|
|
97
117
|
declare const port: (host$?: string, port$?: number) => Promise<unknown>;
|
|
98
118
|
|
|
99
|
-
export declare class Scheduler<T = any> {
|
|
100
|
-
_success?: Func<any>;
|
|
101
|
-
_fail?: Func<any>;
|
|
102
|
-
_task: Promise<any>;
|
|
103
|
-
_finish: boolean;
|
|
104
|
-
constructor();
|
|
105
|
-
next: (v?: T) => this;
|
|
106
|
-
nextWithError: (v?: any) => this;
|
|
107
|
-
finish: (v?: T) => this;
|
|
108
|
-
finishWithError: (v?: T) => this;
|
|
109
|
-
then(resolve: Func<T>, reject: Func<T>): Promise<void>;
|
|
110
|
-
catch(callback?: Func<T>): Promise<any>;
|
|
111
|
-
finally(callback?: Func<void>): Promise<any>;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
119
|
declare namespace Server {
|
|
115
120
|
export {
|
|
116
121
|
host,
|
package/dist/index.js
CHANGED
|
@@ -98,8 +98,7 @@ class Command {
|
|
|
98
98
|
return response;
|
|
99
99
|
}
|
|
100
100
|
async press(key, timeout = 200) {
|
|
101
|
-
if (!key || this.isClose)
|
|
102
|
-
return;
|
|
101
|
+
if (!key || this.isClose) return;
|
|
103
102
|
await this.schedule.target;
|
|
104
103
|
this.schedule.target = new Promise((resolve) => {
|
|
105
104
|
this.schedule.complete = resolve;
|
|
@@ -306,7 +305,7 @@ class Launch {
|
|
|
306
305
|
}
|
|
307
306
|
this._browser = puppeteer.launch({
|
|
308
307
|
...this.puppeteerOptions,
|
|
309
|
-
headless:
|
|
308
|
+
headless: true
|
|
310
309
|
});
|
|
311
310
|
this._browser.then((browser) => {
|
|
312
311
|
this.browser = browser;
|
|
@@ -346,36 +345,55 @@ class Launch {
|
|
|
346
345
|
}
|
|
347
346
|
}
|
|
348
347
|
|
|
349
|
-
class
|
|
348
|
+
class Interrupter {
|
|
349
|
+
static of(options) {
|
|
350
|
+
return new Interrupter(options);
|
|
351
|
+
}
|
|
352
|
+
options = {};
|
|
350
353
|
_success;
|
|
351
354
|
_fail;
|
|
352
355
|
_task;
|
|
353
356
|
_finish = false;
|
|
354
|
-
constructor() {
|
|
355
|
-
|
|
357
|
+
constructor(options) {
|
|
358
|
+
if (options) {
|
|
359
|
+
this.options = options;
|
|
360
|
+
}
|
|
361
|
+
this._generateTask();
|
|
356
362
|
}
|
|
357
|
-
|
|
363
|
+
_generateTask = () => {
|
|
364
|
+
this._task = new Promise((resolve, reject) => {
|
|
365
|
+
this._success = (value) => {
|
|
366
|
+
this._fail = void 0;
|
|
367
|
+
resolve(value);
|
|
368
|
+
};
|
|
369
|
+
this._fail = (value) => {
|
|
370
|
+
this._success = void 0;
|
|
371
|
+
reject(value);
|
|
372
|
+
};
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
next = async (v) => {
|
|
358
376
|
if (!this._finish) {
|
|
359
377
|
this._success?.(v);
|
|
360
|
-
this._task
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
this._fail = (value) => {
|
|
366
|
-
this._success = void 0;
|
|
367
|
-
reject(value);
|
|
368
|
-
};
|
|
369
|
-
});
|
|
378
|
+
await this._task;
|
|
379
|
+
await Promise.resolve();
|
|
380
|
+
this._generateTask();
|
|
381
|
+
} else {
|
|
382
|
+
await this._task;
|
|
370
383
|
}
|
|
371
|
-
return this;
|
|
372
384
|
};
|
|
373
|
-
nextWithError = (v) => {
|
|
385
|
+
nextWithError = async (v) => {
|
|
374
386
|
if (!this._finish) {
|
|
375
387
|
this._fail?.(v);
|
|
376
|
-
|
|
388
|
+
try {
|
|
389
|
+
await this._task;
|
|
390
|
+
} catch {
|
|
391
|
+
await Promise.resolve();
|
|
392
|
+
this._generateTask();
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
await this._task;
|
|
377
396
|
}
|
|
378
|
-
return this;
|
|
379
397
|
};
|
|
380
398
|
finish = (v) => {
|
|
381
399
|
this._success?.(v);
|
|
@@ -463,8 +481,7 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
463
481
|
|
|
464
482
|
let defaultHost = "";
|
|
465
483
|
const host = (force) => {
|
|
466
|
-
if (!force && defaultHost)
|
|
467
|
-
return defaultHost;
|
|
484
|
+
if (!force && defaultHost) return defaultHost;
|
|
468
485
|
const ips = [];
|
|
469
486
|
const ntwk = os.networkInterfaces();
|
|
470
487
|
for (const k in ntwk) {
|
|
@@ -481,8 +498,7 @@ const host = (force) => {
|
|
|
481
498
|
defaultHost = host();
|
|
482
499
|
const port = (host$ = defaultHost, port$ = 1024) => {
|
|
483
500
|
/* istanbul ignore next -- @preserve */
|
|
484
|
-
if (port$ < 1024)
|
|
485
|
-
throw new Error("port < 1024");
|
|
501
|
+
if (port$ < 1024) throw new Error("port < 1024");
|
|
486
502
|
return new Promise((resolve, reject) => {
|
|
487
503
|
const server = http.createServer();
|
|
488
504
|
server.unref();
|
|
@@ -521,4 +537,4 @@ const server = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
521
537
|
port
|
|
522
538
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
523
539
|
|
|
524
|
-
export { Command, e2e as E2E, Launch, Operater,
|
|
540
|
+
export { Command, e2e as E2E, Interrupter, Launch, Operater, server as Server, utils as Utils };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-test",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
9
10
|
"import": "./dist/index.js",
|
|
10
|
-
"require": "./dist/index.cjs"
|
|
11
|
-
"types": "./dist/index.d.ts"
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@deot/dev-shared": "^2.
|
|
23
|
-
"puppeteer": "^
|
|
22
|
+
"@deot/dev-shared": "^2.9.0",
|
|
23
|
+
"puppeteer": "^24.2.0"
|
|
24
24
|
}
|
|
25
25
|
}
|