@deot/dev-test 2.8.0 → 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 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: "new"
333
+ headless: true
335
334
  });
336
335
  this._browser.then((browser) => {
337
336
  this.browser = browser;
@@ -371,6 +370,77 @@ class Launch {
371
370
  }
372
371
  }
373
372
 
373
+ class Interrupter {
374
+ static of(options) {
375
+ return new Interrupter(options);
376
+ }
377
+ options = {};
378
+ _success;
379
+ _fail;
380
+ _task;
381
+ _finish = false;
382
+ constructor(options) {
383
+ if (options) {
384
+ this.options = options;
385
+ }
386
+ this._generateTask();
387
+ }
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) => {
401
+ if (!this._finish) {
402
+ this._success?.(v);
403
+ await this._task;
404
+ await Promise.resolve();
405
+ this._generateTask();
406
+ } else {
407
+ await this._task;
408
+ }
409
+ };
410
+ nextWithError = async (v) => {
411
+ if (!this._finish) {
412
+ this._fail?.(v);
413
+ try {
414
+ await this._task;
415
+ } catch {
416
+ await Promise.resolve();
417
+ this._generateTask();
418
+ }
419
+ } else {
420
+ await this._task;
421
+ }
422
+ };
423
+ finish = (v) => {
424
+ this._success?.(v);
425
+ this._finish = true;
426
+ return this;
427
+ };
428
+ finishWithError = (v) => {
429
+ this._fail?.(v);
430
+ this._finish = true;
431
+ return this;
432
+ };
433
+ then(resolve, reject) {
434
+ return this._task.then(resolve, reject);
435
+ }
436
+ catch(callback) {
437
+ return this._task.catch(callback);
438
+ }
439
+ finally(callback) {
440
+ return this._task.finally(callback);
441
+ }
442
+ }
443
+
374
444
  const TIME_OUT = 60 * 1e3;
375
445
  const impl = () => {
376
446
  const launch = new Launch();
@@ -436,8 +506,7 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
436
506
 
437
507
  let defaultHost = "";
438
508
  const host = (force) => {
439
- if (!force && defaultHost)
440
- return defaultHost;
509
+ if (!force && defaultHost) return defaultHost;
441
510
  const ips = [];
442
511
  const ntwk = os__namespace.networkInterfaces();
443
512
  for (const k in ntwk) {
@@ -454,8 +523,7 @@ const host = (force) => {
454
523
  defaultHost = host();
455
524
  const port = (host$ = defaultHost, port$ = 1024) => {
456
525
  /* istanbul ignore next -- @preserve */
457
- if (port$ < 1024)
458
- throw new Error("port < 1024");
526
+ if (port$ < 1024) throw new Error("port < 1024");
459
527
  return new Promise((resolve, reject) => {
460
528
  const server = http__namespace.createServer();
461
529
  server.unref();
@@ -496,6 +564,7 @@ const server = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
496
564
 
497
565
  exports.Command = Command;
498
566
  exports.E2E = e2e;
567
+ exports.Interrupter = Interrupter;
499
568
  exports.Launch = Launch;
500
569
  exports.Operater = Operater;
501
570
  exports.Server = server;
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;
@@ -52,17 +50,41 @@ declare interface ExpectByPollingOptions {
52
50
  to?: string;
53
51
  }
54
52
 
53
+ declare type Func<T> = (_?: T) => void;
54
+
55
55
  declare const host: (force?: boolean) => string;
56
56
 
57
57
  declare const impl: () => Launch;
58
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
+
59
81
  export declare class Launch {
60
82
  browser: Browser;
61
83
  page: Page;
62
84
  operater: Operater;
63
85
  private _browser;
64
86
  private _page;
65
- puppeteerOptions: PuppeteerLaunchOptions;
87
+ puppeteerOptions: LaunchOptions;
66
88
  options: {
67
89
  logLevel?: string;
68
90
  };
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: "new"
308
+ headless: true
310
309
  });
311
310
  this._browser.then((browser) => {
312
311
  this.browser = browser;
@@ -346,6 +345,77 @@ class Launch {
346
345
  }
347
346
  }
348
347
 
348
+ class Interrupter {
349
+ static of(options) {
350
+ return new Interrupter(options);
351
+ }
352
+ options = {};
353
+ _success;
354
+ _fail;
355
+ _task;
356
+ _finish = false;
357
+ constructor(options) {
358
+ if (options) {
359
+ this.options = options;
360
+ }
361
+ this._generateTask();
362
+ }
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) => {
376
+ if (!this._finish) {
377
+ this._success?.(v);
378
+ await this._task;
379
+ await Promise.resolve();
380
+ this._generateTask();
381
+ } else {
382
+ await this._task;
383
+ }
384
+ };
385
+ nextWithError = async (v) => {
386
+ if (!this._finish) {
387
+ this._fail?.(v);
388
+ try {
389
+ await this._task;
390
+ } catch {
391
+ await Promise.resolve();
392
+ this._generateTask();
393
+ }
394
+ } else {
395
+ await this._task;
396
+ }
397
+ };
398
+ finish = (v) => {
399
+ this._success?.(v);
400
+ this._finish = true;
401
+ return this;
402
+ };
403
+ finishWithError = (v) => {
404
+ this._fail?.(v);
405
+ this._finish = true;
406
+ return this;
407
+ };
408
+ then(resolve, reject) {
409
+ return this._task.then(resolve, reject);
410
+ }
411
+ catch(callback) {
412
+ return this._task.catch(callback);
413
+ }
414
+ finally(callback) {
415
+ return this._task.finally(callback);
416
+ }
417
+ }
418
+
349
419
  const TIME_OUT = 60 * 1e3;
350
420
  const impl = () => {
351
421
  const launch = new Launch();
@@ -411,8 +481,7 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
411
481
 
412
482
  let defaultHost = "";
413
483
  const host = (force) => {
414
- if (!force && defaultHost)
415
- return defaultHost;
484
+ if (!force && defaultHost) return defaultHost;
416
485
  const ips = [];
417
486
  const ntwk = os.networkInterfaces();
418
487
  for (const k in ntwk) {
@@ -429,8 +498,7 @@ const host = (force) => {
429
498
  defaultHost = host();
430
499
  const port = (host$ = defaultHost, port$ = 1024) => {
431
500
  /* istanbul ignore next -- @preserve */
432
- if (port$ < 1024)
433
- throw new Error("port < 1024");
501
+ if (port$ < 1024) throw new Error("port < 1024");
434
502
  return new Promise((resolve, reject) => {
435
503
  const server = http.createServer();
436
504
  server.unref();
@@ -469,4 +537,4 @@ const server = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
469
537
  port
470
538
  }, Symbol.toStringTag, { value: 'Module' }));
471
539
 
472
- export { Command, e2e as E2E, Launch, Operater, server as Server, utils as Utils };
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.8.0",
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.8.0",
23
- "puppeteer": "^21.6.1"
22
+ "@deot/dev-shared": "^2.9.0",
23
+ "puppeteer": "^24.2.0"
24
24
  }
25
25
  }