testit-adapter-cucumber 1.1.1 → 1.1.3

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
@@ -3,13 +3,6 @@
3
3
 
4
4
  ## Getting Started
5
5
 
6
- ### Compatibility
7
-
8
- | Test IT | Adapter |
9
- |---------|---------|
10
- | 3.5 | 1.0 |
11
- | 4.0 | 1.1 |
12
-
13
6
  ### Installation
14
7
  ```
15
8
  npm install testit-adapter-cucumber
@@ -94,6 +87,8 @@ Cucumber tags can be used to specify information about autotest.
94
87
  - `@Link` - can be specified either in JSON (`@Link={"url":"http://google.com","hasInfo":true,"description":"GoogleDescription","title":"Google","type":"Defect"}`) or in text (`@Link=http://google.com`)
95
88
  - `@Label` - Label that is going to be linked to autotest
96
89
  - `@WorkItemId` - Work item's ID to which autotest is going to be linked
90
+ - `@NameSpace` - directory in the TMS system
91
+ - `@ClassName` - subdirectory in the TMS system
97
92
 
98
93
  ### Examples
99
94
 
@@ -1,14 +1,18 @@
1
1
  import { Formatter, IFormatterOptions } from '@cucumber/cucumber';
2
- import { Meta, GherkinDocument, Pickle, TestCase, TestStepFinished, TestCaseStarted, TestCaseFinished, TestStepStarted } from '@cucumber/messages';
3
- import { AdapterProperties, Link } from 'testit-js-commons';
2
+ import { GherkinDocument, Pickle, TestCase, TestStepFinished, TestRunFinished, TestCaseStarted, TestCaseFinished, TestStepStarted, Meta } from '@cucumber/messages';
3
+ import { ClientConfigWithFile, IClient, LinkPost } from 'testit-api-client';
4
+ import { IStorage } from './types/storage';
4
5
  import { IFormatter } from './types/formatter';
6
+ import { AutotestPostWithWorkItemId } from './mappers';
5
7
  export declare class TestItFormatter extends Formatter implements IFormatter {
6
- private storage;
7
- private adapterManager;
8
- private resolvedAutotests;
9
- private testRunStarted;
8
+ client: IClient;
9
+ storage: IStorage;
10
10
  currentTestCaseId: string | undefined;
11
- constructor(options: IFormatterOptions, properties: Partial<AdapterProperties>);
11
+ resolvedAutotests: Array<string | undefined> | undefined;
12
+ constructor(options: IFormatterOptions, config: Partial<ClientConfigWithFile>);
13
+ private testRunId;
14
+ private testRunStarted;
15
+ private attachmentsQueue;
12
16
  onMeta(_meta: Meta): void;
13
17
  onGherkinDocument(document: GherkinDocument): void;
14
18
  onPickle(pickle: Pickle): void;
@@ -17,8 +21,15 @@ export declare class TestItFormatter extends Formatter implements IFormatter {
17
21
  testStepStarted(testStepStarted: TestStepStarted): void;
18
22
  onTestStepFinished(testStepFinished: TestStepFinished): void;
19
23
  testCaseFinished(testCaseFinished: TestCaseFinished): void;
24
+ onTestRunFinished(_testRunFinished: TestRunFinished): void;
25
+ loadAutotest(autotestPost: AutotestPostWithWorkItemId): Promise<void>;
26
+ loadPassedAutotest(autotestPost: AutotestPostWithWorkItemId): Promise<void>;
27
+ createTestRun(): void;
28
+ createNewAutotest(autotestPost: AutotestPostWithWorkItemId): Promise<void>;
29
+ updateAutotest(autotestPost: AutotestPostWithWorkItemId): Promise<void>;
30
+ linkWorkItem(externalId: string, workItemId: string): Promise<void>;
20
31
  addMessage(message: string): void;
21
- addLinks(links: Link[]): void;
22
- addAttachments(data: string[] | string, isText?: boolean, name?: string): Promise<void>;
23
- loadAttachment(attachmentPath: string): Promise<void>;
32
+ addLinks(links: LinkPost[]): void;
33
+ addAttachments(attachments: string[]): void;
34
+ private logError;
24
35
  }
package/dist/formatter.js CHANGED
@@ -2,18 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TestItFormatter = void 0;
4
4
  const cucumber_1 = require("@cucumber/cucumber");
5
- const fs_1 = require("fs");
6
- const uuid_1 = require("uuid");
7
- const path_1 = require("path");
8
- const testit_js_commons_1 = require("testit-js-commons");
9
- const tags_parser_1 = require("./tags-parser");
10
- const scenario_storage_1 = require("./scenario-storage");
5
+ const testit_api_client_1 = require("testit-api-client");
6
+ const storage_1 = require("./storage");
7
+ const utils_1 = require("./utils");
11
8
  class TestItFormatter extends cucumber_1.Formatter {
12
- constructor(options, properties) {
9
+ constructor(options, config) {
13
10
  super(options);
14
- this.storage = new scenario_storage_1.Storage();
15
- this.adapterManager = testit_js_commons_1.Adapter.getAdapterManager(properties);
16
- this.resolvedAutotests = this.adapterManager.getAutotestsForLaunch();
11
+ this.storage = new storage_1.Storage();
12
+ this.attachmentsQueue = [];
13
+ this.client = new testit_api_client_1.Client(config);
17
14
  options.eventBroadcaster.on('envelope', (envelope) => {
18
15
  if (envelope.meta) {
19
16
  return this.onMeta(envelope.meta);
@@ -22,24 +19,25 @@ class TestItFormatter extends cucumber_1.Formatter {
22
19
  return this.onGherkinDocument(envelope.gherkinDocument);
23
20
  }
24
21
  if (envelope.pickle) {
25
- this.resolvedAutotests.then(resolvedAutotests => {
26
- if (resolvedAutotests !== undefined) {
27
- if (resolvedAutotests.length > 0) {
28
- const tags = (0, tags_parser_1.parseTags)(envelope.pickle.tags);
29
- for (const externalId of resolvedAutotests) {
30
- if (externalId === tags.externalId) {
31
- return this.onPickle(envelope.pickle);
32
- }
22
+ if (this.resolvedAutotests !== undefined) {
23
+ if (this.resolvedAutotests.length > 0) {
24
+ const tags = (0, utils_1.parseTags)(envelope.pickle.tags);
25
+ for (const externalId of this.resolvedAutotests) {
26
+ if (externalId === tags.externalId) {
27
+ return this.onPickle(envelope.pickle);
33
28
  }
34
29
  }
35
- envelope.pickle = undefined;
36
30
  }
37
- else {
38
- return this.onPickle(envelope.pickle);
39
- }
40
- });
31
+ envelope.pickle = undefined;
32
+ }
33
+ else {
34
+ return this.onPickle(envelope.pickle);
35
+ }
41
36
  }
42
37
  if (envelope.testCase) {
38
+ if (this.testRunId === undefined && this.storage.isResolvedTestCase(envelope.testCase)) {
39
+ this.createTestRun();
40
+ }
43
41
  return this.onTestCase(envelope.testCase);
44
42
  }
45
43
  if (envelope.testCaseStarted) {
@@ -54,6 +52,9 @@ class TestItFormatter extends cucumber_1.Formatter {
54
52
  if (envelope.testCaseFinished) {
55
53
  return this.testCaseFinished(envelope.testCaseFinished);
56
54
  }
55
+ if (envelope.testRunFinished) {
56
+ return this.onTestRunFinished(envelope.testRunFinished);
57
+ }
57
58
  });
58
59
  options.supportCodeLibrary.World.prototype.addMessage =
59
60
  this.addMessage.bind(this);
@@ -63,7 +64,12 @@ class TestItFormatter extends cucumber_1.Formatter {
63
64
  this.addAttachments.bind(this);
64
65
  }
65
66
  onMeta(_meta) {
66
- this.testRunStarted = this.adapterManager.startLaunch();
67
+ const { testRunId, configurationId } = this.client.getConfig();
68
+ if (testRunId !== undefined) {
69
+ this.testRunId = Promise.resolve(testRunId);
70
+ const responce = this.client.getTestRun(testRunId);
71
+ this.resolvedAutotests = (0, utils_1.parsedAutotests)(responce.testResults, configurationId);
72
+ }
67
73
  }
68
74
  onGherkinDocument(document) {
69
75
  this.storage.saveGherkinDocument(document);
@@ -85,18 +91,103 @@ class TestItFormatter extends cucumber_1.Formatter {
85
91
  this.storage.saveTestStepFinished(testStepFinished);
86
92
  }
87
93
  testCaseFinished(testCaseFinished) {
94
+ this.currentTestCaseId = undefined;
88
95
  this.storage.saveTestCaseFinished(testCaseFinished);
89
- if (this.testRunStarted === undefined) {
90
- throw new Error('Test run is not started');
96
+ }
97
+ onTestRunFinished(_testRunFinished) {
98
+ const { configurationId } = this.client.getConfig();
99
+ const results = this.storage.getTestRunResults(configurationId);
100
+ if (this.testRunId !== undefined && results.length > 0) {
101
+ Promise.all([
102
+ this.testRunId,
103
+ Promise.all(this.attachmentsQueue),
104
+ ])
105
+ .then(async ([id]) => {
106
+ const autotests = this.storage.getAutotests(this.client.getConfig().projectId);
107
+ await Promise.all(autotests.map((autotestPost) => {
108
+ const result = results.find((result) => result.autotestExternalId === autotestPost.externalId);
109
+ if (result !== undefined) {
110
+ if (result.outcome !== 'Passed') {
111
+ return this.loadAutotest(autotestPost);
112
+ }
113
+ return this.loadPassedAutotest(autotestPost);
114
+ }
115
+ }));
116
+ await Promise.all(results.map((result) => {
117
+ return this.client.loadTestRunResults(id, [result]);
118
+ }));
119
+ })
120
+ .catch((err) => {
121
+ var _a;
122
+ console.error(err);
123
+ (_a = this.testRunId) === null || _a === void 0 ? void 0 : _a.then((id) => this.client.completeTestRun(id));
124
+ });
125
+ }
126
+ }
127
+ async loadAutotest(autotestPost) {
128
+ var _a;
129
+ try {
130
+ await this.createNewAutotest(autotestPost);
91
131
  }
92
- const testCaseId = this.currentTestCaseId;
93
- this.testRunStarted
94
- .then(() => {
95
- if (testCaseId !== undefined) {
96
- this.adapterManager.writeTest(this.storage.getTestResult(testCaseId));
132
+ catch (err) {
133
+ const axiosError = err;
134
+ if (((_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status) === 409) {
135
+ const [autotest] = await this.client.getAutotest({
136
+ projectId: this.client.getConfig().projectId,
137
+ externalId: autotestPost.externalId,
138
+ });
139
+ await this.updateAutotest(Object.assign(Object.assign({}, autotest), { links: autotestPost.links }));
97
140
  }
98
- });
99
- this.currentTestCaseId = undefined;
141
+ else {
142
+ this.logError(axiosError);
143
+ }
144
+ }
145
+ }
146
+ async loadPassedAutotest(autotestPost) {
147
+ var _a;
148
+ try {
149
+ await this.createNewAutotest(autotestPost);
150
+ }
151
+ catch (err) {
152
+ const axiosError = err;
153
+ if (((_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status) === 409) {
154
+ await this.updateAutotest(autotestPost);
155
+ }
156
+ else {
157
+ this.logError(axiosError);
158
+ }
159
+ }
160
+ if (autotestPost.workItemId !== undefined) {
161
+ this.linkWorkItem(autotestPost.externalId, autotestPost.workItemId);
162
+ }
163
+ }
164
+ createTestRun() {
165
+ const { projectId } = this.client.getConfig();
166
+ this.testRunId = this.client
167
+ .createTestRun({
168
+ projectId,
169
+ })
170
+ .then((testRun) => testRun.id);
171
+ }
172
+ async createNewAutotest(autotestPost) {
173
+ autotestPost.shouldCreateWorkItem = this.client.getConfig().automaticCreationTestCases;
174
+ await this.client.createAutotest(autotestPost);
175
+ }
176
+ async updateAutotest(autotestPost) {
177
+ await this.client.updateAutotest(autotestPost).catch(this.logError);
178
+ }
179
+ async linkWorkItem(externalId, workItemId) {
180
+ const [autotest] = await this.client
181
+ .getAutotest({
182
+ projectId: this.client.getConfig().projectId,
183
+ externalId: externalId,
184
+ })
185
+ .catch(() => []);
186
+ if ((autotest === null || autotest === void 0 ? void 0 : autotest.id) !== undefined) {
187
+ await this.client.linkToWorkItem(autotest.id, {
188
+ id: workItemId,
189
+ });
190
+ }
100
191
  }
101
192
  addMessage(message) {
102
193
  if (this.currentTestCaseId === undefined) {
@@ -110,40 +201,24 @@ class TestItFormatter extends cucumber_1.Formatter {
110
201
  }
111
202
  this.storage.addLinks(this.currentTestCaseId, links);
112
203
  }
113
- async addAttachments(data, isText = false, name) {
114
- if (isText) {
115
- if (name == undefined) {
116
- name = (0, uuid_1.v4)() + '-attachment.txt';
117
- }
118
- const attachmentPath = (0, path_1.join)(__dirname, name);
119
- (0, fs_1.writeFileSync)(attachmentPath, data.toString(), {
120
- flag: 'w',
121
- });
122
- this.loadAttachment(attachmentPath);
123
- (0, fs_1.unlinkSync)(attachmentPath);
124
- }
125
- else if (typeof data == 'string') {
126
- this.loadAttachment(data);
127
- }
128
- else {
129
- for (const attachmentPath of data) {
130
- this.loadAttachment(attachmentPath);
131
- }
132
- }
133
- }
134
- async loadAttachment(attachmentPath) {
204
+ addAttachments(attachments) {
135
205
  if (this.currentTestCaseId === undefined) {
136
206
  throw new Error('CurrentTestCaseId is not set');
137
207
  }
138
208
  const currentTestCaseId = this.currentTestCaseId;
139
- const id = await this.adapterManager.loadAttachment(attachmentPath);
140
- if (id === undefined) {
141
- // NOTE: Why?
142
- console.warn('Attachment id is not returned');
143
- }
144
- else {
209
+ this.attachmentsQueue.push(...attachments.map(async (attachment) => {
210
+ const { id } = await this.client.loadAttachment(attachment);
211
+ if (id === undefined) {
212
+ // NOTE: Why?
213
+ console.warn('Attachment id is not returned');
214
+ return;
215
+ }
145
216
  this.storage.addAttachment(currentTestCaseId, id);
146
- }
217
+ }));
218
+ }
219
+ logError(err) {
220
+ var _a, _b;
221
+ console.error((_a = err.response) === null || _a === void 0 ? void 0 : _a.status, err.config.method, err.config.url, (_b = err.response) === null || _b === void 0 ? void 0 : _b.data);
147
222
  }
148
223
  }
149
224
  exports.TestItFormatter = TestItFormatter;
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":";;;AAAA,iDAAkE;AAalE,2BAA+C;AAC/C,+BAAkC;AAClC,+BAA4B;AAC5B,yDAK2B;AAE3B,+CAA0C;AAE1C,yDAA6C;AAE7C,MAAa,eAAgB,SAAQ,oBAAS;IAO1C,YACI,OAA0B,EAC1B,UAAsC;QAEtC,KAAK,CAAC,OAAO,CAAC,CAAC;QAVX,YAAO,GAAa,IAAI,0BAAO,EAAE,CAAC;QAYtC,IAAI,CAAC,cAAc,GAAG,2BAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAC5D,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,cAAc,CAAC,qBAAqB,EAAE,CAAC;QAErE,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,QAAkB,EAAE,EAAE;YAC3D,IAAI,QAAQ,CAAC,IAAI,EAAE;gBACf,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aACrC;YACD,IAAI,QAAQ,CAAC,eAAe,EAAE;gBAC1B,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;aAC3D;YACD,IAAI,QAAQ,CAAC,MAAM,EAAE;gBACjB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;oBAC5C,IAAI,iBAAiB,KAAK,SAAS,EAAE;wBACjC,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;4BAC9B,MAAM,IAAI,GAAG,IAAA,uBAAS,EAAC,QAAQ,CAAC,MAAO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C,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAED,cAAc,CAAC,WAAqB;QAClC,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS,EAAE;YACxC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QACD,MAAM,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC;QACjD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CACxB,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YACtC,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;YAC5D,IAAI,EAAE,KAAK,SAAS,EAAE;gBACpB,aAAa;gBACb,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;gBAC9C,OAAO;aACR;YACD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;QACpD,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAEO,QAAQ,CAAC,GAAe;;QAC9B,OAAO,CAAC,KAAK,CACX,MAAA,GAAG,CAAC,QAAQ,0CAAE,MAAM,EACpB,GAAG,CAAC,MAAM,CAAC,MAAM,EACjB,GAAG,CAAC,MAAM,CAAC,GAAG,EACd,MAAA,GAAG,CAAC,QAAQ,0CAAE,IAAI,CACnB,CAAC;IACJ,CAAC;CAGF;AAjQD,0CAiQC"}
@@ -0,0 +1,14 @@
1
+ import { Background, DataTable, Examples, GherkinDocument, Rule, Scenario, Step, TestStepResultStatus } from '@cucumber/messages';
2
+ import { AutotestPost, AutotestStep, OutcomeType } from 'testit-api-client';
3
+ export interface AutotestPostWithWorkItemId extends AutotestPost {
4
+ workItemId?: string;
5
+ }
6
+ export declare function mapStatus(status: TestStepResultStatus): OutcomeType;
7
+ export declare function mapDate(date: number): string;
8
+ export declare function mapDocument(document: GherkinDocument, projectId: string): AutotestPostWithWorkItemId[];
9
+ export declare function mapBackground(background: Background): AutotestStep;
10
+ export declare function mapRule(rule: Rule, projectId: string, setup: AutotestStep[]): AutotestPostWithWorkItemId[];
11
+ export declare function mapScenario(scenario: Scenario, projectId: string, setup: AutotestStep[]): AutotestPostWithWorkItemId;
12
+ export declare function mapExamples(examples: Examples): AutotestStep;
13
+ export declare function mapStep(step: Step): AutotestStep;
14
+ export declare function mapDataTable(dataTable: DataTable | undefined): string | undefined;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapDataTable = exports.mapStep = exports.mapExamples = exports.mapScenario = exports.mapRule = exports.mapBackground = exports.mapDocument = exports.mapDate = exports.mapStatus = void 0;
4
+ const messages_1 = require("@cucumber/messages");
5
+ const utils_1 = require("./utils");
6
+ function mapStatus(status) {
7
+ switch (status) {
8
+ case messages_1.TestStepResultStatus.PASSED:
9
+ return 'Passed';
10
+ case messages_1.TestStepResultStatus.FAILED:
11
+ return 'Failed';
12
+ case messages_1.TestStepResultStatus.PENDING:
13
+ return 'Pending';
14
+ case messages_1.TestStepResultStatus.SKIPPED:
15
+ return 'Skipped';
16
+ case messages_1.TestStepResultStatus.UNKNOWN:
17
+ case messages_1.TestStepResultStatus.UNDEFINED:
18
+ case messages_1.TestStepResultStatus.AMBIGUOUS:
19
+ return 'Blocked';
20
+ default:
21
+ throw new Error('Unknown status');
22
+ }
23
+ }
24
+ exports.mapStatus = mapStatus;
25
+ function mapDate(date) {
26
+ return new Date(date * 1000).toISOString();
27
+ }
28
+ exports.mapDate = mapDate;
29
+ function mapDocument(document, projectId) {
30
+ if (document.feature === undefined) {
31
+ return [];
32
+ }
33
+ const setup = document.feature.children
34
+ .filter((child) => child.background !== undefined)
35
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
36
+ .map((child) => mapBackground(child.background));
37
+ const scenarioAutotests = document.feature.children
38
+ .filter((child) => child.scenario !== undefined)
39
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
40
+ .map((child) => mapScenario(child.scenario, projectId, setup));
41
+ const ruleAutotests = document.feature.children
42
+ .filter((child) => child.rule !== undefined)
43
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44
+ .flatMap((child) => mapRule(child.rule, projectId, setup));
45
+ return scenarioAutotests.concat(...ruleAutotests);
46
+ }
47
+ exports.mapDocument = mapDocument;
48
+ function mapBackground(background) {
49
+ return {
50
+ title: background.name,
51
+ description: background.description,
52
+ steps: background.steps.map(mapStep),
53
+ };
54
+ }
55
+ exports.mapBackground = mapBackground;
56
+ function mapRule(rule, projectId, setup) {
57
+ const ruleSetup = setup.concat(rule.children
58
+ .filter((child) => child.background !== undefined)
59
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
60
+ .map((child) => mapBackground(child.background)));
61
+ return (rule.children
62
+ .filter((child) => child.scenario !== undefined)
63
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
64
+ .map((child) => mapScenario(child.scenario, projectId, ruleSetup)));
65
+ }
66
+ exports.mapRule = mapRule;
67
+ function mapScenario(scenario, projectId, setup) {
68
+ var _a, _b;
69
+ const tags = (0, utils_1.parseTags)(scenario.tags);
70
+ if (tags.externalId === undefined) {
71
+ return {
72
+ externalId: '',
73
+ name: scenario.name,
74
+ projectId
75
+ };
76
+ }
77
+ const exampleSteps = scenario.examples.map(mapExamples);
78
+ return {
79
+ setup: exampleSteps.concat(setup),
80
+ externalId: tags.externalId,
81
+ links: tags.links,
82
+ name: (_a = tags.name) !== null && _a !== void 0 ? _a : scenario.name,
83
+ title: tags.title,
84
+ description: (_b = tags.description) !== null && _b !== void 0 ? _b : scenario.description,
85
+ projectId,
86
+ steps: scenario.steps.map(mapStep),
87
+ workItemId: tags.workItemId,
88
+ namespace: tags.nameSpace,
89
+ classname: tags.className,
90
+ // Disable for now (BUG??)
91
+ // labels:
92
+ // tags.labels.length > 0
93
+ // ? tags.labels.map((label) => ({ name: label }))
94
+ // : undefined,
95
+ };
96
+ }
97
+ exports.mapScenario = mapScenario;
98
+ //TODO: Implement using "parameters" fields
99
+ function mapExamples(examples) {
100
+ var _a, _b, _c, _d;
101
+ let table = [];
102
+ const body = examples.tableBody.map((row) => row.cells.map((cell) => cell.value));
103
+ if (examples.tableHeader !== undefined) {
104
+ const header = (_a = examples.tableHeader) === null || _a === void 0 ? void 0 : _a.cells.map((cell) => cell.value);
105
+ table = body.map((row) => header.reduce((acc, key, i) => {
106
+ acc[key] = row[i];
107
+ return acc;
108
+ }, {}));
109
+ }
110
+ else {
111
+ table = body;
112
+ }
113
+ const description = [examples.description];
114
+ const tags = (0, utils_1.parseTags)(examples.tags);
115
+ if (table.length > 0) {
116
+ description.push(JSON.stringify(table));
117
+ }
118
+ return {
119
+ title: (_c = (_b = tags.title) !== null && _b !== void 0 ? _b : tags.name) !== null && _c !== void 0 ? _c : (examples.name !== '' ? examples.name : 'Parameters'),
120
+ description: (_d = tags.description) !== null && _d !== void 0 ? _d : description.join('\n\n'),
121
+ };
122
+ }
123
+ exports.mapExamples = mapExamples;
124
+ function mapStep(step) {
125
+ var _a, _b;
126
+ return {
127
+ title: `${step.keyword} ${step.text}`,
128
+ description: (_b = (_a = step.docString) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : mapDataTable(step.dataTable),
129
+ };
130
+ }
131
+ exports.mapStep = mapStep;
132
+ function mapDataTable(dataTable) {
133
+ if (dataTable === undefined) {
134
+ return undefined;
135
+ }
136
+ const keys = dataTable.rows[0].cells.map((cell) => cell.value);
137
+ const rows = dataTable.rows
138
+ .slice(1)
139
+ .map((row) => row.cells.map((cell) => cell.value));
140
+ const objects = rows.map((value) => keys.reduce((acc, key, i) => {
141
+ acc[key] = value[i];
142
+ return acc;
143
+ }, {}));
144
+ return JSON.stringify(objects);
145
+ }
146
+ exports.mapDataTable = mapDataTable;
147
+ //# sourceMappingURL=mappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.js","s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,SAAgB,OAAO,CAAC,IAAU;;IAChC,OAAO;QACL,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE;QACrC,WAAW,EAAE,MAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,OAAO,mCAAI,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC;KACrE,CAAC;AACJ,CAAC;AALD,0BAKC;AAED,SAAgB,YAAY,CAC1B,SAAgC;IAEhC,IAAI,SAAS,KAAK,SAAS,EAAE;QAC3B,OAAO,SAAS,CAAC;KAClB;IACD,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/D,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI;SACxB,KAAK,CAAC,CAAC,CAAC;SACR,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACjC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;QAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACpB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAA4B,CAAC,CACjC,CAAC;IACF,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAjBD,oCAiBC"}
@@ -1,6 +1,7 @@
1
+ import { AttachmentPut, AttachmentPutModelAutotestStepResults, AutotestResultsForTestRun, LinkPost } from 'testit-api-client';
1
2
  import { GherkinDocument, Pickle, PickleStep, TestCase, TestCaseFinished, TestCaseStarted, TestStepFinished, TestStepStarted } from '@cucumber/messages';
2
- import { TestResult, Attachment, TestResultStep, Link } from 'testit-js-commons';
3
3
  import { IStorage } from './types/storage';
4
+ import { AutotestPostWithWorkItemId } from './mappers';
4
5
  export declare class Storage implements IStorage {
5
6
  private gherkinDocuments;
6
7
  private pickles;
@@ -10,21 +11,22 @@ export declare class Storage implements IStorage {
10
11
  private testStepsStarted;
11
12
  private testStepsFinished;
12
13
  private messages;
13
- private resultLinks;
14
+ private links;
14
15
  private attachments;
15
- isResolvedTestCase(testCase: TestCase): boolean;
16
16
  saveGherkinDocument(document: GherkinDocument): void;
17
+ getAutotests(projectId: string): AutotestPostWithWorkItemId[];
17
18
  savePickle(pickle: Pickle): void;
19
+ isResolvedTestCase(testCase: TestCase): boolean;
18
20
  saveTestCase(testCase: TestCase): void;
19
21
  saveTestCaseStarted(testCaseStarted: TestCaseStarted): void;
20
22
  saveTestCaseFinished(testCaseFinished: TestCaseFinished): void;
21
23
  saveTestStepStarted(testStepStarted: TestStepStarted): void;
22
24
  saveTestStepFinished(testStepFinished: TestStepFinished): void;
23
- getTestResult(testId: string): TestResult;
24
- getStepResult(pickleStep: PickleStep, testCase: TestCase): TestResultStep;
25
+ getTestRunResults(configurationId: string): AutotestResultsForTestRun[];
26
+ getStepResult(pickleStep: PickleStep, testCase: TestCase): AttachmentPutModelAutotestStepResults;
25
27
  getStepMessage(pickleStep: PickleStep, testCase: TestCase): string | undefined;
26
- getAttachments(testCaseId: string): Attachment[] | undefined;
28
+ getAttachments(testCaseId: string): AttachmentPut[] | undefined;
27
29
  addMessage(testCaseId: string, message: string): void;
28
- addLinks(testCaseId: string, links: Link[]): void;
30
+ addLinks(testCaseId: string, links: LinkPost[]): void;
29
31
  addAttachment(testCaseId: string, attachmentId: string): void;
30
32
  }