testit-adapter-codecept 1.1.7 → 2.0.1

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.
Files changed (80) hide show
  1. package/.prettierrc +9 -0
  2. package/README.md +37 -20
  3. package/build/bootstrap.js +13 -18
  4. package/build/builders/index.d.ts +2 -0
  5. package/build/builders/index.js +7 -0
  6. package/build/builders/run.builder.d.ts +9 -0
  7. package/build/builders/run.builder.js +53 -0
  8. package/build/{services/tests.builder.d.ts → builders/test.builder.d.ts} +3 -4
  9. package/build/{services/tests.builder.js → builders/test.builder.js} +12 -28
  10. package/build/common/classes/index.d.ts +2 -0
  11. package/build/common/classes/index.js +7 -0
  12. package/build/common/classes/logger.class.d.ts +2 -2
  13. package/build/common/classes/logger.class.js +6 -1
  14. package/build/common/types/index.d.ts +1 -0
  15. package/build/common/types/index.js +2 -0
  16. package/build/common/utils/index.d.ts +5 -0
  17. package/build/common/utils/index.js +21 -0
  18. package/build/common/{functions/is-passed.function.d.ts → utils/is-passed.util.d.ts} +1 -1
  19. package/build/common/{functions/is-passed.function.js → utils/is-passed.util.js} +1 -1
  20. package/build/common/{functions/use-hash.function.d.ts → utils/use-hash.util.d.ts} +1 -1
  21. package/build/common/{functions/use-hash.function.js → utils/use-hash.util.js} +3 -3
  22. package/build/helper.d.ts +4 -4
  23. package/build/helper.js +7 -5
  24. package/build/strategies/base.strategy.d.ts +17 -0
  25. package/build/strategies/base.strategy.js +40 -0
  26. package/build/strategies/default.strategy.d.ts +14 -0
  27. package/build/strategies/{default-strategy.class.js → default.strategy.js} +13 -11
  28. package/build/strategies/index.d.ts +5 -0
  29. package/build/strategies/index.js +13 -0
  30. package/build/strategies/partial.strategy.d.ts +18 -0
  31. package/build/strategies/partial.strategy.js +77 -0
  32. package/build/strategies/scratch.strategy.d.ts +16 -0
  33. package/build/strategies/scratch.strategy.js +46 -0
  34. package/build/strategies/strategy.factory.d.ts +4 -5
  35. package/build/strategies/strategy.factory.js +6 -6
  36. package/build/types/codecept.type.d.ts +1 -1
  37. package/build/types/index.d.ts +3 -0
  38. package/build/types/index.js +19 -0
  39. package/build/types/origin.type.d.ts +6 -28
  40. package/build/types/strategy.type.d.ts +3 -3
  41. package/package.json +5 -15
  42. package/build/common/__tests/box.class.spec.d.ts +0 -1
  43. package/build/common/__tests/box.class.spec.js +0 -15
  44. package/build/common/__tests/test.utils.d.ts +0 -4
  45. package/build/common/__tests/test.utils.js +0 -71
  46. package/build/common/classes/config.class.d.ts +0 -6
  47. package/build/common/classes/config.class.js +0 -67
  48. package/build/common/classes/outcome.factory.d.ts +0 -7
  49. package/build/common/classes/outcome.factory.js +0 -19
  50. package/build/common/functions/to-iso-string.function.d.ts +0 -1
  51. package/build/common/functions/to-iso-string.function.js +0 -10
  52. package/build/http/default-http-client.class.d.ts +0 -22
  53. package/build/http/default-http-client.class.js +0 -123
  54. package/build/http/http-client.errors.d.ts +0 -7
  55. package/build/http/http-client.errors.js +0 -18
  56. package/build/jest.config.d.ts +0 -7
  57. package/build/jest.config.js +0 -12
  58. package/build/services/__tests/attachments.class.spec.d.ts +0 -1
  59. package/build/services/__tests/attachments.class.spec.js +0 -23
  60. package/build/services/__tests/runs.builder.spec.d.ts +0 -1
  61. package/build/services/__tests/runs.builder.spec.js +0 -79
  62. package/build/services/__tests/tests.builder.spec.d.ts +0 -1
  63. package/build/services/__tests/tests.builder.spec.js +0 -32
  64. package/build/services/attachments.service.d.ts +0 -11
  65. package/build/services/attachments.service.js +0 -28
  66. package/build/services/runs.builder.d.ts +0 -10
  67. package/build/services/runs.builder.js +0 -65
  68. package/build/strategies/base-strategy.class.d.ts +0 -24
  69. package/build/strategies/base-strategy.class.js +0 -66
  70. package/build/strategies/default-strategy.class.d.ts +0 -16
  71. package/build/strategies/partial-startegy.class.d.ts +0 -20
  72. package/build/strategies/partial-startegy.class.js +0 -72
  73. package/build/strategies/scratch-strategy.class.d.ts +0 -18
  74. package/build/strategies/scratch-strategy.class.js +0 -49
  75. /package/build/common/{functions/compose.function.d.ts → utils/compose.util.d.ts} +0 -0
  76. /package/build/common/{functions/compose.function.js → utils/compose.util.js} +0 -0
  77. /package/build/common/{functions/hash.function.d.ts → utils/hash.util.d.ts} +0 -0
  78. /package/build/common/{functions/hash.function.js → utils/hash.util.js} +0 -0
  79. /package/build/common/{functions/humanize.function.d.ts → utils/humanize.util.d.ts} +0 -0
  80. /package/build/common/{functions/humanize.function.js → utils/humanize.util.js} +0 -0
package/.prettierrc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "endOfLine": "lf",
3
+ "printWidth": 120,
4
+ "semi": true,
5
+ "singleQuote": false,
6
+ "useTabs": false,
7
+ "trailingComma": "es5",
8
+ "tabWidth": 2
9
+ }
package/README.md CHANGED
@@ -10,13 +10,6 @@ npm install testit-adapter-codecept
10
10
 
11
11
  ## Usage
12
12
 
13
- ### API client
14
-
15
- To use adapter you need to install `testit-api-client`:
16
- ```
17
- npm install testit-api-client
18
- ```
19
-
20
13
  ### Configuration
21
14
 
22
15
  | Description | Property | Environment variable | CLI argument |
@@ -50,7 +43,9 @@ export const config: CodeceptJS.MainConfig = {
50
43
  plugins: {
51
44
  TestITPlugin: {
52
45
  require: 'testit-adapter-codecept/build/bootstrap.js',
53
- enabled: true
46
+ enabled: true,
47
+ // logging
48
+ __DEV: false
54
49
  }
55
50
  },
56
51
  include: {},
@@ -85,25 +80,47 @@ Create .env config or file config with default name testit-adapter.config.json i
85
80
  "configurationId": "CONFIGURATION_ID",
86
81
  "testRunId": "TEST_RUN_ID",
87
82
  "testRunName": "TEST_RUN_NAME",
88
- "adapterMode": ADAPTER_MODE,
89
- "automaticCreationTestCases": AUTOMATIC_CREATION_TEST_CASES
83
+ "adapterMode": "ADAPTER_MODE",
84
+ "automaticCreationTestCases": "AUTOMATIC_CREATION_TEST_CASES"
90
85
  }
91
86
  ```
92
87
 
88
+ #### Parallel run
89
+ To create and complete TestRun you can use the Test IT CLI:
90
+
91
+ ```
92
+ $ export TMS_TOKEN=<YOUR_TOKEN>
93
+ $ testit \
94
+ --mode create
95
+ --url https://tms.testit.software \
96
+ --project-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
97
+ --testrun-name "New test run" \
98
+ --output tmp/output.txt
99
+
100
+ $ export TMS_TEST_RUN_ID=$(cat output.txt)
101
+
102
+ $ npx codeceptjs run
103
+
104
+ $ testit \
105
+ --mode finish
106
+ --url https://tms.testit.software \
107
+ --testrun-id $(cat tmp/output.txt)
108
+ ```
109
+
93
110
  ### Methods
94
111
 
95
112
  Methods can be used to specify information about autotest.
96
113
 
97
114
  Description of metadata methods:
98
- - `workItemIds` - linking an autotest to a test case
99
- - `displayName` - name of the autotest in the Test IT system (can be replaced with documentation strings)
100
- - `externalId` - ID of the autotest within the project in the Test IT System
101
- - `title` - title in the autotest card
102
- - `description` - description in the autotest card
103
- - `labels` - tags in the work item
104
- - `link` - links in the autotest card
105
- - `nameSpace` - directory in the TMS system
106
- - `className` - subdirectory in the TMS system
115
+ - `workItemIds` - a method that links autotests with manual tests. Receives the array of manual tests' IDs
116
+ - `displayName` - internal autotest name (used in Test IT)
117
+ - `externalId` - unique internal autotest ID (used in Test IT)
118
+ - `title` - autotest name specified in the autotest card. If not specified, the name from the displayName method is used
119
+ - `description` - autotest description specified in the autotest card
120
+ - `labels` - tags listed in the autotest card
121
+ - `link` - links listed in the autotest card
122
+ - `namespace` - directory in the TMS system
123
+ - `classname` - subdirectory in the TMS system
107
124
 
108
125
  Description of methods:
109
126
  - `addLinks` - links in the autotest result
@@ -131,7 +148,7 @@ Scenario(
131
148
  hasInfo: true
132
149
  }
133
150
  ],
134
- workitemIds: ['1140']
151
+ workItemIds: ['1140']
135
152
  },
136
153
  ({ I }) => {
137
154
  I.amOnPage('https://github.com');
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const codeceptjs_1 = require("codeceptjs");
4
- const config_class_1 = require("./common/classes/config.class");
5
- const logger_class_1 = require("./common/classes/logger.class");
6
- const default_http_client_class_1 = require("./http/default-http-client.class");
7
- const strategy_factory_1 = require("./strategies/strategy.factory");
8
- module.exports = async function () {
9
- const config = new config_class_1.ConfigComposer().compose();
10
- const logger = new logger_class_1.Logger(config.__DEV);
11
- const http = new default_http_client_class_1.DefaultHttpClient(config, logger);
12
- const strategy = strategy_factory_1.StrategyFactory.create(http, logger, config);
13
- const helper = codeceptjs_1.container.helpers('TestITHelper');
4
+ const testit_js_commons_1 = require("testit-js-commons");
5
+ const classes_1 = require("./common/classes");
6
+ const strategies_1 = require("./strategies");
7
+ module.exports = async function (options) {
8
+ var _a;
9
+ 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);
13
+ const helper = codeceptjs_1.container.helpers("TestITHelper");
14
14
  await strategy.bootstrap();
15
15
  codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.after, (test) => {
16
16
  strategy.collect(test.id, helper.metadata);
@@ -19,11 +19,9 @@ module.exports = async function () {
19
19
  codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.before, async (test) => {
20
20
  await strategy.beforeTest(test);
21
21
  });
22
- codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.finished, async (test) => {
23
- codeceptjs_1.recorder.add('transferTestAndRuns', async () => {
24
- const suite = {
25
- tests: [test]
26
- };
22
+ codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.finished, (test) => {
23
+ codeceptjs_1.recorder.add("transferTestAndRuns", async () => {
24
+ const suite = { tests: [test] };
27
25
  await strategy.transferTestsToSystem(suite);
28
26
  await strategy.transferRunsToSystem(suite);
29
27
  });
@@ -31,7 +29,4 @@ module.exports = async function () {
31
29
  codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.all.after, async () => {
32
30
  await strategy.teardown();
33
31
  });
34
- codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.all.after, async () => {
35
- await strategy.teardown();
36
- });
37
32
  };
@@ -0,0 +1,2 @@
1
+ export { RunsBuilder } from "./run.builder";
2
+ export { TestsBuilder } from "./test.builder";
@@ -0,0 +1,7 @@
1
+ "use strict";
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; } });
6
+ var test_builder_1 = require("./test.builder");
7
+ Object.defineProperty(exports, "TestsBuilder", { enumerable: true, get: function () { return test_builder_1.TestsBuilder; } });
@@ -0,0 +1,9 @@
1
+ import { AdapterConfig, Attachment, AutotestResult } from "testit-js-commons";
2
+ import { Codecept, Origin } from "../types";
3
+ export declare class RunsBuilder {
4
+ private readonly config;
5
+ constructor(config: AdapterConfig);
6
+ build(test: Codecept.Test<Origin.TestConfig>, metadata: Origin.TestMetadata, attachments: Attachment[]): AutotestResult;
7
+ private buildManySteps;
8
+ private reduceAfterOrBeforeSuites;
9
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RunsBuilder = void 0;
4
+ const utils_1 = require("../common/utils");
5
+ class RunsBuilder {
6
+ constructor(config) {
7
+ this.config = config;
8
+ }
9
+ build(test, metadata, attachments) {
10
+ var _a, _b, _c, _d, _e, _f, _g, _h;
11
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
+ // @ts-ignore
13
+ const { _beforeEach, _afterEach, _afterAll, _beforeAll } = test.parent;
14
+ const parameters = ((_b = (_a = test === null || test === void 0 ? void 0 : test.inject) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.toString) ? JSON.parse((_d = (_c = test === null || test === void 0 ? void 0 : test.inject) === null || _c === void 0 ? void 0 : _c.current) === null || _d === void 0 ? void 0 : _d.toString()) : {};
15
+ const teardownResults = [
16
+ ...this.reduceAfterOrBeforeSuites(_afterEach),
17
+ ...this.reduceAfterOrBeforeSuites(_afterAll),
18
+ ];
19
+ const setupResults = [
20
+ ...this.reduceAfterOrBeforeSuites(_beforeEach),
21
+ ...this.reduceAfterOrBeforeSuites(_beforeAll),
22
+ ];
23
+ return {
24
+ autoTestExternalId: (_e = (0, utils_1.useDefaultHash)(test)) !== null && _e !== void 0 ? _e : (0, utils_1.useCompositeHash)(test),
25
+ links: metadata === null || metadata === void 0 ? void 0 : metadata.links,
26
+ startedOn: new Date(test.startedAt),
27
+ duration: test.duration,
28
+ attachments,
29
+ parameters,
30
+ 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
+ teardownResults,
32
+ setupResults,
33
+ completedOn: test.duration ? new Date(test.startedAt + test.duration) : undefined,
34
+ message: (_h = metadata === null || metadata === void 0 ? void 0 : metadata.message) !== null && _h !== void 0 ? _h : null,
35
+ outcome: test.state === "passed" ? "Passed" : "Failed",
36
+ stepResults: this.buildManySteps(test.steps),
37
+ };
38
+ }
39
+ buildManySteps(steps) {
40
+ return steps === null || steps === void 0 ? void 0 : steps.map((step) => ({
41
+ title: `${step.name} ${(0, utils_1.humanize)(step.args).join(",")}`.trim(),
42
+ outcome: step.status === "success" ? "Passed" : "Failed",
43
+ description: "",
44
+ startedOn: new Date(step.startedAt),
45
+ duration: step.duration,
46
+ completedOn: new Date(step.finishedAt),
47
+ }));
48
+ }
49
+ reduceAfterOrBeforeSuites(suite) {
50
+ 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
+ }
52
+ }
53
+ exports.RunsBuilder = RunsBuilder;
@@ -1,9 +1,8 @@
1
- import { AutotestPost } from 'testit-api-client';
2
- import { Codecept } from '../types/codecept.type';
3
- import { Origin } from '../types/origin.type';
1
+ import { Codecept, Origin } from "../types";
2
+ import { AdapterConfig, AutotestPost } from "testit-js-commons";
4
3
  export declare class TestsBuilder {
5
4
  private readonly config;
6
- constructor(config: Origin.Config);
5
+ constructor(config: AdapterConfig);
7
6
  build(test: Codecept.Test<Origin.TestConfig>): AutotestPost;
8
7
  private buildManySteps;
9
8
  private reduceAfterOrBeforeSuites;
@@ -1,57 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TestsBuilder = void 0;
4
- const humanize_function_1 = require("../common/functions/humanize.function");
5
- const use_hash_function_1 = require("../common/functions/use-hash.function");
4
+ const utils_1 = require("../common/utils");
6
5
  class TestsBuilder {
7
6
  constructor(config) {
8
7
  this.config = config;
9
8
  }
10
9
  build(test) {
11
10
  var _a, _b, _c, _d, _e;
12
- const config = (0, use_hash_function_1.useConfig)(test);
11
+ const config = (0, utils_1.useConfig)(test);
13
12
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
14
13
  // @ts-ignore
15
14
  const { _beforeEach, _afterEach, _beforeAll, _afterAll } = test.parent;
16
- const teardown = [
17
- ...this.reduceAfterOrBeforeSuites(_afterEach),
18
- ...this.reduceAfterOrBeforeSuites(_afterAll)
19
- ];
20
- const setup = [
21
- ...this.reduceAfterOrBeforeSuites(_beforeEach),
22
- ...this.reduceAfterOrBeforeSuites(_beforeAll)
23
- ];
15
+ const teardown = [...this.reduceAfterOrBeforeSuites(_afterEach), ...this.reduceAfterOrBeforeSuites(_afterAll)];
16
+ const setup = [...this.reduceAfterOrBeforeSuites(_beforeEach), ...this.reduceAfterOrBeforeSuites(_beforeAll)];
24
17
  return {
25
18
  title: config === null || config === void 0 ? void 0 : config.title,
26
19
  name: (_a = config === null || config === void 0 ? void 0 : config.displayName) !== null && _a !== void 0 ? _a : test.title,
27
- projectId: this.config.projectId,
28
- labels: ((_b = config === null || config === void 0 ? void 0 : config.labels) !== null && _b !== void 0 ? _b : []).map(label => ({ name: label })),
29
- description: (_c = config === null || config === void 0 ? void 0 : config.description) !== null && _c !== void 0 ? _c : '',
20
+ labels: ((_b = config === null || config === void 0 ? void 0 : config.labels) !== null && _b !== void 0 ? _b : []).map((label) => ({ name: label })),
21
+ description: (_c = config === null || config === void 0 ? void 0 : config.description) !== null && _c !== void 0 ? _c : "",
30
22
  steps: this.buildManySteps(test.steps),
31
23
  setup,
32
24
  links: (_d = config === null || config === void 0 ? void 0 : config.links) !== null && _d !== void 0 ? _d : [],
33
25
  teardown,
34
- externalId: (_e = (0, use_hash_function_1.useDefaultHash)(test)) !== null && _e !== void 0 ? _e : (0, use_hash_function_1.useCompositeHash)(test),
26
+ externalId: (_e = (0, utils_1.useDefaultHash)(test)) !== null && _e !== void 0 ? _e : (0, utils_1.useCompositeHash)(test),
35
27
  namespace: config === null || config === void 0 ? void 0 : config.nameSpace,
36
- classname: config === null || config === void 0 ? void 0 : config.className
28
+ classname: config === null || config === void 0 ? void 0 : config.className,
37
29
  };
38
30
  }
39
31
  buildManySteps(steps = []) {
40
- return steps
41
- .map(step => ({
42
- title: `${step.name} ${(0, humanize_function_1.humanize)(step.args).join(',')}`.trim(),
43
- description: ''
32
+ return steps.map((step) => ({
33
+ title: `${step.name} ${(0, utils_1.humanize)(step.args).join(",")}`.trim(),
34
+ description: "",
44
35
  }));
45
36
  }
46
37
  reduceAfterOrBeforeSuites(suite) {
47
- return suite
48
- .reduce((array, suite) => {
49
- var _a;
50
- return [
51
- ...array,
52
- ...this.buildManySteps((_a = suite === null || suite === void 0 ? void 0 : suite.steps) !== null && _a !== void 0 ? _a : [])
53
- ];
54
- }, []);
38
+ 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 : [])]; }, []);
55
39
  }
56
40
  }
57
41
  exports.TestsBuilder = TestsBuilder;
@@ -0,0 +1,2 @@
1
+ export { Box } from "./box.class";
2
+ export { Logger } from "./logger.class";
@@ -0,0 +1,7 @@
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 +1,9 @@
1
- import { AxiosError } from 'axios';
1
+ import { AxiosError } from "axios";
2
2
  export declare class Logger {
3
3
  private readonly __DEV;
4
4
  private readonly logger;
5
5
  constructor(__DEV?: boolean);
6
6
  log(message: string): void;
7
7
  warn(message: string): void;
8
- error(error: AxiosError): void;
8
+ error(error: AxiosError | string): void;
9
9
  }
@@ -17,12 +17,17 @@ class Logger {
17
17
  }
18
18
  error(error) {
19
19
  var _a, _b, _c, _d;
20
- this.logger.error(`
20
+ if (typeof error === "string") {
21
+ this.logger.error(error);
22
+ }
23
+ else {
24
+ this.logger.error(`
21
25
  ${(_a = error.response) === null || _a === void 0 ? void 0 : _a.status},
22
26
  ${(_b = error.config) === null || _b === void 0 ? void 0 : _b.method},
23
27
  ${(_c = error.config) === null || _c === void 0 ? void 0 : _c.url},
24
28
  ${JSON.stringify((_d = error.response) === null || _d === void 0 ? void 0 : _d.data)}
25
29
  `);
30
+ }
26
31
  }
