testit-adapter-codecept 2.2.6 → 3.0.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/README.md CHANGED
@@ -107,6 +107,24 @@ $ testit testrun complete
107
107
  --testrun-id $(cat tmp/output.txt)
108
108
  ```
109
109
 
110
+ #### Run with filter
111
+ To create filter by autotests you can use the Test IT CLI (use adapterMode 1 for run with filter):
112
+
113
+ ```
114
+ $ export TMS_TOKEN=<YOUR_TOKEN>
115
+ $ testit autotests_filter
116
+ --url https://tms.testit.software \
117
+ --configuration-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
118
+ --testrun-id 6d4ac4b7-dd67-4805-b879-18da0b89d4a8 \
119
+ --framework codeceptjs \
120
+ --output tmp/filter.txt
121
+
122
+ $ export TMS_TEST_RUN_ID=6d4ac4b7-dd67-4805-b879-18da0b89d4a8
123
+ $ export TMS_ADAPTER_MODE=1
124
+
125
+ $ npx codeceptjs run --grep "$(cat tmp/filter.txt)"
126
+ ```
127
+
110
128
  ### Methods
111
129
 
112
130
  Methods can be used to specify information about autotest.
@@ -2,28 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const codeceptjs_1 = require("codeceptjs");
4
4
  const testit_js_commons_1 = require("testit-js-commons");
5
- const classes_1 = require("./common/classes");
6
- const strategies_1 = require("./strategies");
5
+ const builders_1 = require("./builders");
6
+ const utils_1 = require("./common/utils");
7
7
  module.exports = async function (options) {
8
- var _a;
9
8
  const config = new testit_js_commons_1.ConfigComposer().compose();
10
- const client = new testit_js_commons_1.Client(config);
11
- const logger = new classes_1.Logger((_a = options.__DEV) !== null && _a !== void 0 ? _a : false);
12
- const strategy = strategies_1.StrategyFactory.create(client, logger, config);
9
+ const strategy = testit_js_commons_1.StrategyFactory.create(config);
13
10
  const helper = codeceptjs_1.container.helpers("TestITHelper");
14
- await strategy.bootstrap();
15
- codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.after, (test) => {
16
- strategy.collect(test.id, helper.metadata);
17
- helper.metadata = {};
18
- });
19
- codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.before, async (test) => {
20
- await strategy.beforeTest(test);
21
- });
11
+ await strategy.setup();
22
12
  codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.finished, (test) => {
23
13
  codeceptjs_1.recorder.add("transferTestAndRuns", async () => {
24
- const suite = { tests: [test] };
25
- await strategy.transferTestsToSystem(suite);
26
- await strategy.transferRunsToSystem(suite);
14
+ const autotest = builders_1.TestsBuilder.build(test);
15
+ await strategy.loadAutotest(autotest, (0, utils_1.isPassed)(test));
16
+ const result = await new builders_1.ResultBuilder(config).build(test, helper.metadata);
17
+ await strategy.loadTestRun([result]);
18
+ helper.metadata = {};
27
19
  });
28
20
  });
29
21
  codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.workers.after, async () => {
@@ -1,2 +1,2 @@
1
- export { RunsBuilder } from "./run.builder";
1
+ export { ResultBuilder } from "./result.builder";
2
2
  export { TestsBuilder } from "./test.builder";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TestsBuilder = exports.RunsBuilder = void 0;
4
- var run_builder_1 = require("./run.builder");
5
- Object.defineProperty(exports, "RunsBuilder", { enumerable: true, get: function () { return run_builder_1.RunsBuilder; } });
3
+ exports.TestsBuilder = exports.ResultBuilder = void 0;
4
+ var result_builder_1 = require("./result.builder");
5
+ Object.defineProperty(exports, "ResultBuilder", { enumerable: true, get: function () { return result_builder_1.ResultBuilder; } });
6
6
  var test_builder_1 = require("./test.builder");
7
7
  Object.defineProperty(exports, "TestsBuilder", { enumerable: true, get: function () { return test_builder_1.TestsBuilder; } });
@@ -1,9 +1,11 @@
1
- import { AdapterConfig, Attachment, AutotestResult } from "testit-js-commons";
1
+ import { AdapterConfig, Additions, AutotestResult } from "testit-js-commons";
2
2
  import { Codecept, Origin } from "../types";
3
- export declare class RunsBuilder {
3
+ export declare class ResultBuilder {
4
4
  private readonly config;
5
+ additions: Additions;
5
6
  constructor(config: AdapterConfig);
6
- build(test: Codecept.Test<Origin.TestConfig>, metadata: Origin.TestMetadata, attachments: Attachment[]): AutotestResult;
7
+ build(test: Codecept.Test<Origin.TestConfig>, metadata: Origin.TestMetadata): Promise<AutotestResult>;
8
+ private loadAttachments;
7
9
  private buildManySteps;
8
10
  private reduceAfterOrBeforeSuites;
9
11
  }
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RunsBuilder = void 0;
3
+ exports.ResultBuilder = void 0;
4
+ const testit_js_commons_1 = require("testit-js-commons");
4
5
  const utils_1 = require("../common/utils");
5
- class RunsBuilder {
6
+ class ResultBuilder {
6
7
  constructor(config) {
7
8
  this.config = config;
9
+ this.additions = new testit_js_commons_1.Additions(config);
8
10
  }
9
- build(test, metadata, attachments) {
11
+ async build(test, metadata) {
10
12
  var _a, _b, _c, _d, _e, _f, _g, _h;
11
13
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
14
  // @ts-ignore
@@ -25,7 +27,7 @@ class RunsBuilder {
25
27
  links: metadata === null || metadata === void 0 ? void 0 : metadata.links,
26
28
  startedOn: new Date(test.startedAt),
27
29
  duration: test.duration,
28
- attachments,
30
+ attachments: await this.loadAttachments(test, metadata),
29
31
  parameters,
30
32
  traces: typeof ((_f = test === null || test === void 0 ? void 0 : test.err) === null || _f === void 0 ? void 0 : _f.cliMessage) === "function" ? test.err.cliMessage() : (_g = test === null || test === void 0 ? void 0 : test.err) === null || _g === void 0 ? void 0 : _g.stack,
31
33
  teardownResults,
@@ -36,6 +38,21 @@ class RunsBuilder {
36
38
  stepResults: this.buildManySteps(test.steps),
37
39
  };
38
40
  }
41
+ async loadAttachments(test, metadata) {
42
+ var _a, _b, _c;
43
+ const screenshot = (_a = test.artifacts) === null || _a === void 0 ? void 0 : _a.screenshot;
44
+ const clientUrls = (_b = metadata.attachments) !== null && _b !== void 0 ? _b : [];
45
+ if (screenshot) {
46
+ clientUrls.push(screenshot);
47
+ }
48
+ const attachments = await this.additions.addAttachments(clientUrls);
49
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.text) {
50
+ const attach = await this.additions.addAttachments(metadata.text.content, (_c = metadata.text) === null || _c === void 0 ? void 0 : _c.name);
51
+ attachments.push(...attach);
52
+ }
53
+ this.additions.clear();
54
+ return attachments;
55
+ }
39
56
  buildManySteps(steps) {
40
57
  return steps === null || steps === void 0 ? void 0 : steps.map((step) => ({
41
58
  title: `${step.name} ${(0, utils_1.humanize)(step.args).join(",")}`.trim(),
@@ -50,4 +67,4 @@ class RunsBuilder {
50
67
  return suite.reduce((array, suite) => { var _a; return [...array, ...this.buildManySteps((_a = suite === null || suite === void 0 ? void 0 : suite.steps) !== null && _a !== void 0 ? _a : [])]; }, []);
51
68
  }
52
69
  }
53
- exports.RunsBuilder = RunsBuilder;
70
+ exports.ResultBuilder = ResultBuilder;
@@ -1,9 +1,7 @@
1
1
  import { Codecept, Origin } from "../types";
2
- import { AdapterConfig, AutotestPost } from "testit-js-commons";
2
+ import { AutotestPost } from "testit-js-commons";
3
3
  export declare class TestsBuilder {
4
- private readonly config;
5
- constructor(config: AdapterConfig);
6
- build(test: Codecept.Test<Origin.TestConfig>): AutotestPost;
7
- private buildManySteps;
8
- private reduceAfterOrBeforeSuites;
4
+ static build(test: Codecept.Test<Origin.TestConfig>): AutotestPost;
5
+ private static buildManySteps;
6
+ private static reduceAfterOrBeforeSuites;
9
7
  }
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TestsBuilder = void 0;
4
4
  const utils_1 = require("../common/utils");
5
5
  class TestsBuilder {
6
- constructor(config) {
7
- this.config = config;
8
- }
9
- build(test) {
6
+ static build(test) {
10
7
  var _a, _b, _c, _d, _e;
11
8
  const config = (0, utils_1.useConfig)(test);
12
9
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -26,15 +23,16 @@ class TestsBuilder {
26
23
  externalId: (_e = (0, utils_1.useDefaultHash)(test)) !== null && _e !== void 0 ? _e : (0, utils_1.useCompositeHash)(test),
27
24
  namespace: config === null || config === void 0 ? void 0 : config.nameSpace,
28
25
  classname: config === null || config === void 0 ? void 0 : config.className,
26
+ externalKey: test.title,
29
27
  };
30
28
  }
31
- buildManySteps(steps = []) {
29
+ static buildManySteps(steps = []) {
32
30
  return steps.map((step) => ({
33
31
  title: `${step.name} ${(0, utils_1.humanize)(step.args).join(",")}`.trim(),
34
32
  description: "",
35
33
  }));
36
34
  }
37
- reduceAfterOrBeforeSuites(suite) {
35
+ static reduceAfterOrBeforeSuites(suite) {
38
36
  return suite.reduce((array, suite) => { var _a; return [...array, ...this.buildManySteps((_a = suite === null || suite === void 0 ? void 0 : suite.steps) !== null && _a !== void 0 ? _a : [])]; }, []);
39
37
  }
40
38
  }
@@ -1,3 +1,2 @@
1
- export * from "./strategy.type";
2
1
  export * from "./origin.type";
3
2
  export * from "./codecept.type";
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./strategy.type"), exports);
18
17
  __exportStar(require("./origin.type"), exports);
19
18
  __exportStar(require("./codecept.type"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-adapter-codecept",
3
- "version": "2.2.6",
3
+ "version": "3.0.0",
4
4
  "description": "Codecept adapter for Test IT",
5
5
  "keywords": [],
6
6
  "author": {
@@ -15,7 +15,7 @@
15
15
  "watch": "tsc -p tsconfig.json -w"
16
16
  },
17
17
  "dependencies": {
18
- "testit-js-commons": "~2.2.6"
18
+ "testit-js-commons": "~3.0.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@codeceptjs/configure": "^0.10.0",
@@ -1,5 +0,0 @@
1
- export declare class Box<T> {
2
- private readonly box;
3
- collectWithMerge(id: string, entity: T): void;
4
- get(id: string): T;
5
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Box = void 0;
4
- class Box {
5
- constructor() {
6
- this.box = new Map;
7
- }
8
- collectWithMerge(id, entity) {
9
- const collected = this.box.get(id);
10
- this.box.set(id, collected
11
- ? { ...collected, ...entity }
12
- : entity);
13
- }
14
- get(id) {
15
- return this.box.get(id);
16
- }
17
- }
18
- exports.Box = Box;
@@ -1,2 +0,0 @@
1
- export { Box } from "./box.class";
2
- export { Logger } from "./logger.class";
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Logger = exports.Box = void 0;
4
- var box_class_1 = require("./box.class");
5
- Object.defineProperty(exports, "Box", { enumerable: true, get: function () { return box_class_1.Box; } });
6
- var logger_class_1 = require("./logger.class");
7
- Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_class_1.Logger; } });
@@ -1,9 +0,0 @@
1
- import { AxiosError } from "axios";
2
- export declare class Logger {
3
- private readonly __DEV;
4
- private readonly logger;
5
- constructor(__DEV?: boolean);
6
- log(message: string): void;
7
- warn(message: string): void;
8
- error(error: AxiosError | string): void;
9
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Logger = void 0;
4
- const codeceptjs_1 = require("codeceptjs");
5
- class Logger {
6
- constructor(__DEV = false) {
7
- this.__DEV = __DEV;
8
- this.logger = codeceptjs_1.output;
9
- }
10
- log(message) {
11
- if (this.__DEV) {
12
- this.logger.success(message);
13
- }
14
- }
15
- warn(message) {
16
- this.logger.error(message);
17
- }
18
- error(error) {
19
- var _a, _b, _c, _d;
20
- if (typeof error === "string") {
21
- this.logger.error(error);
22
- }
23
- else {
24
- this.logger.error(`
25
- ${(_a = error.response) === null || _a === void 0 ? void 0 : _a.status},
26
- ${(_b = error.config) === null || _b === void 0 ? void 0 : _b.method},
27
- ${(_c = error.config) === null || _c === void 0 ? void 0 : _c.url},
28
- ${JSON.stringify((_d = error.response) === null || _d === void 0 ? void 0 : _d.data)}
29
- `);
30
- }
31
- }
32
- }
33
- exports.Logger = Logger;
@@ -1,17 +0,0 @@
1
- import { AdapterConfig, IClient } from "testit-js-commons";
2
- import { Box, Logger } from "../common/classes";
3
- import { RunsBuilder, TestsBuilder } from "../builders";
4
- import { Codecept, Origin } from "../types";
5
- export declare abstract class BaseStrategy {
6
- protected readonly http: IClient;
7
- protected readonly logger: Logger;
8
- protected readonly config: AdapterConfig;
9
- protected readonly testsBuilder: TestsBuilder;
10
- protected readonly runsBuilder: RunsBuilder;
11
- protected readonly box: Box<Origin.TestMetadata>;
12
- protected constructor(http: IClient, logger: Logger, config: AdapterConfig);
13
- collect(id: string, metadata: Origin.TestMetadata): void;
14
- connectToTest(externalId: string, test: Codecept.Test): Promise<void>;
15
- beforeTest(test: Codecept.Test): Promise<void>;
16
- createOrUpdateTests(suite: any): Promise<void>;
17
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseStrategy = void 0;
4
- const classes_1 = require("../common/classes");
5
- const utils_1 = require("../common/utils");
6
- const builders_1 = require("../builders");
7
- class BaseStrategy {
8
- constructor(http, logger, config) {
9
- this.http = http;
10
- this.logger = logger;
11
- this.config = config;
12
- this.testsBuilder = new builders_1.TestsBuilder(this.config);
13
- this.runsBuilder = new builders_1.RunsBuilder(this.config);
14
- this.box = new classes_1.Box();
15
- }
16
- collect(id, metadata) {
17
- this.box.collectWithMerge(id, metadata);
18
- }
19
- async connectToTest(externalId, test) {
20
- const config = (0, utils_1.useConfig)(test);
21
- const ids = (config === null || config === void 0 ? void 0 : config.workitemIds) || [];
22
- await this.http.autoTests.linkToWorkItems(externalId, ids);
23
- }
24
- beforeTest(test) {
25
- return Promise.resolve();
26
- }
27
- async createOrUpdateTests(suite) {
28
- for (const test of suite.tests) {
29
- const hasPassedState = (0, utils_1.isPassed)(test);
30
- const testToOriginSystem = this.testsBuilder.build(test);
31
- await this.http.autoTests.loadAutotest(testToOriginSystem, hasPassedState).catch((err) => {
32
- console.log("Error load autotest. \n", err);
33
- });
34
- await this.connectToTest(testToOriginSystem.externalId, test).catch((err) => {
35
- console.log("Error link work item. \n", err);
36
- });
37
- }
38
- }
39
- }
40
- exports.BaseStrategy = BaseStrategy;
@@ -1,14 +0,0 @@
1
- import { AdapterConfig, IClient } from "testit-js-commons";
2
- import { BaseStrategy } from "./base.strategy";
3
- import { Logger } from "../common/classes";
4
- import { Strategy } from "../types";
5
- export declare class DefaultStrategy extends BaseStrategy implements Strategy {
6
- protected readonly http: IClient;
7
- protected readonly logger: Logger;
8
- protected readonly config: AdapterConfig;
9
- constructor(http: IClient, logger: Logger, config: AdapterConfig);
10
- bootstrap(): Promise<void>;
11
- teardown(): Promise<void>;
12
- transferTestsToSystem(suite: any): Promise<void>;
13
- transferRunsToSystem(suite: any): Promise<void>;
14
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultStrategy = void 0;
4
- const base_strategy_1 = require("./base.strategy");
5
- // Adapter mode 1
6
- class DefaultStrategy extends base_strategy_1.BaseStrategy {
7
- constructor(http, logger, config) {
8
- super(http, logger, config);
9
- this.http = http;
10
- this.logger = logger;
11
- this.config = config;
12
- }
13
- async bootstrap() {
14
- if (!this.config.testRunId) {
15
- this.logger.error("Test run id is required when adapter mode is 1");
16
- process.exit(1);
17
- }
18
- await this.http.testRuns.startTestRun(this.config.testRunId);
19
- }
20
- async teardown() {
21
- await this.http.testRuns.completeTestRun(this.config.testRunId);
22
- }
23
- async transferTestsToSystem(suite) {
24
- await this.createOrUpdateTests(suite);
25
- }
26
- async transferRunsToSystem(suite) {
27
- var _a, _b, _c;
28
- for (const test of suite.tests) {
29
- const config = this.box.get(test.id);
30
- const screenshot = (_a = test.artifacts) === null || _a === void 0 ? void 0 : _a.screenshot;
31
- const clientUrls = (_b = config === null || config === void 0 ? void 0 : config.attachments) !== null && _b !== void 0 ? _b : [];
32
- if (screenshot) {
33
- clientUrls.push(screenshot);
34
- }
35
- const attachments = await this.http.attachments.uploadAttachments(clientUrls);
36
- if (config === null || config === void 0 ? void 0 : config.text) {
37
- const attach = await this.http.attachments.uploadTextAttachment(config.text.content, (_c = config.text) === null || _c === void 0 ? void 0 : _c.name);
38
- attachments.push(...attach);
39
- }
40
- const run = this.runsBuilder.build(test, config, attachments);
41
- await this.http.testRuns.loadAutotests(this.config.testRunId, [run]);
42
- }
43
- this.logger.log(`Test run - ${this.config.testRunId} transferred to remote system`);
44
- }
45
- }
46
- exports.DefaultStrategy = DefaultStrategy;
@@ -1,5 +0,0 @@
1
- export { BaseStrategy } from "./base.strategy";
2
- export { DefaultStrategy } from "./default.strategy";
3
- export { PartialStrategy } from "./partial.strategy";
4
- export { ScratchStrategy } from "./scratch.strategy";
5
- export { AdapterMode, StrategyFactory } from "./strategy.factory";
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StrategyFactory = exports.ScratchStrategy = exports.PartialStrategy = exports.DefaultStrategy = exports.BaseStrategy = void 0;
4
- var base_strategy_1 = require("./base.strategy");
5
- Object.defineProperty(exports, "BaseStrategy", { enumerable: true, get: function () { return base_strategy_1.BaseStrategy; } });
6
- var default_strategy_1 = require("./default.strategy");
7
- Object.defineProperty(exports, "DefaultStrategy", { enumerable: true, get: function () { return default_strategy_1.DefaultStrategy; } });
8
- var partial_strategy_1 = require("./partial.strategy");
9
- Object.defineProperty(exports, "PartialStrategy", { enumerable: true, get: function () { return partial_strategy_1.PartialStrategy; } });
10
- var scratch_strategy_1 = require("./scratch.strategy");
11
- Object.defineProperty(exports, "ScratchStrategy", { enumerable: true, get: function () { return scratch_strategy_1.ScratchStrategy; } });
12
- var strategy_factory_1 = require("./strategy.factory");
13
- Object.defineProperty(exports, "StrategyFactory", { enumerable: true, get: function () { return strategy_factory_1.StrategyFactory; } });
@@ -1,18 +0,0 @@
1
- /// <reference types="codeceptjs" />
2
- import { AdapterConfig, IClient } from "testit-js-commons";
3
- import { Logger } from "../common/classes";
4
- import { BaseStrategy } from "./base.strategy";
5
- import { Codecept, Strategy } from "../types";
6
- export declare class PartialStrategy extends BaseStrategy implements Strategy {
7
- protected readonly http: IClient;
8
- protected readonly logger: Logger;
9
- protected readonly config: AdapterConfig;
10
- private readonly testsInRun;
11
- constructor(http: IClient, logger: Logger, config: AdapterConfig);
12
- bootstrap(): Promise<void>;
13
- teardown(): Promise<void>;
14
- private getTestsIdsInRun;
15
- beforeTest(test: Codecept.Test): Promise<void>;
16
- transferRunsToSystem(suite: any): Promise<void>;
17
- transferTestsToSystem(suite: Mocha.Suite): Promise<void>;
18
- }
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartialStrategy = void 0;
4
- const utils_1 = require("../common/utils");
5
- const base_strategy_1 = require("./base.strategy");
6
- // Adapter mode 0
7
- class PartialStrategy extends base_strategy_1.BaseStrategy {
8
- constructor(http, logger, config) {
9
- super(http, logger, config);
10
- this.http = http;
11
- this.logger = logger;
12
- this.config = config;
13
- this.testsInRun = this.http.testRuns.getAutotests(this.config.testRunId);
14
- }
15
- async bootstrap() {
16
- if (!this.config.testRunId) {
17
- this.logger.error("Test run id is required when adapter mode is 0");
18
- process.exit(1);
19
- }
20
- await this.http.testRuns.startTestRun(this.config.testRunId);
21
- }
22
- async teardown() {
23
- await this.http.testRuns.completeTestRun(this.config.testRunId);
24
- }
25
- async getTestsIdsInRun() {
26
- const tests = await this.testsInRun;
27
- return tests === null || tests === void 0 ? void 0 : tests.map((test) => test.autoTest.externalId);
28
- }
29
- async beforeTest(test) {
30
- var _a;
31
- const tests = await this.getTestsIdsInRun();
32
- const hash = (_a = (0, utils_1.useDefaultHash)(test)) !== null && _a !== void 0 ? _a : (0, utils_1.useCompositeHash)(test);
33
- if (!tests.includes(hash.toString())) {
34
- test.run = () => test.skip();
35
- }
36
- }
37
- async transferRunsToSystem(suite) {
38
- var _a, _b;
39
- const tests = await this.getTestsIdsInRun();
40
- const data = await Promise.all((_b = (_a = suite.tests) === null || _a === void 0 ? void 0 : _a.filter((test) => {
41
- var _a;
42
- const hash = (_a = (0, utils_1.useDefaultHash)(test)) !== null && _a !== void 0 ? _a : (0, utils_1.useCompositeHash)(test);
43
- return tests.includes(hash.toString());
44
- })) === null || _b === void 0 ? void 0 : _b.map(async (test) => {
45
- var _a, _b, _c;
46
- const config = this.box.get(test.id);
47
- const screenshot = (_a = test.artifacts) === null || _a === void 0 ? void 0 : _a.screenshot;
48
- const clientUrls = (_b = config === null || config === void 0 ? void 0 : config.attachments) !== null && _b !== void 0 ? _b : [];
49
- if (screenshot) {
50
- clientUrls.push(screenshot);
51
- }
52
- const attachments = await this.http.attachments.uploadAttachments(clientUrls);
53
- if (config === null || config === void 0 ? void 0 : config.text) {
54
- const attach = await this.http.attachments.uploadTextAttachment(config.text.content, (_c = config.text) === null || _c === void 0 ? void 0 : _c.name);
55
- attachments.push(...attach);
56
- }
57
- return this.runsBuilder.build(test, config, attachments);
58
- }));
59
- if (data.length) {
60
- await this.http.testRuns.loadAutotests(this.config.testRunId, data);
61
- this.logger.log(`Test run - ${this.config.testRunId} transferred to remote system`);
62
- }
63
- }
64
- async transferTestsToSystem(suite) {
65
- const tests = await this.testsInRun;
66
- const suiteWithNeededTests = {
67
- ...suite,
68
- tests: suite.tests.filter((test) => {
69
- var _a;
70
- const hash = (_a = (0, utils_1.useDefaultHash)(test)) !== null && _a !== void 0 ? _a : (0, utils_1.useCompositeHash)(test);
71
- return tests.includes(hash.toString());
72
- }),
73
- };
74
- await this.createOrUpdateTests(suiteWithNeededTests);
75
- }
76
- }
77
- exports.PartialStrategy = PartialStrategy;
@@ -1,16 +0,0 @@
1
- /// <reference types="codeceptjs" />
2
- import { AdapterConfig, IClient } from "testit-js-commons";
3
- import { BaseStrategy } from "./base.strategy";
4
- import { Logger } from "../common/classes";
5
- import { Strategy } from "../types";
6
- export declare class ScratchStrategy extends BaseStrategy implements Strategy {
7
- protected readonly http: IClient;
8
- protected readonly logger: Logger;
9
- protected readonly config: AdapterConfig;
10
- private testRunId;
11
- constructor(http: IClient, logger: Logger, config: AdapterConfig);
12
- bootstrap(): Promise<void>;
13
- teardown(): Promise<void>;
14
- transferTestsToSystem(suite: Mocha.Suite): Promise<void>;
15
- transferRunsToSystem(suite: any): Promise<void>;
16
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ScratchStrategy = void 0;
4
- const base_strategy_1 = require("./base.strategy");
5
- // Adapter mode 2
6
- class ScratchStrategy extends base_strategy_1.BaseStrategy {
7
- constructor(http, logger, config) {
8
- super(http, logger, config);
9
- this.http = http;
10
- this.logger = logger;
11
- this.config = config;
12
- }
13
- async bootstrap() {
14
- this.testRunId = await this.http.testRuns.createTestRun();
15
- await this.http.testRuns.startTestRun(this.testRunId);
16
- }
17
- async teardown() {
18
- await this.http.testRuns.completeTestRun(this.testRunId);
19
- }
20
- async transferTestsToSystem(suite) {
21
- await this.createOrUpdateTests(suite);
22
- }
23
- async transferRunsToSystem(suite) {
24
- var _a, _b, _c;
25
- for (const test of suite.tests) {
26
- const config = this.box.get(test.id);
27
- const screenshot = (_a = test.artifacts) === null || _a === void 0 ? void 0 : _a.screenshot;
28
- const clientUrls = (_b = config === null || config === void 0 ? void 0 : config.attachments) !== null && _b !== void 0 ? _b : [];
29
- if (screenshot) {
30
- clientUrls.push(screenshot);
31
- }
32
- const attachments = await this.http.attachments.uploadAttachments(clientUrls);
33
- if (config === null || config === void 0 ? void 0 : config.text) {
34
- const attach = await this.http.attachments.uploadTextAttachment(config.text.content, (_c = config.text) === null || _c === void 0 ? void 0 : _c.name);
35
- attachments.push(...attach);
36
- }
37
- const autotestResult = this.runsBuilder.build(test, config, attachments);
38
- await this.http.testRuns.loadAutotests(this.testRunId, [autotestResult]).catch((e) => {
39
- console.log("Error load test run.");
40
- console.log(e);
41
- });
42
- }
43
- this.logger.log(`Test run - ${this.testRunId} transferred to remote system`);
44
- }
45
- }
46
- exports.ScratchStrategy = ScratchStrategy;
@@ -1,7 +0,0 @@
1
- import { AdapterConfig, IClient } from "testit-js-commons";
2
- import { Logger } from "../common/classes";
3
- import { Strategy } from "../types";
4
- export type AdapterMode = 0 | 1 | 2;
5
- export declare class StrategyFactory {
6
- static create(http: IClient, logger: Logger, config: AdapterConfig): Strategy;
7
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StrategyFactory = void 0;
4
- const default_strategy_1 = require("./default.strategy");
5
- const partial_strategy_1 = require("./partial.strategy");
6
- const scratch_strategy_1 = require("./scratch.strategy");
7
- class StrategyFactory {
8
- static create(http, logger, config) {
9
- var _a;
10
- const strategies = {
11
- 0: () => new partial_strategy_1.PartialStrategy(http, logger, config),
12
- 1: () => new default_strategy_1.DefaultStrategy(http, logger, config),
13
- 2: () => new scratch_strategy_1.ScratchStrategy(http, logger, config),
14
- };
15
- if (!strategies[config === null || config === void 0 ? void 0 : config.adapterMode]) {
16
- logger.warn(`This mode ${config === null || config === void 0 ? void 0 : config.adapterMode} is invalid. Use mode 0, 1, 2`);
17
- }
18
- return strategies[(_a = config === null || config === void 0 ? void 0 : config.adapterMode) !== null && _a !== void 0 ? _a : 0]();
19
- }
20
- }
21
- exports.StrategyFactory = StrategyFactory;
@@ -1,14 +0,0 @@
1
- /// <reference types="codeceptjs" />
2
- import { Origin } from "./origin.type";
3
- export interface Strategy {
4
- bootstrap(): Promise<void>;
5
- teardown(): Promise<void>;
6
- beforeTest(test: Mocha.Test): Promise<void>;
7
- transferTestsToSystem(suite: {
8
- tests: Mocha.Test[];
9
- }): Promise<void>;
10
- transferRunsToSystem(suite: {
11
- tests: Mocha.Test[];
12
- }): Promise<void>;
13
- collect(id: string, data: Origin.TestMetadata): void;
14
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });