@@ -273,14 +273,25 @@ module.exports = (testplane, opts) => {
273
273
У раннера тестов есть метод ` registerWorkers ` , который регистрирует код плагина для параллельного выполнения в воркерах testplane. Метод принимает следующие параметры:
274
274
275
275
<table >
276
- <thead >
277
- <tr ><td >** Параметр** </td ><td >** Тип** </td ><td >** Описание** </td ></tr >
278
- </thead >
279
- <tbody >
280
- <tr ><td >workerFilepath</td ><td >String</td ><td >Абсолютный путь к воркеру.</td ></tr >
281
- <tr ><td >exportedMethods</td ><td >String[ ] </td ><td >Список экспортируемых методов.</td ></tr >
282
-
283
- </tbody >
276
+ <thead >
277
+ <tr >
278
+ <td >>** Параметр** </td >
279
+ <td >** Тип** </td >
280
+ <td >** Описание** </td >
281
+ </tr >
282
+ </thead >
283
+ <tbody >
284
+ <tr >
285
+ <td >>workerFilepath</td >
286
+ <td >String</td >
287
+ <td >Абсолютный путь к воркеру.</td >
288
+ </tr >
289
+ <tr >
290
+ <td >>exportedMethods</td >
291
+ <td >String[ ] </td >
292
+ <td >Список экспортируемых методов.</td >
293
+ </tr >
294
+ </tbody >
284
295
</table >
285
296
286
297
При этом возвращает объект, который содержит асинхронные функции с именами из экспортированных методов.
@@ -360,22 +371,22 @@ testplane.on(testplane.events.CLI, cli => {
360
371
</summary >
361
372
362
373
``` javascript
363
- const parseConfig = require (' ./config' );
374
+ const parseConfig = require (" ./config" );
364
375
365
376
module .exports = (testplane , opts ) => {
366
377
const pluginConfig = parseConfig (opts);
367
378
368
- if (! pluginConfig .enabled < tr >< td > testplane .isWorker ()) {
379
+ if (! pluginConfig .enabled || testplane .isWorker ()) {
369
380
// или плагин отключен, или мы находимся в контексте воркера – уходим
370
381
return ;
371
382
}
372
383
373
- testplane .on (testplane .events .CLI , ( cli ) => {
384
+ testplane .on (testplane .events .CLI , cli => {
374
385
// добавляем опцию --repeat
375
386
cli .option (
376
- ' --repeat <number>' ,
377
- ' how many times tests should be repeated regardless of the result' ,
378
- ( value ) => parseNonNegativeInteger (value, ' repeat' )
387
+ " --repeat <number>" ,
388
+ " how many times tests should be repeated regardless of the result" ,
389
+ value => parseNonNegativeInteger (value, " repeat" ),
379
390
);
380
391
});
381
392
@@ -422,13 +433,13 @@ testplane.on(testplane.events.INIT, async () => {
422
433
</summary >
423
434
424
435
``` javascript
425
- const http = require (' http' );
426
- const parseConfig = require (' ./config' );
436
+ const http = require (" http" );
437
+ const parseConfig = require (" ./config" );
427
438
428
439
module .exports = (testplane , opts ) => {
429
440
const pluginConfig = parseConfig (opts);
430
441
431
- if (! pluginConfig .enabled < / td >< / tr > testplane .isWorker ()) {
442
+ if (! pluginConfig .enabled || testplane .isWorker ()) {
432
443
// или плагин отключен, или мы находимся в контексте воркера – уходим
433
444
return ;
434
445
}
@@ -437,12 +448,10 @@ module.exports = (testplane, opts) => {
437
448
438
449
testplane .on (testplane .events .INIT , () => {
439
450
// контент, который отдает dev-сервер
440
- const content = ' <h1>Hello, World!</h1>' ;
451
+ const content = " <h1>Hello, World!</h1>" ;
441
452
442
453
// создаем сервер и начинаем слушать порт 3000
443
- http
444
- .createServer ((req , res ) => res .end (content))
445
- .listen (3000 );
454
+ http .createServer ((req , res ) => res .end (content)).listen (3000 );
446
455
447
456
// по адресу http://localhost:3000/index.html будет отдаваться: <h1>Hello, World!</h1>
448
457
});
@@ -1495,45 +1504,43 @@ module.exports = (testplane, opts) => {
1495
1504
** Код плагина**
1496
1505
1497
1506
``` javascript
1498
- const http = require (' http' );
1499
- const parseConfig = require (' ./config' );
1507
+ const http = require (" http" );
1508
+ const parseConfig = require (" ./config" );
1500
1509
1501
1510
module .exports = (testplane , opts ) => {
1502
1511
const pluginConfig = parseConfig (opts);
1503
1512
1504
- if (! pluginConfig .enabled < tr >< td > testplane .isWorker ()) {
1513
+ if (! pluginConfig .enabled || testplane .isWorker ()) {
1505
1514
// или плагин отключен, или мы находимся в контексте воркера – уходим
1506
1515
return ;
1507
1516
}
1508
1517
1509
1518
let program;
1510
1519
1511
- testplane .on (testplane .events .CLI , ( cli ) => {
1520
+ testplane .on (testplane .events .CLI , cli => {
1512
1521
// нужно сохранить ссылку на инстанс commander'а (https://github.com/tj/commander.js),
1513
1522
// чтобы потом проверить наличие опции
1514
1523
program = cli;
1515
1524
// добавляем к testplane опцию --dev-server,
1516
1525
// чтобы пользователь мог явно указывать, когда надо запустить dev-сервер
1517
- cli .option (' --dev-server' , ' run dev-server' );
1526
+ cli .option (" --dev-server" , " run dev-server" );
1518
1527
});
1519
1528
1520
1529
testplane .on (testplane .events .INIT , () => {
1521
1530
// dev-сервер может быть запущен как через указание опции --dev-server
1522
1531
// при запуске testplane, так и в настройках плагина
1523
- const devServer = program && program .devServer < / td >< / tr > pluginConfig .devServer ;
1532
+ const devServer = ( program && program .devServer ) || pluginConfig .devServer ;
1524
1533
1525
1534
if (! devServer) {
1526
1535
// если dev-сервер запускать не нужно – уходим
1527
1536
return ;
1528
1537
}
1529
1538
1530
1539
// контент, который отдает dev-сервер
1531
- const content = ' <h1>Hello, World!</h1>' ;
1540
+ const content = " <h1>Hello, World!</h1>" ;
1532
1541
1533
1542
// создаем сервер и начинаем слушать порт 3000
1534
- http
1535
- .createServer ((req , res ) => res .end (content))
1536
- .listen (3000 );
1543
+ http .createServer ((req , res ) => res .end (content)).listen (3000 );
1537
1544
1538
1545
// по адресу http://localhost:3000/index.html будет отдаваться: <h1>Hello, World!</h1>
1539
1546
});
0 commit comments