27
32
  }
28
33
  exports.Logger = Logger;
@@ -0,0 +1 @@
1
+ export { Nullable } from "./nullable.type";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from "./compose.util";
2
+ export * from "./hash.util";
3
+ export * from "./humanize.util";
4
+ export * from "./use-hash.util";
5
+ export * from "./is-passed.util";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./compose.util"), exports);
18
+ __exportStar(require("./hash.util"), exports);
19
+ __exportStar(require("./humanize.util"), exports);
20
+ __exportStar(require("./use-hash.util"), exports);
21
+ __exportStar(require("./is-passed.util"), exports);
@@ -1,2 +1,2 @@
1
- import { Codecept } from '../../types/codecept.type';
1
+ import { Codecept } from "../../types";
2
2
  export declare function isPassed(test: Codecept.Test): boolean;
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isPassed = void 0;
4
4
  function isPassed(test) {
5
- return test.state === 'passed';
5
+ return test.state === "passed";
6
6
  }
7
7
  exports.isPassed = isPassed;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="codeceptjs" />
2
2
  /// <reference types="codeceptjs" />
3
- import { Codecept } from '../../types/codecept.type';
3
+ import { Codecept } from "../../types";
4
4
  export declare const useCompositeKey: (test: Mocha.Test) => string;
5
5
  export declare const useDefaultHash: (test: Codecept.Test) => any;
