# All files index.ts

54.96% Statements 83/151
15.62% Branches 10/64
43.47% Functions 20/46
59.12% Lines 81/137

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    2921x
    1x
    1x
    1x
    1x

    1x
    1x
    1x

    1x
    1x

    1x

    1x

    1x

    1x

    1x

    1x
    1x
    1x
    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x

    1x
    1x
    1x
    1x
    1x

    1x
    1x
    1x
    1x

    1x
    14x

    14x
    14x
    14x

    1x

    2x
    2x

    1x

    1x

    1x

    1x

    1x

    1x

    2x
    2x

    1x

    2x
    2x

    1x

    2x
    2x

    1x

    1x

    1x

    1x

    2x
    2x

    1x

    2x
    2x

    1x

    2x
    2x

    1x

    2x
    2x

    1x

    1x

     import 'reflect-metadata';
    import { create } from '@biorate/symbolic';
    import { object as o } from '@biorate/tools';
    import { test as t } from '@playwright/test';
    import { allure } from 'allure-playwright';

    export * from 'allure-playwright';
    export * from 'playwright';
    export * from '@playwright/test';

    export class PlayWright {
      protected static Symbols = create('PlayWright');

      protected static Test = this.Symbols.Test;

      protected static SuiteOptions = this.Symbols.SuiteOptions;

      protected static AllureOptions = this.Symbols.AllureOptions;

      protected static Skip = this.Symbols.Skip;

      protected static Only = this.Symbols.Only;

      public readonly suite;

      public readonly test;

      public readonly skip;

      public readonly only;

      public readonly label;

      public readonly link;

      public readonly id;

      public readonly epic;

      public readonly feature;

      public readonly story;

      public readonly allureSuite;

      public readonly parentSuite;

      public readonly subSuite;

      public readonly owner;

      public readonly severity;

      public readonly tag;

      public readonly issue;

      public readonly description;

      public constructor() {
        this.suite = this.#suite;
        this.test = this.#test;
        this.skip = this.#skip;
        this.only = this.#only;

        this.label = this.#label;
        this.link = this.#link;
        this.id = this.#id;
        this.epic = this.#epic;
        this.feature = this.#feature;
        this.story = this.#story;
        this.allureSuite = this.#allureSuite;
        this.parentSuite = this.#parentSuite;
        this.subSuite = this.#subSuite;
        this.owner = this.#owner;
        this.severity = this.#severity;
        this.tag = this.#tag;
        this.issue = this.#issue;
        this.description = this.#description;
      }

      protected walkProto(instance: any) {
        const methods = new Set();
        o.walkProto(instance, (object: any) => {
          const names = Object.getOwnPropertyNames(object);
          for (const name of names) {
            if (methods.has(name)) return;
            methods.add(name);
            this.before(name, instance);
            this.after(name, instance);
            const descriptor = Object.getOwnPropertyDescriptor(object, name);
            const meta = Reflect.getMetadata(PlayWright.Test, descriptor?.value);
            if (!meta) continue;
            const allureMethods = Reflect.getMetadata(
              PlayWright.AllureOptions,
              descriptor?.value,
            );
            const skip = Reflect.getMetadata(PlayWright.Skip, descriptor?.value);
            const only = Reflect.getMetadata(PlayWright.Only, descriptor?.value);
            if (skip && only)
              throw new Error(`Can't use both "@skip()" and "@only()" decorators`);
            let test: any = t;
            if (skip) test = t.skip;
            else if (only) test = t.only;
            // @ts-ignore
            test(meta.name ?? name, async function ({ page }, testInfo) {
              for (const method in allureMethods) {
                if (method in allure) {
                  // @ts-ignore
                  await allure[method](...allureMethods[method]);
                }
              }
              await instance[name]({ page }, testInfo);
            });
          }
        });
      }

      #suite = (name?: string) => (Class: any) => {
        const self = this;
        const skip = Reflect.getMetadata(PlayWright.Skip, Class);
        const only = Reflect.getMetadata(PlayWright.Only, Class);
        Iif (skip && only)
          throw new Error(`Can't use both "@skip()" and "@only()" decorators`);
        let describe: any = t.describe;
        Iif (skip) describe = t.describe.skip;
        else Iif (only) describe = t.describe.only;
        describe(name ?? Class.name, function () {
          const instance = new Class();
          const options = Reflect.getMetadata(PlayWright.SuiteOptions, Class);
          for (const name in options) {
            // @ts-ignore
            if (!(name in this)) continue;
            // @ts-ignore
            if (typeof this[name] === 'function') this[name](options[name]);
            // @ts-ignore
            else this[name] = options[name];
          }
          self.beforeAll(Class);
          self.walkProto(instance);
          self.afterAll(Class);
        });
      };

      #setAllureMethod = (target: any, method: string, args: string[]) => {
        let allureOptions: Record<string, string[]> | undefined = Reflect.getMetadata(
          PlayWright.AllureOptions,
          target,
        );
        if (!allureOptions) allureOptions = {};
        allureOptions[method] = args;
        Reflect.defineMetadata(PlayWright.AllureOptions, allureOptions, target);
      };

      #test =
        (name?: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) =>
          Reflect.defineMetadata(PlayWright.Test, { name }, target);

      #skip =
        () =>
        (target: any, ...args: any[]) => {
          Reflect.defineMetadata(PlayWright.Skip, true, target);
        };

      #only =
        () =>
        (target: any, ...args: any[]) =>
          Reflect.defineMetadata(PlayWright.Only, true, target);

      #label =
        (name: string, value: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'label', [name, value]);
        };

      #link =
        (url: string, name: string, type?: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'link', type ? [url, name, type] : [url, name]);
        };

      #id =
        (id: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'id', [id]);
        };

      #epic =
        (epic: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'epic', [epic]);
        };

      #feature =
        (epic: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'feature', [epic]);
        };

      #story =
        (story: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'story', [story]);
        };

      #allureSuite =
        (name: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'suite', [name]);
        };

      #parentSuite =
        (name: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'parentSuite', [name]);
        };

      #subSuite =
        (name: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'subSuite', [name]);
        };

      #owner =
        (name: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'owner', [name]);
        };

      #severity =
        (severity: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'severity', [severity]);
        };

      #tag =
        (tag: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'tag', [tag]);
        };

      #issue =
        (name: string, url?: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'issue', url ? [name, url] : [name]);
        };

      #description =
        (value: string) =>
        (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
          this.#setAllureMethod(target, 'description', [value]);
        };

      protected before(name: string, instance: any) {
        if (name === this.before.name) t.beforeEach(instance[name].bind(instance));
      }

      protected after(name: string, instance: any) {
        if (name === this.after.name) t.afterEach(instance[name].bind(instance));
      }

      protected beforeAll(Class: any) {
        if (Class.before) t.beforeAll(Class.before.bind(Class));
      }

      protected afterAll(Class: any) {
        if (Class.after) t.afterAll(Class.after.bind(Class));
      }
    }

    export const {
      suite,
      skip,
      only,
      test,
      label,
      link,
      id,
      epic,
      feature,
      story,
      allureSuite,
      parentSuite,
      subSuite,
      owner,
      severity,
      tag,
      description,
      issue,
    } = new PlayWright();