testit-adapter-cucumber 1.0.1 → 1.0.2

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.
@@ -0,0 +1,34 @@
1
+ import { Formatter, IFormatterOptions } from '@cucumber/cucumber';
2
+ import { GherkinDocument, Pickle, TestCase, TestStepFinished, TestRunFinished, TestCaseStarted, TestCaseFinished, TestStepStarted, Meta, TestRunStarted } from '@cucumber/messages';
3
+ import { ClientConfigWithFile, IClient, LinkPost } from 'testit-api-client';
4
+ import { IStorage } from './types/storage';
5
+ import { IFormatter } from './types/formatter';
6
+ import { AutotestPostWithWorkItemId } from './mappers';
7
+ export declare class TestItFormatter extends Formatter implements IFormatter {
8
+ client: IClient;
9
+ storage: IStorage;
10
+ currentTestCaseId: string | undefined;
11
+ constructor(options: IFormatterOptions, config: Partial<ClientConfigWithFile>);
12
+ private testRunId;
13
+ private testRunStarted;
14
+ private attachmentsQueue;
15
+ onMeta(_meta: Meta): void;
16
+ onGherkinDocument(document: GherkinDocument): void;
17
+ onPickle(pickle: Pickle): void;
18
+ onTestRunStarted(_testRunStarted: TestRunStarted): void;
19
+ onTestCase(testCase: TestCase): void;
20
+ onTestCaseStarted(testCaseStarted: TestCaseStarted): void;
21
+ testStepStarted(testStepStarted: TestStepStarted): void;
22
+ onTestStepFinished(testStepFinished: TestStepFinished): void;
23
+ testCaseFinished(testCaseFinished: TestCaseFinished): void;
24
+ onTestRunFinished(_testRunFinished: TestRunFinished): void;
25
+ loadAutotest(autotestPost: AutotestPostWithWorkItemId): Promise<void>;
26
+ loadPassedAutotest(autotestPost: AutotestPostWithWorkItemId): Promise<void>;
27
+ createNewAutotest(autotestPost: AutotestPostWithWorkItemId): Promise<void>;
28
+ updateAutotest(autotestPost: AutotestPostWithWorkItemId): Promise<void>;
29
+ linkWorkItem(externalId: string, workItemId: string): Promise<void>;
30
+ addMessage(message: string): void;
31
+ addLinks(links: LinkPost[]): void;
32
+ addAttachments(attachments: string[]): void;
33
+ private logError;
34
+ }
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestItFormatter = void 0;
4
+ const cucumber_1 = require("@cucumber/cucumber");
5
+ const testit_api_client_1 = require("testit-api-client");
6
+ const storage_1 = require("./storage");
7
+ class TestItFormatter extends cucumber_1.Formatter {
8
+ constructor(options, config) {
9
+ super(options);
10
+ this.storage = new storage_1.Storage();
11
+ this.attachmentsQueue = [];
12
+ this.client = new testit_api_client_1.Client(config);
13
+ options.eventBroadcaster.on('envelope', (envelope) => {
14
+ if (envelope.meta) {
15
+ return this.onMeta(envelope.meta);
16
+ }
17
+ if (envelope.gherkinDocument) {
18
+ return this.onGherkinDocument(envelope.gherkinDocument);
19
+ }
20
+ if (envelope.pickle) {
21
+ return this.onPickle(envelope.pickle);
22
+ }
23
+ if (envelope.testCase) {
24
+ return this.onTestCase(envelope.testCase);
25
+ }
26
+ if (envelope.testRunStarted) {
27
+ return this.onTestRunStarted(envelope.testRunStarted);
28
+ }
29
+ if (envelope.testCaseStarted) {
30
+ return this.onTestCaseStarted(envelope.testCaseStarted);
31
+ }
32
+ if (envelope.testStepStarted) {
33
+ return this.testStepStarted(envelope.testStepStarted);
34
+ }
35
+ if (envelope.testStepFinished) {
36
+ return this.onTestStepFinished(envelope.testStepFinished);
37
+ }
38
+ if (envelope.testCaseFinished) {
39
+ return this.testCaseFinished(envelope.testCaseFinished);
40
+ }
41
+ if (envelope.testRunFinished) {
42
+ return this.onTestRunFinished(envelope.testRunFinished);
43
+ }
44
+ });
45
+ options.supportCodeLibrary.World.prototype.addMessage =
46
+ this.addMessage.bind(this);
47
+ options.supportCodeLibrary.World.prototype.addLinks =
48
+ this.addLinks.bind(this);
49
+ options.supportCodeLibrary.World.prototype.addAttachments =
50
+ this.addAttachments.bind(this);
51
+ }
52
+ onMeta(_meta) {
53
+ const { projectId, testRunId } = this.client.getConfig();
54
+ if (testRunId === undefined) {
55
+ this.testRunId = this.client
56
+ .createTestRun({
57
+ projectId,
58
+ })
59
+ .then((testRun) => testRun.id);
60
+ }
61
+ else {
62
+ this.testRunId = Promise.resolve(testRunId);
63
+ }
64
+ }
65
+ onGherkinDocument(document) {
66
+ this.storage.saveGherkinDocument(document);
67
+ }
68
+ onPickle(pickle) {
69
+ this.storage.savePickle(pickle);
70
+ }
71
+ onTestRunStarted(_testRunStarted) {
72
+ if (this.testRunId === undefined) {
73
+ throw new Error('TestRunId is not yet specified');
74
+ }
75
+ this.testRunStarted = this.testRunId.then((id) => this.client.startTestRun(id));
76
+ }
77
+ onTestCase(testCase) {
78
+ this.storage.saveTestCase(testCase);
79
+ }
80
+ onTestCaseStarted(testCaseStarted) {
81
+ this.currentTestCaseId = testCaseStarted.testCaseId;
82
+ this.storage.saveTestCaseStarted(testCaseStarted);
83
+ }
84
+ testStepStarted(testStepStarted) {
85
+ this.storage.saveTestStepStarted(testStepStarted);
86
+ }
87
+ onTestStepFinished(testStepFinished) {
88
+ this.storage.saveTestStepFinished(testStepFinished);
89
+ }
90
+ testCaseFinished(testCaseFinished) {
91
+ this.currentTestCaseId = undefined;
92
+ this.storage.saveTestCaseFinished(testCaseFinished);
93
+ }
94
+ onTestRunFinished(_testRunFinished) {
95
+ if (this.testRunId === undefined) {
96
+ throw new Error('TestRunId is not yet specified');
97
+ }
98
+ if (this.testRunStarted === undefined) {
99
+ throw new Error('Test run is not started yet');
100
+ }
101
+ Promise.all([
102
+ this.testRunId,
103
+ this.testRunStarted,
104
+ Promise.all(this.attachmentsQueue),
105
+ ])
106
+ .then(async ([id]) => {
107
+ const { configurationId } = this.client.getConfig();
108
+ const autotests = this.storage.getAutotests(this.client.getConfig().projectId);
109
+ const results = this.storage.getTestRunResults(configurationId);
110
+ await Promise.all(autotests.map((autotestPost) => {
111
+ const result = results.find((result) => result.autotestExternalId === autotestPost.externalId);
112
+ if (result === undefined) {
113
+ throw new Error(`Cannot find result for ${autotestPost.externalId} autotest`);
114
+ }
115
+ if (result.outcome !== 'Passed') {
116
+ return this.loadAutotest(autotestPost);
117
+ }
118
+ return this.loadPassedAutotest(autotestPost);
119
+ }));
120
+ return this.client.loadTestRunResults(id, results);
121
+ })
122
+ .catch((err) => {
123
+ var _a;
124
+ console.error(err);
125
+ (_a = this.testRunId) === null || _a === void 0 ? void 0 : _a.then((id) => this.client.completeTestRun(id));
126
+ });
127
+ }
128
+ async loadAutotest(autotestPost) {
129
+ var _a;
130
+ try {
131
+ await this.createNewAutotest(autotestPost);
132
+ }
133
+ catch (err) {
134
+ const axiosError = err;
135
+ if (((_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status) === 409) {
136
+ const [autotest] = await this.client.getAutotest({
137
+ projectId: this.client.getConfig().projectId,
138
+ externalId: autotestPost.externalId,
139
+ });
140
+ await this.updateAutotest(Object.assign(Object.assign({}, autotest), { links: autotestPost.links }));
141
+ }
142
+ else {
143
+ this.logError(axiosError);
144
+ }
145
+ }
146
+ }
147
+ async loadPassedAutotest(autotestPost) {
148
+ var _a;
149
+ try {
150
+ await this.createNewAutotest(autotestPost);
151
+ }
152
+ catch (err) {
153
+ const axiosError = err;
154
+ if (((_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status) === 409) {
155
+ await this.updateAutotest(autotestPost);
156
+ }
157
+ else {
158
+ this.logError(axiosError);
159
+ }
160
+ }
161
+ if (autotestPost.workItemId !== undefined) {
162
+ this.linkWorkItem(autotestPost.externalId, autotestPost.workItemId);
163
+ }
164
+ }
165
+ async createNewAutotest(autotestPost) {
166
+ await this.client.createAutotest(autotestPost);
167
+ }
168
+ async updateAutotest(autotestPost) {
169
+ await this.client.updateAutotest(autotestPost).catch(this.logError);
170
+ }
171
+ async linkWorkItem(externalId, workItemId) {
172
+ const [autotest] = await this.client
173
+ .getAutotest({
174
+ projectId: this.client.getConfig().projectId,
175
+ externalId: externalId,
176
+ })
177
+ .catch(() => []);
178
+ if ((autotest === null || autotest === void 0 ? void 0 : autotest.id) !== undefined) {
179
+ await this.client.linkToWorkItem(autotest.id, {
180
+ id: workItemId,
181
+ });
182
+ }
183
+ }
184
+ addMessage(message) {
185
+ if (this.currentTestCaseId === undefined) {
186
+ throw new Error('CurrentTestCaseId is not set');
187
+ }
188
+ this.storage.addMessage(this.currentTestCaseId, message);
189
+ }
190
+ addLinks(links) {
191
+ if (this.currentTestCaseId === undefined) {
192
+ throw new Error('CurrentTestCaseId is not set');
193
+ }
194
+ this.storage.addLinks(this.currentTestCaseId, links);
195
+ }
196
+ addAttachments(attachments) {
197
+ if (this.currentTestCaseId === undefined) {
198
+ throw new Error('CurrentTestCaseId is not set');
199
+ }
200
+ const currentTestCaseId = this.currentTestCaseId;
201
+ this.attachmentsQueue.push(...attachments.map(async (attachment) => {
202
+ const { id } = await this.client.loadAttachment(attachment);
203
+ if (id === undefined) {
204
+ // NOTE: Why?
205
+ console.warn('Attachment id is not returned');
206
+ return;
207
+ }
208
+ this.storage.addAttachment(currentTestCaseId, id);
209
+ }));
210
+ }
211
+ logError(err) {
212
+ var _a, _b;
213
+ 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);
214
+ }
215
+ }
216
+ exports.TestItFormatter = TestItFormatter;
217
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":";;;AAAA,iDAAkE;AAclE,yDAK2B;AAE3B,uCAAoC;AAKpC,MAAa,eAAgB,SAAQ,oBAAS;IAK5C,YACE,OAA0B,EAC1B,MAAqC;QAErC,KAAK,CAAC,OAAO,CAAC,CAAC;QAPjB,YAAO,GAAa,IAAI,iBAAO,EAAE,CAAC;QAmD1B,qBAAgB,GAAoB,EAAE,CAAC;QA3C7C,IAAI,CAAC,MAAM,GAAG,IAAI,0BAAM,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC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,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;AAlQD,0CAkQC"}
@@ -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,140 @@
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
+ throw new Error(`External id is not provided in ${scenario.name}`);
72
+ }
73
+ const exampleSteps = scenario.examples.map(mapExamples);
74
+ return {
75
+ setup: exampleSteps.concat(setup),
76
+ externalId: tags.externalId,
77
+ links: tags.links,
78
+ name: (_a = tags.name) !== null && _a !== void 0 ? _a : scenario.name,
79
+ title: tags.title,
80
+ description: (_b = tags.description) !== null && _b !== void 0 ? _b : scenario.description,
81
+ projectId,
82
+ steps: scenario.steps.map(mapStep),
83
+ workItemId: tags.workItemId,
84
+ // Disable for now (BUG??)
85
+ // labels:
86
+ // tags.labels.length > 0
87
+ // ? tags.labels.map((label) => ({ name: label }))
88
+ // : undefined,
89
+ };
90
+ }
91
+ exports.mapScenario = mapScenario;
92
+ function mapExamples(examples) {
93
+ var _a, _b, _c, _d;
94
+ let table = [];
95
+ const body = examples.tableBody.map((row) => row.cells.map((cell) => cell.value));
96
+ if (examples.tableHeader !== undefined) {
97
+ const header = (_a = examples.tableHeader) === null || _a === void 0 ? void 0 : _a.cells.map((cell) => cell.value);
98
+ table = body.map((row) => header.reduce((acc, key, i) => {
99
+ acc[key] = row[i];
100
+ return acc;
101
+ }, {}));
102
+ }
103
+ else {
104
+ table = body;
105
+ }
106
+ const description = [examples.description];
107
+ const tags = (0, utils_1.parseTags)(examples.tags);
108
+ if (table.length > 0) {
109
+ description.push(JSON.stringify(table));
110
+ }
111
+ return {
112
+ title: (_c = (_b = tags.title) !== null && _b !== void 0 ? _b : tags.name) !== null && _c !== void 0 ? _c : examples.name,
113
+ description: (_d = tags.description) !== null && _d !== void 0 ? _d : description.join('\n\n'),
114
+ };
115
+ }
116
+ exports.mapExamples = mapExamples;
117
+ function mapStep(step) {
118
+ var _a, _b;
119
+ return {
120
+ title: `${step.keyword} ${step.text}`,
121
+ description: (_b = (_a = step.docString) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : mapDataTable(step.dataTable),
122
+ };
123
+ }
124
+ exports.mapStep = mapStep;
125
+ function mapDataTable(dataTable) {
126
+ if (dataTable === undefined) {
127
+ return undefined;
128
+ }
129
+ const keys = dataTable.rows[0].cells.map((cell) => cell.value);
130
+ const rows = dataTable.rows
131
+ .slice(1)
132
+ .map((row) => row.cells.map((cell) => cell.value));
133
+ const objects = rows.map((value) => keys.reduce((acc, key, i) => {
134
+ acc[key] = value[i];
135
+ return acc;
136
+ }, {}));
137
+ return JSON.stringify(objects);
138
+ }
139
+ exports.mapDataTable = mapDataTable;
140
+ //# sourceMappingURL=mappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.js","sourceRoot":"","sources":["../src/mappers.ts"],"names":[],"mappings":";;;AAAA,iDAS4B;AAE5B,mCAAoC;AAMpC,SAAgB,SAAS,CAAC,MAA4B;IACpD,QAAQ,MAAM,EAAE;QACd,KAAK,+BAAoB,CAAC,MAAM;YAC9B,OAAO,QAAQ,CAAC;QAClB,KAAK,+BAAoB,CAAC,MAAM;YAC9B,OAAO,QAAQ,CAAC;QAClB,KAAK,+BAAoB,CAAC,OAAO;YAC/B,OAAO,SAAS,CAAC;QACnB,KAAK,+BAAoB,CAAC,OAAO;YAC/B,OAAO,SAAS,CAAC;QACnB,KAAK,+BAAoB,CAAC,OAAO,CAAC;QAClC,KAAK,+BAA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,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"}
@@ -0,0 +1,31 @@
1
+ import { AttachmentPut, AttachmentPutModelAutotestStepResults, AutotestResultsForTestRun, LinkPost } from 'testit-api-client';
2
+ import { GherkinDocument, Pickle, PickleStep, TestCase, TestCaseFinished, TestCaseStarted, TestStepFinished, TestStepStarted } from '@cucumber/messages';
3
+ import { IStorage } from './types/storage';
4
+ import { AutotestPostWithWorkItemId } from './mappers';
5
+ export declare class Storage implements IStorage {
6
+ private gherkinDocuments;
7
+ private pickles;
8
+ private testCases;
9
+ private testCasesStarted;
10
+ private testCasesFinished;
11
+ private testStepsStarted;
12
+ private testStepsFinished;
13
+ private messages;
14
+ private links;
15
+ private attachments;
16
+ saveGherkinDocument(document: GherkinDocument): void;
17
+ getAutotests(projectId: string): AutotestPostWithWorkItemId[];
18
+ savePickle(pickle: Pickle): void;
19
+ saveTestCase(testCase: TestCase): void;
20
+ saveTestCaseStarted(testCaseStarted: TestCaseStarted): void;
21
+ saveTestCaseFinished(testCaseFinished: TestCaseFinished): void;
22
+ saveTestStepStarted(testStepStarted: TestStepStarted): void;
23
+ saveTestStepFinished(testStepFinished: TestStepFinished): void;
24
+ getTestRunResults(configurationId: string): AutotestResultsForTestRun[];
25
+ getStepResult(pickleStep: PickleStep, testCase: TestCase): AttachmentPutModelAutotestStepResults;
26
+ getStepMessage(pickleStep: PickleStep, testCase: TestCase): string | undefined;
27
+ getAttachments(testCaseId: string): AttachmentPut[] | undefined;
28
+ addMessage(testCaseId: string, message: string): void;
29
+ addLinks(testCaseId: string, links: LinkPost[]): void;
30
+ addAttachment(testCaseId: string, attachmentId: string): void;
31
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Storage = void 0;
4
+ const mappers_1 = require("./mappers");
5
+ const utils_1 = require("./utils");
6
+ class Storage {
7
+ constructor() {
8
+ this.gherkinDocuments = [];
9
+ this.pickles = [];
10
+ this.testCases = [];
11
+ this.testCasesStarted = [];
12
+ this.testCasesFinished = [];
13
+ this.testStepsStarted = [];
14
+ this.testStepsFinished = [];
15
+ this.messages = {};
16
+ this.links = {};
17
+ this.attachments = {};
18
+ }
19
+ saveGherkinDocument(document) {
20
+ this.gherkinDocuments.push(document);
21
+ }
22
+ getAutotests(projectId) {
23
+ return this.gherkinDocuments.flatMap((document) => (0, mappers_1.mapDocument)(document, projectId));
24
+ }
25
+ savePickle(pickle) {
26
+ this.pickles.push(pickle);
27
+ }
28
+ saveTestCase(testCase) {
29
+ this.testCases.push(testCase);
30
+ }
31
+ saveTestCaseStarted(testCaseStarted) {
32
+ this.testCasesStarted.push(testCaseStarted);
33
+ }
34
+ saveTestCaseFinished(testCaseFinished) {
35
+ this.testCasesFinished.push(testCaseFinished);
36
+ }
37
+ saveTestStepStarted(testStepStarted) {
38
+ this.testStepsStarted.push(testStepStarted);
39
+ }
40
+ saveTestStepFinished(testStepFinished) {
41
+ this.testStepsFinished.push(testStepFinished);
42
+ }
43
+ getTestRunResults(configurationId) {
44
+ var _a, _b, _c;
45
+ const results = [];
46
+ for (const pickle of this.pickles) {
47
+ const tags = (0, utils_1.parseTags)(pickle.tags);
48
+ if (tags.externalId === undefined) {
49
+ throw new Error('External id is not provided');
50
+ }
51
+ const testCase = this.testCases.find((testCase) => testCase.pickleId === pickle.id);
52
+ if (testCase === undefined) {
53
+ throw new Error('TestCase not found');
54
+ }
55
+ const testCaseStarted = this.testCasesStarted.find((testCase) => testCase.id === testCase.id);
56
+ if (testCaseStarted === undefined) {
57
+ throw new Error('TestCaseStarted not found');
58
+ }
59
+ const testCaseFinished = this.testCasesFinished.find((testCase) => testCase.testCaseStartedId === testCaseStarted.id);
60
+ if (testCaseFinished === undefined) {
61
+ throw new Error('TestCaseFinished not found');
62
+ }
63
+ const steps = pickle.steps
64
+ .map((step) => this.getStepResult(step, testCase))
65
+ .filter((item, i, arr) => {
66
+ var _a;
67
+ const prevOutcome = (_a = arr[i - 1]) === null || _a === void 0 ? void 0 : _a.outcome;
68
+ if (item.outcome === 'Skipped' &&
69
+ prevOutcome !== undefined &&
70
+ ['Failed', 'Skipped'].includes(prevOutcome)) {
71
+ return false;
72
+ }
73
+ return true;
74
+ });
75
+ const messages = [];
76
+ for (const step of pickle.steps) {
77
+ const message = this.getStepMessage(step, testCase);
78
+ if (message !== undefined) {
79
+ messages.push(message);
80
+ }
81
+ }
82
+ const links = (_a = this.links[testCase.id]) !== null && _a !== void 0 ? _a : [];
83
+ links.push(...tags.links);
84
+ const result = {
85
+ autotestExternalId: tags.externalId,
86
+ configurationId,
87
+ links,
88
+ stepResults: steps,
89
+ outcome: (0, utils_1.calculateResultOutcome)(steps.map((step) => step.outcome)),
90
+ startedOn: (0, mappers_1.mapDate)(testCaseStarted.timestamp.seconds),
91
+ completeOn: (0, mappers_1.mapDate)(testCaseFinished.timestamp.seconds),
92
+ duration: testCaseFinished.timestamp.seconds -
93
+ testCaseStarted.timestamp.seconds,
94
+ message: (_c = (_b = this.messages[testCase.id]) === null || _b === void 0 ? void 0 : _b.join('\n\n')) !== null && _c !== void 0 ? _c : undefined,
95
+ traces: messages.join('\n\n'),
96
+ attachments: this.getAttachments(testCase.id),
97
+ };
98
+ results.push(result);
99
+ }
100
+ return results;
101
+ }
102
+ getStepResult(pickleStep, testCase) {
103
+ const testStep = testCase.testSteps.find((step) => step.pickleStepId === pickleStep.id);
104
+ if (testStep === undefined) {
105
+ throw new Error('TestCase step not found');
106
+ }
107
+ const testStepStarted = this.testStepsStarted.find((step) => step.testStepId === testStep.id);
108
+ if (testStepStarted === undefined) {
109
+ throw new Error('TestStepStarted not found');
110
+ }
111
+ const testStepFinished = this.testStepsFinished.find((step) => step.testStepId === testStepStarted.testStepId);
112
+ if (testStepFinished === undefined) {
113
+ throw new Error('TestStepFinished not found');
114
+ }
115
+ return {
116
+ title: pickleStep.text,
117
+ startedOn: (0, mappers_1.mapDate)(testStepStarted.timestamp.seconds),
118
+ duration: testStepFinished.testStepResult.duration.seconds,
119
+ completedOn: (0, mappers_1.mapDate)(testStepFinished.timestamp.seconds),
120
+ outcome: (0, mappers_1.mapStatus)(testStepFinished.testStepResult.status),
121
+ };
122
+ }
123
+ getStepMessage(pickleStep, testCase) {
124
+ const testStep = testCase.testSteps.find((step) => step.pickleStepId === pickleStep.id);
125
+ if (testStep === undefined) {
126
+ throw new Error('TestCase step not found');
127
+ }
128
+ const testStepStarted = this.testStepsStarted.find((step) => step.testStepId === testStep.id);
129
+ if (testStepStarted === undefined) {
130
+ throw new Error('TestStepStarted not found');
131
+ }
132
+ const testStepFinished = this.testStepsFinished.find((step) => step.testStepId === testStepStarted.testStepId);
133
+ if (testStepFinished === undefined) {
134
+ throw new Error('TestStepFinished not found');
135
+ }
136
+ return testStepFinished.testStepResult.message;
137
+ }
138
+ getAttachments(testCaseId) {
139
+ if (this.attachments[testCaseId] === undefined) {
140
+ return undefined;
141
+ }
142
+ return this.attachments[testCaseId].map((id) => ({ id }));
143
+ }
144
+ addMessage(testCaseId, message) {
145
+ if (this.messages[testCaseId] === undefined) {
146
+ this.messages[testCaseId] = [message];
147
+ }
148
+ else {
149
+ this.messages[testCaseId].push(message);
150
+ }
151
+ }
152
+ addLinks(testCaseId, links) {
153
+ if (this.links[testCaseId] === undefined) {
154
+ this.links[testCaseId] = links;
155
+ }
156
+ else {
157
+ this.links[testCaseId].push(...links);
158
+ }
159
+ }
160
+ addAttachment(testCaseId, attachmentId) {
161
+ if (this.attachments[testCaseId] === undefined) {
162
+ this.attachments[testCaseId] = [attachmentId];
163
+ }
164
+ else {
165
+ this.attachments[testCaseId].concat(attachmentId);
166
+ }
167
+ }
168
+ }
169
+ exports.Storage = Storage;
170
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":";;;AAiBA,uCAKmB;AACnB,mCAA4D;AAE5D,MAAa,OAAO;IAApB;QACU,qBAAgB,GAAsB,EAAE,CAAC;QACzC,YAAO,GAAa,EAAE,CAAC;QACvB,cAAS,GAAe,EAAE,CAAC;QAC3B,qBAAgB,GAAsB,EAAE,CAAC;QACzC,sBAAiB,GAAuB,EAAE,CAAC;QAC3C,qBAAgB,GAAsB,EAAE,CAAC;QACzC,sBAAiB,GAAuB,EAAE,CAAC;QAC3C,aAAQ,GAA6B,EAAE,CAAC;QACxC,UAAK,GAA+B,EAAE,CAAC;QACvC,gBAAW,GAA6B,EAAE,CAAC;IAgLrD,CAAC;IA9KC,mBAAmB,CAAC,QAAyB;QAC3C,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IACD,YAAY,CAAC,SAAiB;QAC5B,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAChD,IAAA,qBAAW,EAAC,QAAQ,EAAE,SAAS,CAAC,CACjC,CAAC;IACJ,CAAC;IACD,UAAU,CAAC,MAAc;QACvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IACD,YAAY,CAAC,QAAkB;QAC7B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CA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WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;SAC/C;aAAM;YACL,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;SACnD;IACH,CAAC;CACF;AA1LD,0BA0LC"}
@@ -0,0 +1,17 @@
1
+ import { GherkinDocument, Meta, Pickle, TestCase, TestCaseFinished, TestCaseStarted, TestRunFinished, TestRunStarted, TestStepFinished, TestStepStarted } from '@cucumber/messages';
2
+ import { IClient } from 'testit-api-client';
3
+ import { IStorage } from './storage';
4
+ export interface IFormatter {
5
+ client: IClient;
6
+ storage: IStorage;
7
+ onMeta(meta: Meta): void;
8
+ onGherkinDocument(document: GherkinDocument): void;
9
+ onPickle(pickle: Pickle): void;
10
+ onTestRunStarted(testRunStarted: TestRunStarted): void;
11
+ onTestCase(testCase: TestCase): void;
12
+ onTestCaseStarted(testCaseStarted: TestCaseStarted): void;
13
+ testStepStarted(testStepStarted: TestStepStarted): void;
14
+ onTestStepFinished(testStepFinished: TestStepFinished): void;
15
+ testCaseFinished(testCaseFinished: TestCaseFinished): void;
16
+ onTestRunFinished(_testRunFinished: TestRunFinished): void;
17
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/types/formatter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { GherkinDocument, Pickle, TestCase, TestCaseFinished, TestCaseStarted, TestStepFinished, TestStepStarted } from '@cucumber/messages';
2
+ import { AutotestResultsForTestRun, LinkPost } from 'testit-api-client';
3
+ import { AutotestPostWithWorkItemId } from '../mappers';
4
+ export interface IStorage {
5
+ saveGherkinDocument(document: GherkinDocument): void;
6
+ getAutotests(projectId: string): AutotestPostWithWorkItemId[];
7
+ savePickle(pickle: Pickle): void;
8
+ saveTestCase(testCase: TestCase): void;
9
+ saveTestCaseStarted(testCaseStarted: TestCaseStarted): void;
10
+ saveTestCaseFinished(testCaseFinished: TestCaseFinished): void;
11
+ saveTestStepStarted(testStepStarted: TestStepStarted): void;
12
+ saveTestStepFinished(testStepFinished: TestStepFinished): void;
13
+ getTestRunResults(configurationId: string): AutotestResultsForTestRun[];
14
+ addMessage(testCaseId: string, message: string): void;
15
+ addLinks(testCaseId: string, links: LinkPost[]): void;
16
+ addAttachment(testCaseId: string, attachmentId: string): void;
17
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/types/storage.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import { Link } from 'testit-api-client';
2
+ export declare type ParsedTags = {
3
+ externalId?: string;
4
+ links: Omit<Link, 'id'>[];
5
+ title?: string;
6
+ workItemId?: string;
7
+ name?: string;
8
+ description?: string;
9
+ labels: string[];
10
+ };
11
+ export declare enum TagType {
12
+ ExternalId = 0,
13
+ LinkUrl = 1,
14
+ Link = 2,
15
+ Title = 3,
16
+ WorkItemId = 4,
17
+ Name = 5,
18
+ Description = 6,
19
+ Label = 7,
20
+ Unknown = 8
21
+ }
22
+ export declare const tags: Record<keyof ParsedTags, string>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tags = exports.TagType = void 0;
4
+ var TagType;
5
+ (function (TagType) {
6
+ TagType[TagType["ExternalId"] = 0] = "ExternalId";
7
+ TagType[TagType["LinkUrl"] = 1] = "LinkUrl";
8
+ TagType[TagType["Link"] = 2] = "Link";
9
+ TagType[TagType["Title"] = 3] = "Title";
10
+ TagType[TagType["WorkItemId"] = 4] = "WorkItemId";
11
+ TagType[TagType["Name"] = 5] = "Name";
12
+ TagType[TagType["Description"] = 6] = "Description";
13
+ TagType[TagType["Label"] = 7] = "Label";
14
+ TagType[TagType["Unknown"] = 8] = "Unknown";
15
+ })(TagType = exports.TagType || (exports.TagType = {}));
16
+ exports.tags = {
17
+ externalId: 'ExternalId',
18
+ links: 'Link',
19
+ title: 'Title',
20
+ name: 'DisplayName',
21
+ workItemId: 'WorkItemId',
22
+ description: 'Description',
23
+ labels: 'Label',
24
+ };
25
+ //# sourceMappingURL=tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../../src/types/tags.ts"],"names":[],"mappings":";;;AAYA,IAAY,OAUX;AAVD,WAAY,OAAO;IACjB,iDAAU,CAAA;IACV,2CAAO,CAAA;IACP,qCAAI,CAAA;IACJ,uCAAK,CAAA;IACL,iDAAU,CAAA;IACV,qCAAI,CAAA;IACJ,mDAAW,CAAA;IACX,uCAAK,CAAA;IACL,2CAAO,CAAA;AACT,CAAC,EAVW,OAAO,GAAP,eAAO,KAAP,eAAO,QAUlB;AAEY,QAAA,IAAI,GAAqC;IACpD,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,aAAa;IACnB,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,aAAa;IAC1B,MAAM,EAAE,OAAO;CAChB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { World } from '@cucumber/cucumber';
2
+ import { LinkPost } from 'testit-api-client';
3
+ export interface TestItWorld extends World {
4
+ addMessage(message: string): void;
5
+ addLinks(links: LinkPost[]): void;
6
+ addAttachments(attachments: string[]): void;
7
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=world.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"world.js","sourceRoot":"","sources":["../../src/types/world.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { Tag } from '@cucumber/messages';
2
+ import { Link, OutcomeType } from 'testit-api-client';
3
+ import { ParsedTags, TagType } from './types/tags';
4
+ export declare function getTagType(tag: string): TagType;
5
+ export declare function getExternalId(tag: string): string;
6
+ export declare function getLinkUrl(tag: string): string;
7
+ export declare function getLink(tag: string): Omit<Link, 'id'>;
8
+ export declare function getTitle(tag: string): string;
9
+ export declare function getWorkItemId(tag: string): string;
10
+ export declare function getName(tag: string): string;
11
+ export declare function getDescription(tag: string): string;
12
+ export declare function getLabel(tag: string): string;
13
+ export declare function parseTags(tags: readonly Pick<Tag, 'name'>[]): ParsedTags;
14
+ export declare function calculateResultOutcome(outcomes: (OutcomeType | undefined)[]): OutcomeType;
package/dist/utils.js ADDED
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateResultOutcome = exports.parseTags = exports.getLabel = exports.getDescription = exports.getName = exports.getWorkItemId = exports.getTitle = exports.getLink = exports.getLinkUrl = exports.getExternalId = exports.getTagType = void 0;
4
+ const tags_1 = require("./types/tags");
5
+ function getTagType(tag) {
6
+ if (new RegExp(`^@${tags_1.tags.externalId}=.+$`).test(tag)) {
7
+ return tags_1.TagType.ExternalId;
8
+ }
9
+ if (new RegExp(`^@${tags_1.tags.links}=.+$`).test(tag)) {
10
+ // Check if it is JSON
11
+ if (tag.endsWith('}')) {
12
+ return tags_1.TagType.Link;
13
+ }
14
+ return tags_1.TagType.LinkUrl;
15
+ }
16
+ if (new RegExp(`^@${tags_1.tags.title}=.+$`).test(tag)) {
17
+ return tags_1.TagType.Title;
18
+ }
19
+ if (new RegExp(`^@${tags_1.tags.workItemId}=.+$`).test(tag)) {
20
+ return tags_1.TagType.WorkItemId;
21
+ }
22
+ if (new RegExp(`^@${tags_1.tags.name}=.+$`).test(tag)) {
23
+ return tags_1.TagType.Name;
24
+ }
25
+ if (new RegExp(`^@${tags_1.tags.description}=.+$`).test(tag)) {
26
+ return tags_1.TagType.Description;
27
+ }
28
+ if (new RegExp(`^@${tags_1.tags.labels}=.+$`).test(tag)) {
29
+ return tags_1.TagType.Label;
30
+ }
31
+ return tags_1.TagType.Unknown;
32
+ }
33
+ exports.getTagType = getTagType;
34
+ function getExternalId(tag) {
35
+ return tag.replace(new RegExp(`^@${tags_1.tags.externalId}=`), '');
36
+ }
37
+ exports.getExternalId = getExternalId;
38
+ function getLinkUrl(tag) {
39
+ return tag.replace(new RegExp(`^@${tags_1.tags.links}=`), '');
40
+ }
41
+ exports.getLinkUrl = getLinkUrl;
42
+ function getLink(tag) {
43
+ const linkData = JSON.parse(getLinkUrl(tag));
44
+ return linkData;
45
+ }
46
+ exports.getLink = getLink;
47
+ function getTitle(tag) {
48
+ return tag.replace(new RegExp(`^@${tags_1.tags.title}=`), '');
49
+ }
50
+ exports.getTitle = getTitle;
51
+ function getWorkItemId(tag) {
52
+ return tag.replace(new RegExp(`^@${tags_1.tags.workItemId}=`), '');
53
+ }
54
+ exports.getWorkItemId = getWorkItemId;
55
+ function getName(tag) {
56
+ return tag.replace(new RegExp(`^@${tags_1.tags.name}=`), '');
57
+ }
58
+ exports.getName = getName;
59
+ function getDescription(tag) {
60
+ return tag.replace(new RegExp(`^@${tags_1.tags.description}=`), '');
61
+ }
62
+ exports.getDescription = getDescription;
63
+ function getLabel(tag) {
64
+ return tag.replace(new RegExp(`^@${tags_1.tags.labels}=`), '');
65
+ }
66
+ exports.getLabel = getLabel;
67
+ function parseTags(tags) {
68
+ var _a, _b, _c;
69
+ const parsedTags = { links: [], labels: [] };
70
+ for (const tag of tags) {
71
+ switch (getTagType(tag.name)) {
72
+ case tags_1.TagType.ExternalId:
73
+ parsedTags.externalId = getExternalId(tag.name);
74
+ continue;
75
+ case tags_1.TagType.LinkUrl: {
76
+ (_a = parsedTags.links) === null || _a === void 0 ? void 0 : _a.push({ url: getLinkUrl(tag.name) });
77
+ continue;
78
+ }
79
+ case tags_1.TagType.Link: {
80
+ (_b = parsedTags.links) === null || _b === void 0 ? void 0 : _b.push(getLink(tag.name));
81
+ continue;
82
+ }
83
+ case tags_1.TagType.Title: {
84
+ parsedTags.title = getTitle(tag.name);
85
+ continue;
86
+ }
87
+ case tags_1.TagType.WorkItemId: {
88
+ parsedTags.workItemId = getWorkItemId(tag.name);
89
+ continue;
90
+ }
91
+ case tags_1.TagType.Name: {
92
+ parsedTags.name = getName(tag.name);
93
+ continue;
94
+ }
95
+ case tags_1.TagType.Description: {
96
+ parsedTags.description = getDescription(tag.name);
97
+ continue;
98
+ }
99
+ case tags_1.TagType.Label: {
100
+ (_c = parsedTags.labels) === null || _c === void 0 ? void 0 : _c.push(getLabel(tag.name));
101
+ continue;
102
+ }
103
+ case tags_1.TagType.Unknown:
104
+ continue;
105
+ default:
106
+ throw new Error('Unknown tag type');
107
+ }
108
+ }
109
+ return parsedTags;
110
+ }
111
+ exports.parseTags = parseTags;
112
+ function calculateResultOutcome(outcomes) {
113
+ if (outcomes.some((outcome) => outcome === 'Failed')) {
114
+ return 'Failed';
115
+ }
116
+ if (outcomes.some((outcome) => outcome === 'Blocked')) {
117
+ return 'Blocked';
118
+ }
119
+ if (outcomes.some((outcome) => outcome === 'Skipped')) {
120
+ return 'Skipped';
121
+ }
122
+ if (outcomes.every((outcome) => outcome === 'Passed')) {
123
+ return 'Passed';
124
+ }
125
+ throw new Error('Cannot calculate result outcome');
126
+ }
127
+ exports.calculateResultOutcome = calculateResultOutcome;
128
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAEA,uCAAyD;AAEzD,SAAgB,UAAU,CAAC,GAAW;IACpC,IAAI,IAAI,MAAM,CAAC,KAAK,WAAI,CAAC,UAAU,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACpD,OAAO,cAAO,CAAC,UAAU,CAAC;KAC3B;IACD,IAAI,IAAI,MAAM,CAAC,KAAK,WAAI,CAAC,KAAK,MAAM,CAAC,CAAC,IAAI,CAAC,GAA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CAAC,OAAO;gBAClB,SAAS;YACX;gBACE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;SACvC;KACF;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AA1CD,8BA0CC;AAED,SAAgB,sBAAsB,CACpC,QAAqC;IAErC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,QAAQ,CAAC,EAAE;QACpD,OAAO,QAAQ,CAAC;KACjB;IACD,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,SAAS,CAAC,EAAE;QACrD,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,SAAS,CAAC,EAAE;QACrD,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,QAAQ,CAAC,EAAE;QACrD,OAAO,QAAQ,CAAC;KACjB;IACD,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACrD,CAAC;AAhBD,wDAgBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-adapter-cucumber",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Adapter provides formatter for cucumber output and some additional methods to Cucumber world.",
5
5
  "main": "dist/formatter.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "@cucumber/cucumber": "^7.3.1",
21
21
  "@cucumber/messages": "^17.1.1",
22
- "testit-api-client": "^1.0.0"
22
+ "testit-api-client": "^1.0.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@babel/preset-env": "^7.15.8",
@@ -40,5 +40,10 @@
40
40
  "bugs": {
41
41
  "url": "https://github.com/testit-tms/adapters-js/issues"
42
42
  },
43
- "homepage": "https://github.com/testit-tms/adapters-js"
43
+ "homepage": "https://github.com/testit-tms/adapters-js",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/testit-tms/adapters-js.git"
47
+ },
48
+ "types": "./dist\\formatter.d.ts"
44
49
  }
package/readme.md CHANGED
@@ -38,6 +38,15 @@ And fill object with your configuration. Formatter sends results to TestIt.
38
38
 
39
39
  > TestRunId is optional. If it's not provided than it create automatically.
40
40
 
41
+ Add to `cucumber.js` file
42
+
43
+ ```js
44
+ module.exports = {
45
+ default:
46
+ '-f ./testitFormatter.js',
47
+ };
48
+ ```
49
+
41
50
  Formatter provides additional methods to World:
42
51
 
43
52
  - addMessage - adds message to autotest