6
6
  export declare const useCompositeHash: (test: Mocha.Test) => any;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useConfig = exports.useCompositeHash = exports.useDefaultHash = exports.useCompositeKey = void 0;
4
- const compose_function_1 = require("./compose.function");
5
- const hash_function_1 = require("./hash.function");
4
+ const compose_util_1 = require("./compose.util");
5
+ const hash_util_1 = require("./hash.util");
6
6
  const useCompositeKey = (test) => { var _a; return `${test.title}:${(_a = test.parent) === null || _a === void 0 ? void 0 : _a.title}`; };
7
7
  exports.useCompositeKey = useCompositeKey;
8
8
  const useDefaultHash = (test) => { var _a; return (_a = test === null || test === void 0 ? void 0 : test.opts) === null || _a === void 0 ? void 0 : _a.externalId; };
9
9
  exports.useDefaultHash = useDefaultHash;
10
- const useCompositeHash = (test) => (0, compose_function_1.compose)(hash_function_1.hash, exports.useCompositeKey)(test);
10
+ const useCompositeHash = (test) => (0, compose_util_1.compose)(hash_util_1.hash, exports.useCompositeKey)(test);
11
11
  exports.useCompositeHash = useCompositeHash;
12
12
  const useConfig = (test) => test.opts;
13
13
  exports.useConfig = useConfig;
package/build/helper.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { LinkPost, LinkType } from 'testit-api-client';
2
- import { Nullable } from './common/types/nullable.type';
3
- import { Origin } from './types/origin.type';
1
+ import { Link, LinkType } from "testit-js-commons";
2
+ import { Nullable } from "./common/types";
3
+ import { Origin } from "./types";
4
4
  export declare class TestMetadataHelper extends Helper {
5
5
  metadata: Nullable<Origin.TestMetadata>;
6
6
  addMessage(message: string): void;
7
7
  addAttachments(paths: string[] | string, name?: string): void;
8
- addLinks(linksOrName: LinkPost[] | string, description?: string, type?: LinkType, url?: string): void;
8
+ addLinks(linksOrName: Link[] | string, description?: string, type?: LinkType, url?: string): void;
9
9
  }
package/build/helper.js CHANGED
@@ -16,20 +16,22 @@ class TestMetadataHelper extends Helper {
16
16
  }
17
17
  this.metadata.text = {
18
18
  name,
19
- content: paths
19
+ content: paths,
20
20
  };
21
21
  }
22
22
  addLinks(linksOrName, description, type, url) {
23
- if (typeof linksOrName !== 'string') {
23
+ if (typeof linksOrName !== "string") {
24
24
  this.metadata.links = linksOrName;
25
25
  }
26
26
  else {
27
- this.metadata.links = [{
27
+ this.metadata.links = [
28
+ {
28
29
  title: linksOrName,
29
30
  url,
30
31
  description,
31
- type
32
- }];
32
+ type,
33
+ },
34
+ ];
33
35
  }
34
36
  }
35
37
  }
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,40 @@
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;
@@ -0,0 +1,14 @@
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,21 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultStrategy = void 0;
4
- const attachments_service_1 = require("../services/attachments.service");
5
- const base_strategy_class_1 = require("./base-strategy.class");
6
- class DefaultStrategy extends base_strategy_class_1.BaseStrategy {
4
+ const base_strategy_1 = require("./base.strategy");
5
+ // Adapter mode 1
6
+ class DefaultStrategy extends base_strategy_1.BaseStrategy {
7
7
  constructor(http, logger, config) {
8
8
  super(http, logger, config);
9
9
  this.http = http;
10
10
  this.logger = logger;
11
11
  this.config = config;
12
- this.attachments = new attachments_service_1.AttachmentsService(this.http);
13
12
  }
14
13
  async bootstrap() {
15
- await this.http.startRunIfNeeded(this.config.testRunId);
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);
16
19
  }
17
20
  async teardown() {
18
- await this.http.completeRunIfNeeded(this.config.testRunId);
21
+ await this.http.testRuns.completeTestRun(this.config.testRunId);
19
22
  }
20
23
  async transferTestsToSystem(suite) {
21
24
  await this.createOrUpdateTests(suite);
@@ -29,14 +32,13 @@ class DefaultStrategy extends base_strategy_class_1.BaseStrategy {
29
32
  if (screenshot) {
30
33
  clientUrls.push(screenshot);
31
34
  }
32
- const attachments = await this.attachments.attach(clientUrls);
35
+ const attachments = await this.http.attachments.uploadAttachments(clientUrls);
33
36
  if (config === null || config === void 0 ? void 0 : config.text) {
34
- const attach = await this.attachments
35
- .attachTextLikeFile(config.text.content, (_c = config.text) === null || _c === void 0 ? void 0 : _c.name);
36
- attachments.push(attach);
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);
37
39
  }
38
40
  const run = this.runsBuilder.build(test, config, attachments);
39
- await this.http.updateRuns(run);
41
+ await this.http.testRuns.loadAutotests(this.config.testRunId, [run]);
40
42
  }
41
43
  this.logger.log(`Test run - ${this.config.testRunId} transferred to remote system`);
42
44
  }
@@ -0,0 +1,5 @@
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";
@@ -0,0 +1,13 @@
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; } });