@dev-blinq/cucumber-js 1.0.96 → 1.0.97

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.
@@ -1,11 +1,19 @@
1
1
  import Formatter, { IFormatterOptions } from '.';
2
+ import ReportGenerator from './helpers/report_generator';
2
3
  export default class BVTAnalysisFormatter extends Formatter {
4
+ static reportGenerator: ReportGenerator;
5
+ static reRunFailedStepsIndex: {
6
+ testCaseId: string;
7
+ failedStepIndex: number;
8
+ }[] | null;
3
9
  private reportGenerator;
4
10
  private uploader;
5
11
  private exit;
6
12
  private START;
7
13
  private runName;
14
+ private failedStepsIndex;
8
15
  private summaryFormatter;
16
+ private rootCauseArray;
9
17
  constructor(options: IFormatterOptions);
10
18
  private sendEvent;
11
19
  private uploadReport;
@@ -15,6 +23,7 @@ export default class BVTAnalysisFormatter extends Formatter {
15
23
  private processTestCase;
16
24
  private uploadFinalReport;
17
25
  private retrain;
26
+ private rerun;
18
27
  private call_cucumber_client;
19
28
  private getAppDataDir;
20
29
  }
@@ -18,6 +18,8 @@ const api_1 = require("./api");
18
18
  const summary_formatter_1 = __importDefault(require("./summary_formatter"));
19
19
  const constants_1 = require("./helpers/constants");
20
20
  const axios_client_1 = require("../configuration/axios_client");
21
+ const util_1 = require("util");
22
+ const child_process_2 = require("child_process");
21
23
  //User token
22
24
  const TOKEN = process.env.TOKEN;
23
25
  class BVTAnalysisFormatter extends _1.default {
@@ -26,22 +28,40 @@ class BVTAnalysisFormatter extends _1.default {
26
28
  this.reportGenerator = new report_generator_1.default();
27
29
  this.uploader = new uploader_1.default(this.reportGenerator);
28
30
  this.exit = false;
31
+ this.rootCauseArray = [];
29
32
  this.summaryFormatter = new summary_formatter_1.default(options);
33
+ BVTAnalysisFormatter.reportGenerator = this.reportGenerator;
34
+ this.rootCauseArray = [];
35
+ this.failedStepsIndex = [];
36
+ BVTAnalysisFormatter.reRunFailedStepsIndex = process.env.RERUN
37
+ ? JSON.parse(process.env.RERUN)
38
+ : null;
30
39
  if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {
31
40
  throw new Error('TOKEN must be set');
32
41
  }
33
42
  this.sendEvent(constants_1.ActionEvents.cli_run_tests);
34
- options.eventBroadcaster.on('envelope', async (envelope) => {
43
+ options.eventBroadcaster.on('envelope', async (envelope, data) => {
44
+ if ((0, value_checker_1.doesHaveValue)(envelope.testCaseFinished) && data) {
45
+ const { rootCause, report } = data;
46
+ if (!rootCause.status) {
47
+ console.error(`Root cause: ${rootCause.failClass}\n, ${rootCause.analysis}\nfailing step: ${rootCause.failedStep}`);
48
+ this.rootCauseArray.push({ rootCause, report });
49
+ this.failedStepsIndex.push({
50
+ testCaseId: report.id,
51
+ failedStepIndex: rootCause.failedStep,
52
+ });
53
+ }
54
+ return;
55
+ }
35
56
  await this.reportGenerator.handleMessage(envelope);
36
57
  if ((0, value_checker_1.doesHaveValue)(envelope.meta) &&
37
58
  (0, value_checker_1.doesHaveValue)(envelope.meta.runName)) {
38
59
  this.runName = envelope.meta.runName;
39
60
  }
40
61
  if ((0, value_checker_1.doesHaveValue)(envelope.testRunFinished)) {
41
- const report = this.reportGenerator.getReport();
42
62
  this.START = Date.now();
43
63
  if (process.env.BVT_FORMATTER === 'ANALYSIS') {
44
- await this.analyzeReport(report);
64
+ await this.analyzeReport();
45
65
  }
46
66
  else {
47
67
  // await this.uploadReport(report)
@@ -94,10 +114,10 @@ class BVTAnalysisFormatter extends _1.default {
94
114
  }, 100); // check every 100ms
95
115
  });
96
116
  }
97
- async analyzeReport(report) {
98
- if (report.result.status === 'PASSED' ||
117
+ async analyzeReport() {
118
+ if (this.rootCauseArray.length === 0 ||
99
119
  process.env.NO_RETRAIN === 'false') {
100
- if (report.result.status === 'PASSED') {
120
+ if (this.rootCauseArray.length === 0) {
101
121
  this.log('No test failed. No need to retrain\n');
102
122
  }
103
123
  if (process.env.NO_RETRAIN === 'false') {
@@ -110,55 +130,38 @@ class BVTAnalysisFormatter extends _1.default {
110
130
  }
111
131
  //checking if the type of report.result is JsonResultFailed or not
112
132
  this.log('Some tests failed, starting the retraining...\n');
113
- if (!('startTime' in report.result) || !('endTime' in report.result)) {
114
- this.log('Unknown error occured,not retraining\n');
115
- return;
116
- }
117
- await this.processTestCases(report);
133
+ await this.processTestCases();
118
134
  if (this.reportGenerator.getReport().result.status === 'FAILED') {
119
135
  process.exit(1);
120
136
  }
121
137
  process.exit(0);
122
138
  }
123
- async processTestCases(report) {
124
- const finalTestCases = [];
125
- for (const testCase of report.testCases) {
126
- const modifiedTestCase = await this.processTestCase(testCase, report);
127
- finalTestCases.push(modifiedTestCase);
139
+ async processTestCases() {
140
+ for (const { rootCause, report } of this.rootCauseArray) {
141
+ await this.processTestCase(rootCause, report);
128
142
  }
129
- const finalResult = finalTestCases.some((tc) => tc.result.status !== 'PASSED')
130
- ? report.result
131
- : {
132
- ...report.result,
133
- status: 'PASSED',
134
- };
135
- return {
136
- result: finalResult,
137
- testCases: finalTestCases,
138
- env: report.env,
139
- };
140
143
  }
141
- async processTestCase(testCase, report) {
142
- if (testCase.result.status === 'PASSED') {
143
- return testCase;
144
+ async processTestCase(rootCause, report) {
145
+ const failedTestSteps = rootCause.failedStep;
146
+ if (BVTAnalysisFormatter.reRunFailedStepsIndex &&
147
+ BVTAnalysisFormatter.reRunFailedStepsIndex.length > 0) {
148
+ const previousRun = BVTAnalysisFormatter.reRunFailedStepsIndex[0];
149
+ if (previousRun.failedStepIndex === failedTestSteps) {
150
+ console.log('Same step has failed again, skipping retraining');
151
+ BVTAnalysisFormatter.reRunFailedStepsIndex.shift();
152
+ return;
153
+ }
154
+ BVTAnalysisFormatter.reRunFailedStepsIndex.shift();
144
155
  }
145
- const failedTestSteps = testCase.steps
146
- .map((step, i) => step.result.status === 'FAILED' || step.result.status === 'UNDEFINED'
147
- ? i
148
- : null)
149
- .filter((i) => i !== null);
150
- const retrainStats = await this.retrain(failedTestSteps, testCase);
156
+ const retrainStats = await this.retrain(failedTestSteps, report);
151
157
  if (!retrainStats) {
152
- return testCase;
158
+ return;
153
159
  }
154
160
  await this.uploader.modifyTestCase({
155
- ...testCase,
161
+ ...report,
156
162
  retrainStats,
157
163
  });
158
- return {
159
- ...testCase,
160
- retrainStats,
161
- };
164
+ await this.rerun(report);
162
165
  }
163
166
  async uploadFinalReport(finalReport) {
164
167
  let success = true;
@@ -193,6 +196,37 @@ class BVTAnalysisFormatter extends _1.default {
193
196
  }
194
197
  return await this.call_cucumber_client(failedTestCases, testCase);
195
198
  }
199
+ async rerun(report) {
200
+ await new Promise((resolve) => {
201
+ const node_path = process.argv.shift();
202
+ const args = [
203
+ path_1.default.join(process.cwd(), 'node_modules', '@dev-blinq', 'cucumber-js', 'bin', 'cucumber.js'),
204
+ '--name',
205
+ `^${report.scenarioName}$`,
206
+ '--exit',
207
+ '--format',
208
+ 'bvt',
209
+ '--run-name',
210
+ `${report.scenarioName}@debug`,
211
+ path_1.default.join(process.cwd(), 'features', `${report.featureName}.feature`),
212
+ ];
213
+ const cucumberClient = (0, child_process_1.spawn)(node_path, args, {
214
+ env: {
215
+ ...process.env,
216
+ RERUN: JSON.stringify(this.failedStepsIndex),
217
+ },
218
+ });
219
+ cucumberClient.stdout.on('data', (data) => {
220
+ console.log(data.toString());
221
+ });
222
+ cucumberClient.stderr.on('data', (data) => {
223
+ console.error(data.toString());
224
+ });
225
+ cucumberClient.on('close', () => {
226
+ resolve();
227
+ });
228
+ });
229
+ }
196
230
  async call_cucumber_client(stepsToRetrain, testCase) {
197
231
  return new Promise((resolve, reject) => {
198
232
  const cucumber_client_path = path_1.default.resolve(process.cwd(), 'node_modules', '@dev-blinq', 'cucumber_client', 'bin', 'client', 'cucumber.js');
@@ -201,7 +235,7 @@ class BVTAnalysisFormatter extends _1.default {
201
235
  path_1.default.join(process.cwd(), testCase.uri),
202
236
  `${testCase.scenarioName}`,
203
237
  'undefined',
204
- `${stepsToRetrain.join(',')}`,
238
+ `${stepsToRetrain},`,
205
239
  ];
206
240
  if (process.env.BLINQ_ENV) {
207
241
  args.push(`--env=${process.env.BLINQ_ENV}`);
@@ -284,6 +318,17 @@ function logReportLink(runId, projectId) {
284
318
  }
285
319
  const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`;
286
320
  console.log(`Report link: ${reportLink}\n`);
321
+ try {
322
+ publishReportLinkToGuacServer(reportLink);
323
+ }
324
+ catch (err) {
325
+ }
287
326
  }
288
327
  exports.logReportLink = logReportLink;
328
+ function publishReportLinkToGuacServer(reportLink) {
329
+ if ((0, fs_1.existsSync)("/tmp/report_publish.sh")) {
330
+ const execAsync = (0, util_1.promisify)(child_process_2.exec);
331
+ execAsync("sh /tmp/report_publish.sh " + reportLink);
332
+ }
333
+ }
289
334
  //# sourceMappingURL=bvt_analysis_formatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bvt_analysis_formatter.js","sourceRoot":"","sources":["../../src/formatter/bvt_analysis_formatter.ts"],"names":[],"mappings":";;;;;;AACA,iDAAqC;AACrC,2BAA4D;AAC5D,0CAAsD;AACtD,gDAAuB;AACvB,6BAA6B;AAC7B,yCAAgD;AAChD,oDAAgD;AAChD,kFAKmC;AACnC,kEAA+C;AAC/C,4CAAmB;AACnB,+BAA6C;AAC7C,4EAAkD;AAClD,mDAAgE;AAChE,gEAA2D;AAC3D,YAAY;AACZ,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA;AAQ/B,MAAqB,oBAAqB,SAAQ,UAAS;IAQzD,YAAY,OAA0B;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QARR,oBAAe,GAAG,IAAI,0BAAe,EAAE,CAAA;QACvC,aAAQ,GAAG,IAAI,kBAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACnD,SAAI,GAAG,KAAK,CAAA;QAOlB,IAAI,CAAC,gBAAgB,GAAG,IAAI,2BAAgB,CAAC,OAAO,CAAC,CAAA;QACrD,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,GAA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O,CAAC,GAAG,CAAC,gBAAgB,UAAU,IAAI,CAAC,CAAA;AAC7C,CAAC;AAXD,sCAWC","sourcesContent":["import { Envelope, Meta } from '@cucumber/messages'\nimport { spawn } from 'child_process'\nimport { readFileSync, existsSync, writeFileSync } from 'fs'\nimport { mkdir, unlink, writeFile } from 'fs/promises'\nimport path from 'path'\nimport { tmpName } from 'tmp'\nimport Formatter, { IFormatterOptions } from '.'\nimport { doesHaveValue } from '../value_checker'\nimport ReportGenerator, {\n JsonReport,\n JsonTestProgress,\n JsonTestResult,\n RetrainStats,\n} from './helpers/report_generator'\nimport ReportUploader from './helpers/uploader'\nimport os from 'os'\nimport { getProjectByAccessKey } from './api'\nimport SummaryFormatter from './summary_formatter'\nimport { ActionEvents, SERVICES_URI } from './helpers/constants'\nimport { axiosClient } from '../configuration/axios_client'\n//User token\nconst TOKEN = process.env.TOKEN\ninterface MetaMessage extends Meta {\n runName: string\n}\n\ninterface EnvelopeWithMetaMessage extends Envelope {\n meta: MetaMessage\n}\nexport default class BVTAnalysisFormatter extends Formatter {\n private reportGenerator = new ReportGenerator()\n private uploader = new ReportUploader(this.reportGenerator)\n private exit = false\n private START: number\n private runName: string\n private summaryFormatter: SummaryFormatter\n\n constructor(options: IFormatterOptions) {\n super(options)\n this.summaryFormatter = new SummaryFormatter(options)\n if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {\n throw new Error('TOKEN must be set')\n }\n this.sendEvent(ActionEvents.cli_run_tests)\n options.eventBroadcaster.on(\n 'envelope',\n async (envelope: EnvelopeWithMetaMessage) => {\n await this.reportGenerator.handleMessage(envelope)\n if (\n doesHaveValue(envelope.meta) &&\n doesHaveValue(envelope.meta.runName)\n ) {\n this.runName = envelope.meta.runName\n }\n if (doesHaveValue(envelope.testRunFinished)) {\n const report = this.reportGenerator.getReport()\n this.START = Date.now()\n if (process.env.BVT_FORMATTER === 'ANALYSIS') {\n await this.analyzeReport(report)\n } else {\n // await this.uploadReport(report)\n }\n this.exit = true\n }\n }\n )\n }\n\n private sendEvent(event: ActionEvents) {\n axiosClient\n .post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event,\n },\n {\n headers: {\n Authorization: `Bearer ${TOKEN}`,\n 'x-source': 'cucumber_js',\n },\n }\n )\n .catch((err) => {\n // Error with events, ignoring\n })\n }\n\n private async uploadReport(report: JsonReport) {\n const uploadSuccessful = await this.uploadFinalReport(report)\n if (uploadSuccessful && report.result.status !== 'FAILED') {\n process.exit(0)\n }\n process.exit(1)\n }\n\n async finished(): Promise<any> {\n await new Promise((resolve) => {\n const checkInterval = setInterval(() => {\n let anyRem\n if (process.env.UPLOADING_TEST_CASE) {\n anyRem = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n } else {\n anyRem = undefined\n }\n\n if (this.exit && (!anyRem || anyRem.length === 0)) {\n // clearInterval(checkInterval)\n // resolve(null)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n } else {\n process.exit(0)\n }\n }\n }, 100) // check every 100ms\n })\n }\n private async analyzeReport(report: JsonReport) {\n if (\n report.result.status === 'PASSED' ||\n process.env.NO_RETRAIN === 'false'\n ) {\n if (report.result.status === 'PASSED') {\n this.log('No test failed. No need to retrain\\n')\n }\n if (process.env.NO_RETRAIN === 'false') {\n this.log(\n 'Retraining is skipped since the failed step contains an API request\\n'\n )\n }\n // const uploadSuccessful = await this.uploadFinalReport(report)\n // process.exit(0)\n this.exit = true\n return\n }\n\n //checking if the type of report.result is JsonResultFailed or not\n this.log('Some tests failed, starting the retraining...\\n')\n if (!('startTime' in report.result) || !('endTime' in report.result)) {\n this.log('Unknown error occured,not retraining\\n')\n return\n }\n await this.processTestCases(report)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n }\n process.exit(0)\n }\n private async processTestCases(report: JsonReport): Promise<JsonReport> {\n const finalTestCases = []\n for (const testCase of report.testCases) {\n const modifiedTestCase = await this.processTestCase(testCase, report)\n\n finalTestCases.push(modifiedTestCase)\n }\n const finalResult = finalTestCases.some(\n (tc) => tc.result.status !== 'PASSED'\n )\n ? report.result\n : ({\n ...report.result,\n status: 'PASSED',\n } as JsonTestResult)\n return {\n result: finalResult,\n testCases: finalTestCases,\n env: report.env,\n }\n }\n private async processTestCase(\n testCase: JsonTestProgress,\n report: JsonReport\n ): Promise<JsonTestProgress> {\n if (testCase.result.status === 'PASSED') {\n return testCase\n }\n const failedTestSteps = testCase.steps\n .map((step, i) =>\n step.result.status === 'FAILED' || step.result.status === 'UNDEFINED'\n ? i\n : null\n )\n .filter((i) => i !== null)\n const retrainStats = await this.retrain(failedTestSteps, testCase)\n\n if (!retrainStats) {\n return testCase\n }\n await this.uploader.modifyTestCase({\n ...testCase,\n retrainStats,\n })\n\n return {\n ...testCase,\n retrainStats,\n }\n }\n\n private async uploadFinalReport(finalReport: JsonReport) {\n let success = true\n try {\n const { projectId, runId } = await this.uploader.uploadRun(\n finalReport,\n this.runName\n )\n logReportLink(runId, projectId)\n } catch (err) {\n this.log('Error uploading report\\n')\n if ('stack' in err) {\n this.log(err.stack)\n }\n success = false\n } finally {\n try {\n writeFileSync(\n path.join(this.reportGenerator.reportFolder, 'report.json'),\n JSON.stringify(finalReport, null, 2),\n 'utf-8'\n )\n } catch (e) {\n console.error('failed to write report.json to local disk')\n }\n }\n\n //this.log(JSON.stringify(finalReport, null, 2))\n return success\n }\n private async retrain(\n failedTestCases: number[],\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n const data = await getProjectByAccessKey(TOKEN)\n const currentTimestampInSeconds = Math.floor(Date.now() / 1000)\n if (data.project.expriration_date < currentTimestampInSeconds) {\n console.log(\n 'Warning: Your project has expired, retraining is restricted. Please contact sales.'\n )\n process.exit(1)\n }\n return await this.call_cucumber_client(failedTestCases, testCase)\n }\n\n private async call_cucumber_client(\n stepsToRetrain: number[],\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n return new Promise((resolve, reject) => {\n const cucumber_client_path = path.resolve(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber_client',\n 'bin',\n 'client',\n 'cucumber.js'\n )\n\n const args: string[] = [\n process.cwd(),\n path.join(process.cwd(), testCase.uri),\n `${testCase.scenarioName}`,\n 'undefined',\n `${stepsToRetrain.join(',')}`,\n ]\n\n if (process.env.BLINQ_ENV) {\n args.push(`--env=${process.env.BLINQ_ENV}`)\n }\n\n if (!existsSync(path.join(this.getAppDataDir(), 'blinq.io', '.temp'))) {\n mkdir(path.join(this.getAppDataDir(), 'blinq.io', '.temp'), {\n recursive: true,\n })\n }\n\n tmpName(async (err, name) => {\n const tempFile = path.join(\n this.getAppDataDir(),\n 'blinq.io',\n '.temp',\n path.basename(name)\n )\n console.log('File path: ', tempFile)\n await writeFile(tempFile, '', 'utf-8')\n\n args.push(`--temp-file=${tempFile}`)\n const cucumberClient = spawn('node', [cucumber_client_path, ...args], {\n env: {\n ...process.env,\n },\n })\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', async (code) => {\n if (code === 0) {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } else {\n this.log('Error retraining\\n')\n try {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } catch (e) {\n this.log('Error reading scenario report\\n ' + e)\n resolve(null)\n }\n }\n })\n })\n })\n }\n\n private getAppDataDir() {\n if (process.env.BLINQ_APPDATA_DIR) {\n return process.env.BLINQ_APPDATA_DIR\n }\n\n let appDataDir: string\n\n switch (process.platform) {\n case 'win32':\n appDataDir = process.env.APPDATA!\n break\n case 'darwin':\n appDataDir = path.join(os.homedir(), 'Library', 'Application Support')\n break\n default:\n appDataDir = path.join(os.homedir(), '.config')\n break\n }\n return appDataDir\n }\n}\n\nexport function logReportLink(runId: string, projectId: string) {\n let reportLinkBaseUrl = 'https://app.blinq.io'\n if (process.env.NODE_ENV_BLINQ === 'local') {\n reportLinkBaseUrl = 'http://localhost:3000'\n } else if (process.env.NODE_ENV_BLINQ === 'dev') {\n reportLinkBaseUrl = 'https://dev.app.blinq.io'\n } else if (process.env.NODE_ENV_BLINQ === 'stage') {\n reportLinkBaseUrl = 'https://stage.app.blinq.io'\n }\n const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`\n console.log(`Report link: ${reportLink}\\n`)\n}\n"]}
1
+ {"version":3,"file":"bvt_analysis_formatter.js","sourceRoot":"","sources":["../../src/formatter/bvt_analysis_formatter.ts"],"names":[],"mappings":";;;;;;AACA,iDAAqC;AACrC,2BAA4D;AAC5D,0CAAsD;AACtD,gDAAuB;AACvB,6BAA6B;AAC7B,yCAAgD;AAChD,oDAAgD;AAChD,kFAKmC;AACnC,kEAA+C;AAC/C,4CAAmB;AACnB,+BAA6C;AAC7C,4EAAkD;AAClD,mDAAgE;AAChE,gEAA2D;AAK3D,+BAAiC;AACjC,iDAAqC;AAErC,YAAY;AACZ,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA;AAQ/B,MAAqB,oBAAqB,SAAQ,UAAS;IAiBzD,YAAY,OAA0B;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QAbR,oBAAe,GAAG,IAAI,0BAAe,EAAE,CAAA;QACvC,aAAQ,GAAG,IAAI,kBAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACnD,SAAI,GAAG,KAAK,CAAA;QAKZ,mBAAc,GAGhB,EAAE,CAAA;QAIN,IAAI,CAAC,gBAAgB,GAAG,IAAI,2BAAgB,CAAC,OAAO,CAAC,CAAA;QACrD,oBAAoB,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAA;QAC3D,IAAI,CAAC,cAAc,GAAG,EAAE,CAAA;QACxB,IAAI,CAAC,gBAAgB,GAA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AG,iBAAiB,IAAI,SAAS,eAAe,KAAK,EAAE,CAAA;IAC1E,OAAO,CAAC,GAAG,CAAC,gBAAgB,UAAU,IAAI,CAAC,CAAA;IAC3C,IAAI;QACF,6BAA6B,CAAC,UAAU,CAAC,CAAC;KAC3C;IAAC,OAAO,GAAG,EAAE;KACb;AACH,CAAC;AAfD,sCAeC;AAED,SAAS,6BAA6B,CAAC,UAAkB;IACvD,IAAI,IAAA,eAAU,EAAC,wBAAwB,CAAC,EAAE;QACxC,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;QAClC,SAAS,CAAC,4BAA4B,GAAG,UAAU,CAAC,CAAC;KACtD;AACH,CAAC","sourcesContent":["import { Envelope, Meta } from '@cucumber/messages'\nimport { spawn } from 'child_process'\nimport { readFileSync, existsSync, writeFileSync } from 'fs'\nimport { mkdir, unlink, writeFile } from 'fs/promises'\nimport path from 'path'\nimport { tmpName } from 'tmp'\nimport Formatter, { IFormatterOptions } from '.'\nimport { doesHaveValue } from '../value_checker'\nimport ReportGenerator, {\n JsonReport,\n JsonTestProgress,\n JsonTestResult,\n RetrainStats,\n} from './helpers/report_generator'\nimport ReportUploader from './helpers/uploader'\nimport os from 'os'\nimport { getProjectByAccessKey } from './api'\nimport SummaryFormatter from './summary_formatter'\nimport { ActionEvents, SERVICES_URI } from './helpers/constants'\nimport { axiosClient } from '../configuration/axios_client'\nimport {\n FinishTestCaseResponse,\n RootCauseProps,\n} from './helpers/upload_serivce'\nimport { promisify } from 'util';\nimport { exec } from 'child_process';\n\n//User token\nconst TOKEN = process.env.TOKEN\ninterface MetaMessage extends Meta {\n runName: string\n}\n\ninterface EnvelopeWithMetaMessage extends Envelope {\n meta: MetaMessage\n}\nexport default class BVTAnalysisFormatter extends Formatter {\n static reportGenerator: ReportGenerator\n static reRunFailedStepsIndex:\n | { testCaseId: string; failedStepIndex: number }[]\n | null\n private reportGenerator = new ReportGenerator()\n private uploader = new ReportUploader(this.reportGenerator)\n private exit = false\n private START: number\n private runName: string\n private failedStepsIndex: { testCaseId: string; failedStepIndex: number }[]\n private summaryFormatter: SummaryFormatter\n private rootCauseArray: {\n rootCause: RootCauseProps\n report: JsonTestProgress\n }[] = []\n\n constructor(options: IFormatterOptions) {\n super(options)\n this.summaryFormatter = new SummaryFormatter(options)\n BVTAnalysisFormatter.reportGenerator = this.reportGenerator\n this.rootCauseArray = []\n this.failedStepsIndex = []\n BVTAnalysisFormatter.reRunFailedStepsIndex = process.env.RERUN\n ? JSON.parse(process.env.RERUN)\n : null\n\n if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {\n throw new Error('TOKEN must be set')\n }\n this.sendEvent(ActionEvents.cli_run_tests)\n options.eventBroadcaster.on(\n 'envelope',\n async (envelope: EnvelopeWithMetaMessage, data?: any) => {\n if (doesHaveValue(envelope.testCaseFinished) && data) {\n const { rootCause, report } = data as FinishTestCaseResponse\n\n if (!rootCause.status) {\n console.error(\n `Root cause: ${rootCause.failClass}\\n, ${rootCause.analysis}\\nfailing step: ${rootCause.failedStep}`\n )\n this.rootCauseArray.push({ rootCause, report })\n this.failedStepsIndex.push({\n testCaseId: report.id,\n failedStepIndex: rootCause.failedStep,\n })\n }\n return\n }\n await this.reportGenerator.handleMessage(envelope)\n\n if (\n doesHaveValue(envelope.meta) &&\n doesHaveValue(envelope.meta.runName)\n ) {\n this.runName = envelope.meta.runName\n }\n if (doesHaveValue(envelope.testRunFinished)) {\n this.START = Date.now()\n if (process.env.BVT_FORMATTER === 'ANALYSIS') {\n await this.analyzeReport()\n } else {\n // await this.uploadReport(report)\n }\n this.exit = true\n }\n }\n )\n }\n\n private sendEvent(event: ActionEvents) {\n axiosClient\n .post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event,\n },\n {\n headers: {\n Authorization: `Bearer ${TOKEN}`,\n 'x-source': 'cucumber_js',\n },\n }\n )\n .catch((err) => {\n // Error with events, ignoring\n })\n }\n\n private async uploadReport(report: JsonReport) {\n const uploadSuccessful = await this.uploadFinalReport(report)\n if (uploadSuccessful && report.result.status !== 'FAILED') {\n process.exit(0)\n }\n process.exit(1)\n }\n\n async finished(): Promise<any> {\n await new Promise((resolve) => {\n const checkInterval = setInterval(() => {\n let anyRem\n if (process.env.UPLOADING_TEST_CASE) {\n anyRem = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n } else {\n anyRem = undefined\n }\n\n if (this.exit && (!anyRem || anyRem.length === 0)) {\n // clearInterval(checkInterval)\n // resolve(null)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n } else {\n process.exit(0)\n }\n }\n }, 100) // check every 100ms\n })\n }\n private async analyzeReport() {\n if (\n this.rootCauseArray.length === 0 ||\n process.env.NO_RETRAIN === 'false'\n ) {\n if (this.rootCauseArray.length === 0) {\n this.log('No test failed. No need to retrain\\n')\n }\n if (process.env.NO_RETRAIN === 'false') {\n this.log(\n 'Retraining is skipped since the failed step contains an API request\\n'\n )\n }\n // const uploadSuccessful = await this.uploadFinalReport(report)\n // process.exit(0)\n this.exit = true\n return\n }\n\n //checking if the type of report.result is JsonResultFailed or not\n\n this.log('Some tests failed, starting the retraining...\\n')\n await this.processTestCases()\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n }\n process.exit(0)\n }\n private async processTestCases() {\n for (const { rootCause, report } of this.rootCauseArray) {\n await this.processTestCase(rootCause, report)\n }\n }\n private async processTestCase(\n rootCause: RootCauseProps,\n report: JsonTestProgress\n ) {\n const failedTestSteps = rootCause.failedStep\n\n if (\n BVTAnalysisFormatter.reRunFailedStepsIndex &&\n BVTAnalysisFormatter.reRunFailedStepsIndex.length > 0\n ) {\n const previousRun = BVTAnalysisFormatter.reRunFailedStepsIndex[0]\n if (previousRun.failedStepIndex === failedTestSteps) {\n console.log('Same step has failed again, skipping retraining')\n BVTAnalysisFormatter.reRunFailedStepsIndex.shift()\n return\n }\n BVTAnalysisFormatter.reRunFailedStepsIndex.shift()\n }\n\n const retrainStats = await this.retrain(failedTestSteps, report)\n\n if (!retrainStats) {\n return\n }\n\n await this.uploader.modifyTestCase({\n ...report,\n retrainStats,\n })\n\n await this.rerun(report)\n }\n\n private async uploadFinalReport(finalReport: JsonReport) {\n let success = true\n try {\n const { projectId, runId } = await this.uploader.uploadRun(\n finalReport,\n this.runName\n )\n logReportLink(runId, projectId)\n } catch (err) {\n this.log('Error uploading report\\n')\n if ('stack' in err) {\n this.log(err.stack)\n }\n success = false\n } finally {\n try {\n writeFileSync(\n path.join(this.reportGenerator.reportFolder, 'report.json'),\n JSON.stringify(finalReport, null, 2),\n 'utf-8'\n )\n } catch (e) {\n console.error('failed to write report.json to local disk')\n }\n }\n\n //this.log(JSON.stringify(finalReport, null, 2))\n return success\n }\n private async retrain(\n failedTestCases: number,\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n const data = await getProjectByAccessKey(TOKEN)\n const currentTimestampInSeconds = Math.floor(Date.now() / 1000)\n if (data.project.expriration_date < currentTimestampInSeconds) {\n console.log(\n 'Warning: Your project has expired, retraining is restricted. Please contact sales.'\n )\n process.exit(1)\n }\n return await this.call_cucumber_client(failedTestCases, testCase)\n }\n\n private async rerun(report: JsonTestProgress) {\n await new Promise<void>((resolve) => {\n const node_path = process.argv.shift()\n const args = [\n path.join(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber-js',\n 'bin',\n 'cucumber.js'\n ),\n '--name',\n `^${report.scenarioName}$`,\n '--exit',\n '--format',\n 'bvt',\n '--run-name',\n `${report.scenarioName}@debug`,\n path.join(process.cwd(), 'features', `${report.featureName}.feature`),\n ]\n const cucumberClient = spawn(node_path, args, {\n env: {\n ...process.env,\n RERUN: JSON.stringify(this.failedStepsIndex),\n },\n })\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', () => {\n resolve()\n })\n })\n }\n\n private async call_cucumber_client(\n stepsToRetrain: number,\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n return new Promise((resolve, reject) => {\n const cucumber_client_path = path.resolve(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber_client',\n 'bin',\n 'client',\n 'cucumber.js'\n )\n\n const args: string[] = [\n process.cwd(),\n path.join(process.cwd(), testCase.uri),\n `${testCase.scenarioName}`,\n 'undefined',\n `${stepsToRetrain},`,\n ]\n\n if (process.env.BLINQ_ENV) {\n args.push(`--env=${process.env.BLINQ_ENV}`)\n }\n\n if (!existsSync(path.join(this.getAppDataDir(), 'blinq.io', '.temp'))) {\n mkdir(path.join(this.getAppDataDir(), 'blinq.io', '.temp'), {\n recursive: true,\n })\n }\n\n tmpName(async (err, name) => {\n const tempFile = path.join(\n this.getAppDataDir(),\n 'blinq.io',\n '.temp',\n path.basename(name)\n )\n console.log('File path: ', tempFile)\n await writeFile(tempFile, '', 'utf-8')\n\n args.push(`--temp-file=${tempFile}`)\n const cucumberClient = spawn('node', [cucumber_client_path, ...args], {\n env: {\n ...process.env,\n },\n })\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', async (code) => {\n if (code === 0) {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } else {\n this.log('Error retraining\\n')\n try {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } catch (e) {\n this.log('Error reading scenario report\\n ' + e)\n resolve(null)\n }\n }\n })\n })\n })\n }\n\n private getAppDataDir() {\n if (process.env.BLINQ_APPDATA_DIR) {\n return process.env.BLINQ_APPDATA_DIR\n }\n\n let appDataDir: string\n\n switch (process.platform) {\n case 'win32':\n appDataDir = process.env.APPDATA!\n break\n case 'darwin':\n appDataDir = path.join(os.homedir(), 'Library', 'Application Support')\n break\n default:\n appDataDir = path.join(os.homedir(), '.config')\n break\n }\n return appDataDir\n }\n}\n\nexport function logReportLink(runId: string, projectId: string) {\n let reportLinkBaseUrl = 'https://app.blinq.io'\n if (process.env.NODE_ENV_BLINQ === 'local') {\n reportLinkBaseUrl = 'http://localhost:3000'\n } else if (process.env.NODE_ENV_BLINQ === 'dev') {\n reportLinkBaseUrl = 'https://dev.app.blinq.io'\n } else if (process.env.NODE_ENV_BLINQ === 'stage') {\n reportLinkBaseUrl = 'https://stage.app.blinq.io'\n }\n const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`\n console.log(`Report link: ${reportLink}\\n`)\n try {\n publishReportLinkToGuacServer(reportLink);\n } catch (err) {\n }\n}\n\nfunction publishReportLinkToGuacServer(reportLink: string) {\n if (existsSync(\"/tmp/report_publish.sh\")) {\n const execAsync = promisify(exec);\n execAsync(\"sh /tmp/report_publish.sh \" + reportLink);\n }\n}\n"]}
@@ -65,6 +65,7 @@ export type JsonStep = {
65
65
  webLog: webLog[];
66
66
  networkData: any[];
67
67
  data?: any;
68
+ ariaSnapshot: string;
68
69
  };
69
70
  export type RetrainStats = {
70
71
  result: JsonTestResult;
@@ -81,6 +82,7 @@ export type JsonTestProgress = {
81
82
  steps: JsonStep[];
82
83
  result: JsonTestResult;
83
84
  retrainStats?: RetrainStats;
85
+ initialAriaSnapshot?: string;
84
86
  webLog: any;
85
87
  networkLog: any;
86
88
  env: {
@@ -117,9 +119,11 @@ export default class ReportGenerator {
117
119
  private stepLogs;
118
120
  private stepNetworkLogs;
119
121
  private runName;
122
+ private ariaSnapshot;
123
+ private initialAriaSnapshot;
120
124
  reportFolder: null | string;
121
125
  private uploadService;
122
- handleMessage(envelope: EnvelopeWithMetaMessage): Promise<void>;
126
+ handleMessage(envelope: EnvelopeWithMetaMessage | messages.Envelope, reRunId?: string): Promise<any>;
123
127
  getReport(): JsonReport;
124
128
  private handleParseError;
125
129
  private onGherkinDocument;
@@ -67,11 +67,13 @@ class ReportGenerator {
67
67
  this.stepLogs = [];
68
68
  this.stepNetworkLogs = [];
69
69
  this.runName = '';
70
+ this.ariaSnapshot = '';
71
+ this.initialAriaSnapshot = '';
70
72
  this.reportFolder = null;
71
73
  this.uploadService = new upload_serivce_1.RunUploadService(REPORT_SERVICE_URL, REPORT_SERVICE_TOKEN);
72
74
  }
73
- async handleMessage(envelope) {
74
- if (envelope.meta && envelope.meta.runName) {
75
+ async handleMessage(envelope, reRunId) {
76
+ if (envelope.meta && 'runName' in envelope.meta) {
75
77
  this.runName = envelope.meta.runName;
76
78
  }
77
79
  const type = Object.keys(envelope)[0];
@@ -127,8 +129,7 @@ class ReportGenerator {
127
129
  }
128
130
  case 'testCaseFinished': {
129
131
  const testCaseFinished = envelope[type];
130
- await this.onTestCaseFinished(testCaseFinished);
131
- break;
132
+ return await this.onTestCaseFinished(testCaseFinished, reRunId);
132
133
  }
133
134
  // case "hook": { break} // After Hook
134
135
  case 'testRunFinished': {
@@ -266,6 +267,8 @@ class ReportGenerator {
266
267
  },
267
268
  networkData: [],
268
269
  webLog: [],
270
+ data: {},
271
+ ariaSnapshot: this.ariaSnapshot,
269
272
  });
270
273
  return this.stepReportMap.get(pickleStep.id);
271
274
  });
@@ -308,6 +311,14 @@ class ReportGenerator {
308
311
  this.reportFolder = body.replaceAll('\\', '/');
309
312
  return;
310
313
  }
314
+ if (mediaType === 'application/json+snapshot-before') {
315
+ this.initialAriaSnapshot = body;
316
+ return;
317
+ }
318
+ if (mediaType === 'application/json+snapshot-after') {
319
+ this.ariaSnapshot = body;
320
+ return;
321
+ }
311
322
  if (mediaType === 'application/json+env') {
312
323
  const data = JSON.parse(body);
313
324
  this.report.env = data;
@@ -338,7 +349,7 @@ class ReportGenerator {
338
349
  stepProgess.commands.push(command);
339
350
  }
340
351
  }
341
- getFailedTestStepResult({ commands, startTime, endTime, result }) {
352
+ getFailedTestStepResult({ commands, startTime, endTime, result, }) {
342
353
  for (const command of commands) {
343
354
  if (command.result.status === 'FAILED') {
344
355
  return {
@@ -404,7 +415,7 @@ class ReportGenerator {
404
415
  commands: stepProgess.commands,
405
416
  startTime: prevStepResult.startTime,
406
417
  endTime: this.getTimeStamp(timestamp),
407
- result: testStepResult
418
+ result: testStepResult,
408
419
  });
409
420
  }
410
421
  else {
@@ -416,6 +427,8 @@ class ReportGenerator {
416
427
  }
417
428
  stepProgess.webLog = this.stepLogs;
418
429
  stepProgess.networkData = this.stepNetworkLogs;
430
+ stepProgess.ariaSnapshot = this.ariaSnapshot;
431
+ this.ariaSnapshot = '';
419
432
  this.stepNetworkLogs = [];
420
433
  this.stepLogs = [];
421
434
  if (Object.keys(data).length > 0) {
@@ -468,7 +481,7 @@ class ReportGenerator {
468
481
  status: 'PASSED',
469
482
  };
470
483
  }
471
- async onTestCaseFinished(testCaseFinished) {
484
+ async onTestCaseFinished(testCaseFinished, reRunId) {
472
485
  const { testCaseStartedId, timestamp } = testCaseFinished;
473
486
  const testProgress = this.testCaseReportMap.get(testCaseStartedId);
474
487
  const prevResult = testProgress.result;
@@ -481,11 +494,13 @@ class ReportGenerator {
481
494
  };
482
495
  testProgress.webLog = this.logs;
483
496
  testProgress.networkLog = this.networkLog;
497
+ testProgress.initialAriaSnapshot = this.initialAriaSnapshot;
498
+ this.initialAriaSnapshot = '';
484
499
  this.networkLog = [];
485
500
  this.logs = [];
486
- await this.uploadTestCase(testProgress);
501
+ return await this.uploadTestCase(testProgress, reRunId);
487
502
  }
488
- async uploadTestCase(testCase) {
503
+ async uploadTestCase(testCase, rerunId) {
489
504
  let runId = '';
490
505
  let projectId = '';
491
506
  if (!process.env.UPLOADING_TEST_CASE) {
@@ -494,6 +509,7 @@ class ReportGenerator {
494
509
  const anyRemArr = JSON.parse(process.env.UPLOADING_TEST_CASE);
495
510
  const randomID = Math.random().toString(36).substring(7);
496
511
  anyRemArr.push(randomID);
512
+ let data;
497
513
  process.env.UPLOADING_TEST_CASE = JSON.stringify(anyRemArr);
498
514
  try {
499
515
  if (process.env.RUN_ID &&
@@ -511,7 +527,7 @@ class ReportGenerator {
511
527
  process.env.PROJECT_ID = projectId;
512
528
  }
513
529
  }
514
- await this.uploadService.uploadTestCase(testCase, runId, projectId, this.reportFolder);
530
+ data = await this.uploadService.uploadTestCase(testCase, runId, projectId, this.reportFolder, rerunId);
515
531
  this.writeTestCaseReportToDisk(testCase);
516
532
  }
517
533
  catch (e) {
@@ -522,6 +538,7 @@ class ReportGenerator {
522
538
  arrRem.splice(arrRem.indexOf(randomID), 1);
523
539
  process.env.UPLOADING_TEST_CASE = JSON.stringify(arrRem);
524
540
  }
541
+ return data ? data : null;
525
542
  }
526
543
  writeTestCaseReportToDisk(testCase) {
527
544
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"report_generator.js","sourceRoot":"","sources":["../../../src/formatter/helpers/report_generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA8C;AAC9C,4CAAmB;AACnB,gDAAuB;AACvB,qDAAmD;AAKnD,MAAM,GAAG,GACP,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,KAAK;IAClC,CAAC,CAAC,mCAAmC;IACrC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO;QACtC,CAAC,CAAC,gCAAgC;QAClC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO;YACtC,CAAC,CAAC,qCAAqC;YACvC,CAAC,CAAC,+BAA+B,CAAA;AAEzC,MAAM,kBAAkB,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,kBAAkB,mCAAI,GAAG,CAAA;AAChE,MAAM,UAAU,GAAG,EAAE,CAAA;AACrB,MAAM,WAAW,GAAG,CAAC,CAAA;AACrB,MAAM,oBAAoB,GACxB,MAAA,OAAO,CAAC,GAAG,CAAC,KAAK,mCAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA;AAyHvD,MAAqB,eAAe;IAAp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,EAAE,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC;YACrC,OAAO;YACP,aAAa;SACd,CAAA;IACH,CAAC;CACF;AAtiBD,kCAsiBC","sourcesContent":["import * as messages from '@cucumber/messages'\nimport fs from 'fs'\nimport path from 'path'\nimport { RunUploadService } from './upload_serivce'\n// type JsonException = messages.Exception\ntype JsonTimestamp = number //messages.Timestamp\ntype JsonStepType = 'Unknown' | 'Context' | 'Action' | 'Outcome' | 'Conjunction'\n\nconst URL =\n process.env.NODE_ENV_BLINQ === 'dev'\n ? 'https://dev.api.blinq.io/api/runs'\n : process.env.NODE_ENV_BLINQ === 'local'\n ? 'http://localhost:5001/api/runs'\n : process.env.NODE_ENV_BLINQ === 'stage'\n ? 'https://stage.api.blinq.io/api/runs'\n : 'https://api.blinq.io/api/runs'\n\nconst REPORT_SERVICE_URL = process.env.REPORT_SERVICE_URL ?? URL\nconst BATCH_SIZE = 10\nconst MAX_RETRIES = 3\nconst REPORT_SERVICE_TOKEN =\n process.env.TOKEN ?? process.env.REPORT_SERVICE_TOKEN\nexport type JsonResultUnknown = {\n status: 'UNKNOWN'\n}\ntype JsonResultSkipped = {\n status: 'SKIPPED'\n}\ntype JsonResultUndefined = {\n status: 'UNDEFINED'\n}\ntype JsonResultAmbiguous = {\n status: 'AMBIGUOUS'\n}\nexport type JsonResultStarted = {\n status: 'STARTED'\n startTime: JsonTimestamp\n}\ntype JsonResultPending = {\n status: 'PENDING'\n startTime: JsonTimestamp\n endTime: JsonTimestamp\n}\nexport type JsonResultPassed = {\n status: 'PASSED'\n startTime: JsonTimestamp\n endTime: JsonTimestamp\n}\nexport type JsonResultFailed = {\n status: 'FAILED'\n startTime: JsonTimestamp\n endTime: JsonTimestamp\n message?: string\n // exception?: JsonException\n}\nexport type JsonFixedByAi = {\n status: 'FIXED_BY_AI'\n startTime: JsonTimestamp\n endTime: JsonTimestamp\n}\n\ntype JsonCommandResult = JsonResultPassed | JsonResultFailed\ntype JsonStepResult =\n | JsonResultUnknown\n | JsonResultSkipped\n | JsonResultUndefined\n | JsonResultAmbiguous\n | JsonResultStarted\n | JsonResultPending\n | JsonResultPassed\n | JsonResultFailed\n | JsonFixedByAi\nexport type JsonTestResult =\n | JsonResultUnknown\n | JsonResultStarted\n | JsonResultPassed\n | JsonResultFailed\n | JsonFixedByAi\ntype JsonReportResult = JsonTestResult\n\ntype JsonCommand = {\n type: string\n value?: string\n text: string\n screenshotId?: string\n result: JsonCommandResult\n netWorkLog?: any[]\n}\ntype webLog = {\n type: string\n text: string\n location: string\n time: string\n}\nexport type JsonStep = {\n keyword: string\n type: JsonStepType\n text: string\n commands: JsonCommand[]\n result: JsonStepResult\n webLog: webLog[]\n networkData: any[]\n data?: any\n}\nexport type RetrainStats = {\n result: JsonTestResult\n totalSteps: number\n upload_id: string\n local_id: number\n}\nexport type JsonTestProgress = {\n id: string\n featureName: string\n uri: string\n scenarioName: string\n parameters: Record<string, string>\n steps: JsonStep[]\n result: JsonTestResult\n retrainStats?: RetrainStats\n webLog: any\n networkLog: any\n env: {\n name: string\n baseUrl: string\n }\n}\n\nexport type JsonReport = {\n testCases: JsonTestProgress[]\n result: JsonReportResult\n env: {\n name: string\n baseUrl: string\n }\n}\n\ninterface MetaMessage extends messages.Meta {\n runName: string\n}\ninterface EnvelopeWithMetaMessage extends messages.Envelope {\n meta: MetaMessage\n}\nexport default class ReportGenerator {\n private report: JsonReport = {\n result: {\n status: 'UNKNOWN',\n },\n testCases: [] as JsonTestProgress[],\n env: {\n name: '',\n baseUrl: '',\n },\n }\n private gherkinDocumentMap = new Map<string, messages.GherkinDocument>()\n private stepMap = new Map<string, messages.Step>()\n private pickleMap = new Map<string, messages.Pickle>()\n private testCaseMap = new Map<string, messages.TestCase>()\n private testStepMap = new Map<string, messages.TestStep>()\n private stepReportMap = new Map<string, JsonStep>()\n private testCaseReportMap = new Map<string, JsonTestProgress>()\n private scenarioIterationCountMap = new Map<string, number>()\n private logs: webLog[] = []\n private networkLog: any[] = []\n private stepLogs: webLog[] = []\n private stepNetworkLogs: any[] = []\n private runName = ''\n reportFolder: null | string = null\n private uploadService = new RunUploadService(\n REPORT_SERVICE_URL,\n REPORT_SERVICE_TOKEN\n )\n\n async handleMessage(envelope: EnvelopeWithMetaMessage) {\n if (envelope.meta && envelope.meta.runName) {\n this.runName = envelope.meta.runName\n }\n const type = Object.keys(envelope)[0] as keyof messages.Envelope\n switch (type) {\n // case \"meta\": { break}\n // case \"source\": { break}\n case 'parseError': {\n const parseError = envelope[type]\n this.handleParseError(parseError)\n break\n }\n case 'gherkinDocument': {\n const doc = envelope[type]\n this.onGherkinDocument(doc)\n break\n }\n case 'pickle': {\n const pickle = envelope[type]\n this.onPickle(pickle)\n break\n }\n // case \"stepDefinition\": { break}\n // case \"hook\": { break} // Before Hook\n case 'testRunStarted': {\n const testRunStarted = envelope[type]\n this.onTestRunStarted(testRunStarted)\n break\n }\n case 'testCase': {\n const testCase = envelope[type]\n this.onTestCase(testCase)\n break\n }\n case 'testCaseStarted': {\n const testCaseStarted = envelope[type]\n this.onTestCaseStarted(testCaseStarted)\n break\n }\n case 'testStepStarted': {\n const testStepStarted = envelope[type]\n this.onTestStepStarted(testStepStarted)\n break\n }\n case 'attachment': {\n const attachment = envelope[type]\n this.onAttachment(attachment)\n break\n }\n case 'testStepFinished': {\n const testStepFinished = envelope[type]\n this.onTestStepFinished(testStepFinished)\n break\n }\n case 'testCaseFinished': {\n const testCaseFinished = envelope[type]\n await this.onTestCaseFinished(testCaseFinished)\n break\n }\n // case \"hook\": { break} // After Hook\n case 'testRunFinished': {\n const testRunFinished = envelope[type]\n this.onTestRunFinished(testRunFinished)\n break\n }\n\n // case \"parameterType\" : { break}\n // case \"undefinedParameterType\": { break}\n }\n }\n getReport() {\n return this.report\n }\n private handleParseError(parseError: messages.ParseError) {\n const { message } = parseError\n const timestamp = new Date().getTime()\n this.report.result = {\n status: 'FAILED',\n startTime: timestamp,\n endTime: timestamp,\n message: message,\n }\n }\n\n private onGherkinDocument(doc: messages.GherkinDocument) {\n this.gherkinDocumentMap.set(doc.uri, doc)\n doc.feature.children.forEach((child) => {\n if (child.scenario) {\n child.scenario.steps.forEach((step) => {\n this.stepMap.set(step.id, step)\n })\n } else if (child.background) {\n child.background.steps.forEach((step) => {\n this.stepMap.set(step.id, step)\n })\n } else if (child.rule) {\n child.rule.children.forEach((child) => {\n if (child.scenario) {\n child.scenario.steps.forEach((step) => {\n this.stepMap.set(step.id, step)\n })\n } else if (child.background) {\n child.background.steps.forEach((step) => {\n this.stepMap.set(step.id, step)\n })\n }\n })\n }\n })\n }\n private onPickle(pickle: messages.Pickle) {\n this.pickleMap.set(pickle.id, pickle)\n }\n private getTimeStamp(timestamp: messages.Timestamp) {\n return timestamp.seconds * 1000 + timestamp.nanos / 1000000\n }\n private onTestRunStarted(testRunStarted: messages.TestRunStarted) {\n this.report.result = {\n status: 'STARTED',\n startTime: this.getTimeStamp(testRunStarted.timestamp),\n }\n }\n private onTestCase(testCase: messages.TestCase) {\n this.testCaseMap.set(testCase.id, testCase)\n testCase.testSteps.forEach((testStep) => {\n this.testStepMap.set(testStep.id, testStep)\n })\n }\n private _findScenario(doc: messages.GherkinDocument, scenarioId: string) {\n for (const child of doc.feature.children) {\n if (child.scenario && child.scenario.id === scenarioId) {\n return child.scenario\n }\n if (child.rule) {\n for (const scenario of child.rule.children) {\n if (scenario.scenario && scenario.scenario.id === scenarioId) {\n return scenario.scenario\n }\n }\n }\n }\n throw new Error(`scenario \"${scenarioId}\" not found`)\n }\n private _getParameters(scenario: messages.Scenario, exampleId: string) {\n const parameters: Record<string, string> = {}\n if (scenario.examples.length === 0) return parameters\n for (const examples of scenario.examples) {\n for (const tableRow of examples.tableBody) {\n if (tableRow.id === exampleId) {\n for (let i = 0; i < examples.tableHeader.cells.length; i++) {\n parameters[examples.tableHeader.cells[i].value] =\n tableRow.cells[i].value\n }\n }\n }\n }\n return parameters\n }\n private onTestCaseStarted(testCaseStarted: messages.TestCaseStarted) {\n const { testCaseId, id, timestamp } = testCaseStarted\n const testCase = this.testCaseMap.get(testCaseId)\n if (testCase === undefined)\n throw new Error(`testCase with id ${testCaseId} not found`)\n const pickle = this.pickleMap.get(testCase.pickleId)\n if (pickle === undefined)\n throw new Error(`pickle with id ${testCase.pickleId} not found`)\n\n const doc = this.gherkinDocumentMap.get(pickle.uri)\n if (doc === undefined)\n throw new Error(`gherkinDocument with uri ${pickle.uri} not found`)\n const featureName = doc.feature.name\n\n const scenarioId = pickle.astNodeIds[0]\n const scenario = this._findScenario(doc, scenarioId)\n const scenarioName = scenario.name\n if (!this.scenarioIterationCountMap.has(scenarioId)) {\n this.scenarioIterationCountMap.set(scenarioId, 1)\n }\n const parameters = this._getParameters(scenario, pickle.astNodeIds[1])\n console.log(\n `Running scenario ${scenarioName} iteration ${this.scenarioIterationCountMap.get(\n scenarioId\n )} with parameters:\\n${JSON.stringify(parameters, null, 4)}\\n \n `\n )\n this.scenarioIterationCountMap.set(\n scenarioId,\n this.scenarioIterationCountMap.get(scenarioId) + 1\n )\n const steps: JsonStep[] = pickle.steps.map((pickleStep) => {\n const stepId = pickleStep.astNodeIds[0]\n const step = this.stepMap.get(stepId)\n this.stepReportMap.set(pickleStep.id, {\n type: step.keywordType,\n keyword: step.keyword,\n text: step.text,\n commands: [],\n result: {\n status: 'UNKNOWN',\n },\n networkData: [],\n webLog: [],\n })\n return this.stepReportMap.get(pickleStep.id)\n })\n this.testCaseReportMap.set(id, {\n id,\n uri: pickle.uri,\n featureName,\n scenarioName,\n parameters,\n steps,\n result: {\n status: 'STARTED',\n startTime: this.getTimeStamp(timestamp),\n },\n webLog: [],\n networkLog: [],\n env: {\n name: this.report.env.name,\n baseUrl: this.report.env.baseUrl,\n },\n })\n this.report.testCases.push(this.testCaseReportMap.get(id))\n }\n private onTestStepStarted(testStepStarted: messages.TestStepStarted) {\n const { testStepId, timestamp } = testStepStarted\n const testStep = this.testStepMap.get(testStepId)\n if (testStep === undefined)\n throw new Error(`testStep with id ${testStepId} not found`)\n if (testStep.pickleStepId === undefined) return\n const stepProgess = this.stepReportMap.get(testStep.pickleStepId)\n stepProgess.result = {\n status: 'STARTED',\n startTime: this.getTimeStamp(timestamp),\n }\n }\n private onAttachment(attachment: messages.Attachment) {\n const { testStepId, body, mediaType } = attachment\n if (mediaType === 'text/plain') {\n this.reportFolder = body.replaceAll('\\\\', '/')\n return\n }\n if (mediaType === 'application/json+env') {\n const data = JSON.parse(body)\n this.report.env = data\n this.report.testCases.map((testCase) => {\n testCase.env = data\n return testCase\n })\n }\n if (mediaType === 'application/json+log') {\n const log: webLog = JSON.parse(body)\n if (this.logs.length < 1000) {\n this.logs.push(log)\n this.stepLogs.push(log)\n }\n }\n if (mediaType === 'application/json+network') {\n const networkLog = JSON.parse(body)\n if (this.networkLog.length < 1000) this.networkLog.push(networkLog)\n this.stepNetworkLogs.push(networkLog)\n }\n const testStep = this.testStepMap.get(testStepId)\n if (testStep.pickleStepId === undefined) return\n\n const stepProgess = this.stepReportMap.get(testStep.pickleStepId)\n if (mediaType === 'application/json') {\n const command: JsonCommand = JSON.parse(body)\n stepProgess.commands.push(command)\n }\n }\n private getFailedTestStepResult({\n commands,\n startTime,\n endTime,\n result\n }: { commands: JsonCommand[], startTime: number, endTime: number, result: messages.TestStepResult }): JsonStepResult {\n for (const command of commands) {\n if (command.result.status === 'FAILED') {\n return {\n status: 'FAILED',\n message: command.result.message,\n startTime,\n endTime,\n } as const\n }\n }\n return {\n status: 'FAILED',\n startTime,\n endTime,\n message: result.message,\n }\n }\n private onTestStepFinished(testStepFinished: messages.TestStepFinished) {\n const { testStepId, testStepResult, timestamp } = testStepFinished\n const testStep = this.testStepMap.get(testStepId)\n if (testStep.pickleStepId === undefined) {\n if (testStepResult.status === 'FAILED') {\n console.error(\n `Before/After hook failed with message: ${testStepResult.message}`\n )\n }\n return\n }\n if (testStepResult.status === 'UNDEFINED') {\n const step = this.stepReportMap.get(testStep.pickleStepId)\n const stepName = step ? step.keyword + ' ' + step.text : 'Undefined step'\n const undefinedCommand: messages.Attachment = {\n testStepId: testStepId,\n body: JSON.stringify({\n type: 'error',\n text: 'Undefined step: ' + stepName,\n result: {\n status: 'FAILED',\n startTime: this.getTimeStamp(timestamp),\n endTime: this.getTimeStamp(timestamp),\n },\n }),\n mediaType: 'application/json',\n contentEncoding: messages.AttachmentContentEncoding.IDENTITY,\n }\n this.onAttachment(undefinedCommand)\n }\n const stepProgess = this.stepReportMap.get(testStep.pickleStepId)\n const prevStepResult = stepProgess.result as {\n status: 'STARTED'\n startTime: JsonTimestamp\n }\n let data = {}\n try {\n const reportFolder = this.reportFolder\n if (reportFolder === null) {\n throw new Error(\n '\"reportFolder\" is \"null\". Failed to run BVT hooks. Please retry after running \"Generate All\" or \"Record Scenario\" '\n )\n }\n if (fs.existsSync(path.join(reportFolder, 'data.json'))) {\n data = JSON.parse(\n fs.readFileSync(path.join(reportFolder, 'data.json'), 'utf8')\n )\n }\n } catch (error) {\n console.log('Error reading data.json')\n }\n if (testStepResult.status === 'FAILED') {\n stepProgess.result = this.getFailedTestStepResult(\n {\n commands: stepProgess.commands,\n startTime: prevStepResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n result: testStepResult\n }\n )\n } else {\n stepProgess.result = {\n status: testStepResult.status,\n startTime: prevStepResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n }\n }\n\n stepProgess.webLog = this.stepLogs\n stepProgess.networkData = this.stepNetworkLogs\n this.stepNetworkLogs = []\n this.stepLogs = []\n if (Object.keys(data).length > 0) {\n stepProgess.data = data\n }\n }\n getLogFileContent() {\n let projectPath = process.cwd()\n if (process.env.PROJECT_PATH) {\n projectPath = process.env.PROJECT_PATH\n }\n const logFolder = path.join(projectPath, 'logs', 'web')\n if (!fs.existsSync(logFolder)) {\n return []\n }\n let nextId = 1\n while (fs.existsSync(path.join(logFolder, `${nextId}.json`))) {\n nextId++\n }\n if (nextId === 1) {\n return []\n }\n try {\n const logFileContent = fs.readFileSync(\n path.join(logFolder, `${nextId - 1}.json`),\n 'utf8'\n )\n return JSON.parse(logFileContent)\n } catch (error) {\n return []\n }\n }\n private getTestCaseResult(steps: JsonStep[]) {\n for (const step of steps) {\n switch (step.result.status) {\n case 'FAILED':\n return {\n status: step.result.status,\n message: step.result.message,\n // exception: step.result.exception,\n } as const\n case 'AMBIGUOUS':\n case 'UNDEFINED':\n case 'PENDING':\n return {\n status: 'FAILED',\n message: `step \"${step.text}\" is ${step.result.status}`,\n } as const\n }\n }\n return {\n status: 'PASSED',\n } as const\n }\n private async onTestCaseFinished(\n testCaseFinished: messages.TestCaseFinished\n ) {\n const { testCaseStartedId, timestamp } = testCaseFinished\n const testProgress = this.testCaseReportMap.get(testCaseStartedId)\n const prevResult = testProgress.result as {\n status: 'STARTED'\n startTime: JsonTimestamp\n }\n const steps = Object.values(testProgress.steps)\n const result = this.getTestCaseResult(steps)\n testProgress.result = {\n ...result,\n startTime: prevResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n }\n testProgress.webLog = this.logs\n testProgress.networkLog = this.networkLog\n this.networkLog = []\n this.logs = []\n await this.uploadTestCase(testProgress)\n }\n private async uploadTestCase(testCase: JsonTestProgress) {\n let runId = ''\n let projectId = ''\n if (!process.env.UPLOADING_TEST_CASE) {\n process.env.UPLOADING_TEST_CASE = '[]'\n }\n const anyRemArr = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n const randomID = Math.random().toString(36).substring(7)\n anyRemArr.push(randomID)\n process.env.UPLOADING_TEST_CASE = JSON.stringify(anyRemArr)\n try {\n if (\n process.env.RUN_ID &&\n process.env.PROJECT_ID &&\n !process.env.IGNORE_ENV_VARIABLES\n ) {\n runId = process.env.RUN_ID\n projectId = process.env.PROJECT_ID\n } else {\n const runDoc = await this.uploadService.createRunDocument(this.runName)\n runId = runDoc._id\n projectId = runDoc.project_id\n if (!process.env.IGNORE_ENV_VARIABLES) {\n process.env.RUN_ID = runId\n process.env.PROJECT_ID = projectId\n }\n }\n await this.uploadService.uploadTestCase(\n testCase,\n runId,\n projectId,\n this.reportFolder\n )\n this.writeTestCaseReportToDisk(testCase)\n } catch (e) {\n console.error('Error uploading test case:', e)\n } finally {\n const arrRem = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n arrRem.splice(arrRem.indexOf(randomID), 1)\n process.env.UPLOADING_TEST_CASE = JSON.stringify(arrRem)\n }\n }\n private writeTestCaseReportToDisk(testCase: JsonTestProgress) {\n try {\n let i = 0\n while (fs.existsSync(path.join(this.reportFolder, `${i}`))) {\n i++\n }\n fs.mkdirSync(path.join(this.reportFolder, `${i}`))\n //exclude network log from the saved report\n const networkLog = testCase.networkLog\n delete testCase.networkLog\n fs.writeFileSync(\n path.join(this.reportFolder, `${i}`, `report.json`),\n JSON.stringify(testCase, null, 2)\n )\n fs.writeFileSync(\n path.join(this.reportFolder, `${i}`, `network.json`),\n JSON.stringify(networkLog, null, 2)\n )\n } catch (error) {\n console.error('Error writing test case report to disk:', error)\n }\n }\n private onTestRunFinished(testRunFinished: messages.TestRunFinished) {\n const { timestamp, success, message } = testRunFinished\n const prevResult = this.report.result as {\n status: 'STARTED'\n startTime: JsonTimestamp\n }\n this.report.result = {\n status: success ? 'PASSED' : 'FAILED',\n startTime: prevResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n message,\n // exception,\n }\n }\n}\n"]}
1
+ {"version":3,"file":"report_generator.js","sourceRoot":"","sources":["../../../src/formatter/helpers/report_generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA8C;AAC9C,4CAAmB;AACnB,gDAAuB;AACvB,qDAAmD;AAKnD,MAAM,GAAG,GACP,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,KAAK;IAClC,CAAC,CAAC,mCAAmC;IACrC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO;QACxC,CAAC,CAAC,gCAAgC;QAClC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO;YACxC,CAAC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AAE,CAAA;aACJ;YACD,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;YAClD,2CAA2C;YAC3C,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAA;YACtC,OAAO,QAAQ,CAAC,UAAU,CAAA;YAC1B,YAAE,CAAC,aAAa,CACd,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,EAAE,aAAa,CAAC,EACnD,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAClC,CAAA;YACD,YAAE,CAAC,aAAa,CACd,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,EAAE,cAAc,CAAC,EACpD,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CACpC,CAAA;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAA;SAChE;IACH,CAAC;IACO,iBAAiB,CAAC,eAAyC;QACjE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,eAAe,CAAA;QACvD,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAG9B,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG;YACnB,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;YACrC,SAAS,EAAE,UAAU,CAAC,SAAS;YAC/B,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC;YACrC,OAAO;YACP,aAAa;SACd,CAAA;IACH,CAAC;CACF;AA/jBD,kCA+jBC","sourcesContent":["import * as messages from '@cucumber/messages'\nimport fs from 'fs'\nimport path from 'path'\nimport { RunUploadService } from './upload_serivce'\n// type JsonException = messages.Exception\ntype JsonTimestamp = number //messages.Timestamp\ntype JsonStepType = 'Unknown' | 'Context' | 'Action' | 'Outcome' | 'Conjunction'\n\nconst URL =\n process.env.NODE_ENV_BLINQ === 'dev'\n ? 'https://dev.api.blinq.io/api/runs'\n : process.env.NODE_ENV_BLINQ === 'local'\n ? 'http://localhost:5001/api/runs'\n : process.env.NODE_ENV_BLINQ === 'stage'\n ? 'https://stage.api.blinq.io/api/runs'\n : 'https://api.blinq.io/api/runs'\n\nconst REPORT_SERVICE_URL = process.env.REPORT_SERVICE_URL ?? URL\nconst BATCH_SIZE = 10\nconst MAX_RETRIES = 3\nconst REPORT_SERVICE_TOKEN =\n process.env.TOKEN ?? process.env.REPORT_SERVICE_TOKEN\nexport type JsonResultUnknown = {\n status: 'UNKNOWN'\n}\ntype JsonResultSkipped = {\n status: 'SKIPPED'\n}\ntype JsonResultUndefined = {\n status: 'UNDEFINED'\n}\ntype JsonResultAmbiguous = {\n status: 'AMBIGUOUS'\n}\nexport type JsonResultStarted = {\n status: 'STARTED'\n startTime: JsonTimestamp\n}\ntype JsonResultPending = {\n status: 'PENDING'\n startTime: JsonTimestamp\n endTime: JsonTimestamp\n}\nexport type JsonResultPassed = {\n status: 'PASSED'\n startTime: JsonTimestamp\n endTime: JsonTimestamp\n}\nexport type JsonResultFailed = {\n status: 'FAILED'\n startTime: JsonTimestamp\n endTime: JsonTimestamp\n message?: string\n // exception?: JsonException\n}\nexport type JsonFixedByAi = {\n status: 'FIXED_BY_AI'\n startTime: JsonTimestamp\n endTime: JsonTimestamp\n}\n\ntype JsonCommandResult = JsonResultPassed | JsonResultFailed\ntype JsonStepResult =\n | JsonResultUnknown\n | JsonResultSkipped\n | JsonResultUndefined\n | JsonResultAmbiguous\n | JsonResultStarted\n | JsonResultPending\n | JsonResultPassed\n | JsonResultFailed\n | JsonFixedByAi\nexport type JsonTestResult =\n | JsonResultUnknown\n | JsonResultStarted\n | JsonResultPassed\n | JsonResultFailed\n | JsonFixedByAi\ntype JsonReportResult = JsonTestResult\n\ntype JsonCommand = {\n type: string\n value?: string\n text: string\n screenshotId?: string\n result: JsonCommandResult\n netWorkLog?: any[]\n}\ntype webLog = {\n type: string\n text: string\n location: string\n time: string\n}\nexport type JsonStep = {\n keyword: string\n type: JsonStepType\n text: string\n commands: JsonCommand[]\n result: JsonStepResult\n webLog: webLog[]\n networkData: any[]\n data?: any\n ariaSnapshot: string\n}\nexport type RetrainStats = {\n result: JsonTestResult\n totalSteps: number\n upload_id: string\n local_id: number\n}\nexport type JsonTestProgress = {\n id: string\n featureName: string\n uri: string\n scenarioName: string\n parameters: Record<string, string>\n steps: JsonStep[]\n result: JsonTestResult\n retrainStats?: RetrainStats\n initialAriaSnapshot?: string\n webLog: any\n networkLog: any\n env: {\n name: string\n baseUrl: string\n }\n}\n\nexport type JsonReport = {\n testCases: JsonTestProgress[]\n result: JsonReportResult\n env: {\n name: string\n baseUrl: string\n }\n}\n\ninterface MetaMessage extends messages.Meta {\n runName: string\n}\ninterface EnvelopeWithMetaMessage extends messages.Envelope {\n meta: MetaMessage\n}\nexport default class ReportGenerator {\n private report: JsonReport = {\n result: {\n status: 'UNKNOWN',\n },\n testCases: [] as JsonTestProgress[],\n env: {\n name: '',\n baseUrl: '',\n },\n }\n private gherkinDocumentMap = new Map<string, messages.GherkinDocument>()\n private stepMap = new Map<string, messages.Step>()\n private pickleMap = new Map<string, messages.Pickle>()\n private testCaseMap = new Map<string, messages.TestCase>()\n private testStepMap = new Map<string, messages.TestStep>()\n private stepReportMap = new Map<string, JsonStep>()\n private testCaseReportMap = new Map<string, JsonTestProgress>()\n private scenarioIterationCountMap = new Map<string, number>()\n private logs: webLog[] = []\n private networkLog: any[] = []\n private stepLogs: webLog[] = []\n private stepNetworkLogs: any[] = []\n private runName = ''\n private ariaSnapshot = ''\n private initialAriaSnapshot = ''\n reportFolder: null | string = null\n private uploadService = new RunUploadService(\n REPORT_SERVICE_URL,\n REPORT_SERVICE_TOKEN\n )\n\n async handleMessage(\n envelope: EnvelopeWithMetaMessage | messages.Envelope,\n reRunId?: string\n ): Promise<any> {\n if (envelope.meta && 'runName' in envelope.meta) {\n this.runName = envelope.meta.runName\n }\n const type = Object.keys(envelope)[0] as keyof messages.Envelope\n switch (type) {\n // case \"meta\": { break}\n // case \"source\": { break}\n case 'parseError': {\n const parseError = envelope[type]\n this.handleParseError(parseError)\n break\n }\n case 'gherkinDocument': {\n const doc = envelope[type]\n this.onGherkinDocument(doc)\n break\n }\n case 'pickle': {\n const pickle = envelope[type]\n this.onPickle(pickle)\n break\n }\n // case \"stepDefinition\": { break}\n // case \"hook\": { break} // Before Hook\n case 'testRunStarted': {\n const testRunStarted = envelope[type]\n this.onTestRunStarted(testRunStarted)\n break\n }\n case 'testCase': {\n const testCase = envelope[type]\n this.onTestCase(testCase)\n break\n }\n case 'testCaseStarted': {\n const testCaseStarted = envelope[type]\n this.onTestCaseStarted(testCaseStarted)\n break\n }\n case 'testStepStarted': {\n const testStepStarted = envelope[type]\n this.onTestStepStarted(testStepStarted)\n break\n }\n case 'attachment': {\n const attachment = envelope[type]\n this.onAttachment(attachment)\n break\n }\n case 'testStepFinished': {\n const testStepFinished = envelope[type]\n this.onTestStepFinished(testStepFinished)\n break\n }\n case 'testCaseFinished': {\n const testCaseFinished = envelope[type]\n return await this.onTestCaseFinished(testCaseFinished, reRunId)\n }\n // case \"hook\": { break} // After Hook\n case 'testRunFinished': {\n const testRunFinished = envelope[type]\n this.onTestRunFinished(testRunFinished)\n break\n }\n\n // case \"parameterType\" : { break}\n // case \"undefinedParameterType\": { break}\n }\n }\n getReport() {\n return this.report\n }\n private handleParseError(parseError: messages.ParseError) {\n const { message } = parseError\n const timestamp = new Date().getTime()\n this.report.result = {\n status: 'FAILED',\n startTime: timestamp,\n endTime: timestamp,\n message: message,\n }\n }\n\n private onGherkinDocument(doc: messages.GherkinDocument) {\n this.gherkinDocumentMap.set(doc.uri, doc)\n doc.feature.children.forEach((child) => {\n if (child.scenario) {\n child.scenario.steps.forEach((step) => {\n this.stepMap.set(step.id, step)\n })\n } else if (child.background) {\n child.background.steps.forEach((step) => {\n this.stepMap.set(step.id, step)\n })\n } else if (child.rule) {\n child.rule.children.forEach((child) => {\n if (child.scenario) {\n child.scenario.steps.forEach((step) => {\n this.stepMap.set(step.id, step)\n })\n } else if (child.background) {\n child.background.steps.forEach((step) => {\n this.stepMap.set(step.id, step)\n })\n }\n })\n }\n })\n }\n private onPickle(pickle: messages.Pickle) {\n this.pickleMap.set(pickle.id, pickle)\n }\n private getTimeStamp(timestamp: messages.Timestamp) {\n return timestamp.seconds * 1000 + timestamp.nanos / 1000000\n }\n private onTestRunStarted(testRunStarted: messages.TestRunStarted) {\n this.report.result = {\n status: 'STARTED',\n startTime: this.getTimeStamp(testRunStarted.timestamp),\n }\n }\n private onTestCase(testCase: messages.TestCase) {\n this.testCaseMap.set(testCase.id, testCase)\n testCase.testSteps.forEach((testStep) => {\n this.testStepMap.set(testStep.id, testStep)\n })\n }\n private _findScenario(doc: messages.GherkinDocument, scenarioId: string) {\n for (const child of doc.feature.children) {\n if (child.scenario && child.scenario.id === scenarioId) {\n return child.scenario\n }\n if (child.rule) {\n for (const scenario of child.rule.children) {\n if (scenario.scenario && scenario.scenario.id === scenarioId) {\n return scenario.scenario\n }\n }\n }\n }\n throw new Error(`scenario \"${scenarioId}\" not found`)\n }\n private _getParameters(scenario: messages.Scenario, exampleId: string) {\n const parameters: Record<string, string> = {}\n if (scenario.examples.length === 0) return parameters\n for (const examples of scenario.examples) {\n for (const tableRow of examples.tableBody) {\n if (tableRow.id === exampleId) {\n for (let i = 0; i < examples.tableHeader.cells.length; i++) {\n parameters[examples.tableHeader.cells[i].value] =\n tableRow.cells[i].value\n }\n }\n }\n }\n return parameters\n }\n private onTestCaseStarted(testCaseStarted: messages.TestCaseStarted) {\n const { testCaseId, id, timestamp } = testCaseStarted\n const testCase = this.testCaseMap.get(testCaseId)\n if (testCase === undefined)\n throw new Error(`testCase with id ${testCaseId} not found`)\n const pickle = this.pickleMap.get(testCase.pickleId)\n if (pickle === undefined)\n throw new Error(`pickle with id ${testCase.pickleId} not found`)\n\n const doc = this.gherkinDocumentMap.get(pickle.uri)\n if (doc === undefined)\n throw new Error(`gherkinDocument with uri ${pickle.uri} not found`)\n const featureName = doc.feature.name\n\n const scenarioId = pickle.astNodeIds[0]\n const scenario = this._findScenario(doc, scenarioId)\n const scenarioName = scenario.name\n if (!this.scenarioIterationCountMap.has(scenarioId)) {\n this.scenarioIterationCountMap.set(scenarioId, 1)\n }\n const parameters = this._getParameters(scenario, pickle.astNodeIds[1])\n console.log(\n `Running scenario ${scenarioName} iteration ${this.scenarioIterationCountMap.get(\n scenarioId\n )} with parameters:\\n${JSON.stringify(parameters, null, 4)}\\n \n `\n )\n this.scenarioIterationCountMap.set(\n scenarioId,\n this.scenarioIterationCountMap.get(scenarioId) + 1\n )\n const steps: JsonStep[] = pickle.steps.map((pickleStep) => {\n const stepId = pickleStep.astNodeIds[0]\n const step = this.stepMap.get(stepId)\n this.stepReportMap.set(pickleStep.id, {\n type: step.keywordType,\n keyword: step.keyword,\n text: step.text,\n commands: [],\n result: {\n status: 'UNKNOWN',\n },\n networkData: [],\n webLog: [],\n data: {},\n ariaSnapshot: this.ariaSnapshot,\n })\n return this.stepReportMap.get(pickleStep.id)\n })\n this.testCaseReportMap.set(id, {\n id,\n uri: pickle.uri,\n featureName,\n scenarioName,\n parameters,\n steps,\n result: {\n status: 'STARTED',\n startTime: this.getTimeStamp(timestamp),\n },\n webLog: [],\n networkLog: [],\n env: {\n name: this.report.env.name,\n baseUrl: this.report.env.baseUrl,\n },\n })\n this.report.testCases.push(this.testCaseReportMap.get(id))\n }\n private onTestStepStarted(testStepStarted: messages.TestStepStarted) {\n const { testStepId, timestamp } = testStepStarted\n const testStep = this.testStepMap.get(testStepId)\n if (testStep === undefined)\n throw new Error(`testStep with id ${testStepId} not found`)\n if (testStep.pickleStepId === undefined) return\n const stepProgess = this.stepReportMap.get(testStep.pickleStepId)\n stepProgess.result = {\n status: 'STARTED',\n startTime: this.getTimeStamp(timestamp),\n }\n }\n private onAttachment(attachment: messages.Attachment) {\n const { testStepId, body, mediaType } = attachment\n if (mediaType === 'text/plain') {\n this.reportFolder = body.replaceAll('\\\\', '/')\n return\n }\n if (mediaType === 'application/json+snapshot-before') {\n this.initialAriaSnapshot = body\n return\n }\n if (mediaType === 'application/json+snapshot-after') {\n this.ariaSnapshot = body\n return\n }\n if (mediaType === 'application/json+env') {\n const data = JSON.parse(body)\n this.report.env = data\n this.report.testCases.map((testCase) => {\n testCase.env = data\n return testCase\n })\n }\n if (mediaType === 'application/json+log') {\n const log: webLog = JSON.parse(body)\n if (this.logs.length < 1000) {\n this.logs.push(log)\n this.stepLogs.push(log)\n }\n }\n if (mediaType === 'application/json+network') {\n const networkLog = JSON.parse(body)\n if (this.networkLog.length < 1000) this.networkLog.push(networkLog)\n this.stepNetworkLogs.push(networkLog)\n }\n const testStep = this.testStepMap.get(testStepId)\n if (testStep.pickleStepId === undefined) return\n\n const stepProgess = this.stepReportMap.get(testStep.pickleStepId)\n if (mediaType === 'application/json') {\n const command: JsonCommand = JSON.parse(body)\n stepProgess.commands.push(command)\n }\n }\n private getFailedTestStepResult({\n commands,\n startTime,\n endTime,\n result,\n }: {\n commands: JsonCommand[]\n startTime: number\n endTime: number\n result: messages.TestStepResult\n }): JsonStepResult {\n for (const command of commands) {\n if (command.result.status === 'FAILED') {\n return {\n status: 'FAILED',\n message: command.result.message,\n startTime,\n endTime,\n } as const\n }\n }\n return {\n status: 'FAILED',\n startTime,\n endTime,\n message: result.message,\n }\n }\n private onTestStepFinished(testStepFinished: messages.TestStepFinished) {\n const { testStepId, testStepResult, timestamp } = testStepFinished\n const testStep = this.testStepMap.get(testStepId)\n if (testStep.pickleStepId === undefined) {\n if (testStepResult.status === 'FAILED') {\n console.error(\n `Before/After hook failed with message: ${testStepResult.message}`\n )\n }\n return\n }\n if (testStepResult.status === 'UNDEFINED') {\n const step = this.stepReportMap.get(testStep.pickleStepId)\n const stepName = step ? step.keyword + ' ' + step.text : 'Undefined step'\n const undefinedCommand: messages.Attachment = {\n testStepId: testStepId,\n body: JSON.stringify({\n type: 'error',\n text: 'Undefined step: ' + stepName,\n result: {\n status: 'FAILED',\n startTime: this.getTimeStamp(timestamp),\n endTime: this.getTimeStamp(timestamp),\n },\n }),\n mediaType: 'application/json',\n contentEncoding: messages.AttachmentContentEncoding.IDENTITY,\n }\n this.onAttachment(undefinedCommand)\n }\n const stepProgess = this.stepReportMap.get(testStep.pickleStepId)\n const prevStepResult = stepProgess.result as {\n status: 'STARTED'\n startTime: JsonTimestamp\n }\n let data = {}\n try {\n const reportFolder = this.reportFolder\n if (reportFolder === null) {\n throw new Error(\n '\"reportFolder\" is \"null\". Failed to run BVT hooks. Please retry after running \"Generate All\" or \"Record Scenario\" '\n )\n }\n if (fs.existsSync(path.join(reportFolder, 'data.json'))) {\n data = JSON.parse(\n fs.readFileSync(path.join(reportFolder, 'data.json'), 'utf8')\n )\n }\n } catch (error) {\n console.log('Error reading data.json')\n }\n if (testStepResult.status === 'FAILED') {\n stepProgess.result = this.getFailedTestStepResult({\n commands: stepProgess.commands,\n startTime: prevStepResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n result: testStepResult,\n })\n } else {\n stepProgess.result = {\n status: testStepResult.status,\n startTime: prevStepResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n }\n }\n\n stepProgess.webLog = this.stepLogs\n stepProgess.networkData = this.stepNetworkLogs\n stepProgess.ariaSnapshot = this.ariaSnapshot\n this.ariaSnapshot = ''\n this.stepNetworkLogs = []\n this.stepLogs = []\n if (Object.keys(data).length > 0) {\n stepProgess.data = data\n }\n }\n getLogFileContent() {\n let projectPath = process.cwd()\n if (process.env.PROJECT_PATH) {\n projectPath = process.env.PROJECT_PATH\n }\n const logFolder = path.join(projectPath, 'logs', 'web')\n if (!fs.existsSync(logFolder)) {\n return []\n }\n let nextId = 1\n while (fs.existsSync(path.join(logFolder, `${nextId}.json`))) {\n nextId++\n }\n if (nextId === 1) {\n return []\n }\n try {\n const logFileContent = fs.readFileSync(\n path.join(logFolder, `${nextId - 1}.json`),\n 'utf8'\n )\n return JSON.parse(logFileContent)\n } catch (error) {\n return []\n }\n }\n private getTestCaseResult(steps: JsonStep[]) {\n for (const step of steps) {\n switch (step.result.status) {\n case 'FAILED':\n return {\n status: step.result.status,\n message: step.result.message,\n // exception: step.result.exception,\n } as const\n case 'AMBIGUOUS':\n case 'UNDEFINED':\n case 'PENDING':\n return {\n status: 'FAILED',\n message: `step \"${step.text}\" is ${step.result.status}`,\n } as const\n }\n }\n return {\n status: 'PASSED',\n } as const\n }\n private async onTestCaseFinished(\n testCaseFinished: messages.TestCaseFinished,\n reRunId?: string\n ) {\n const { testCaseStartedId, timestamp } = testCaseFinished\n const testProgress = this.testCaseReportMap.get(testCaseStartedId)\n const prevResult = testProgress.result as {\n status: 'STARTED'\n startTime: JsonTimestamp\n }\n const steps = Object.values(testProgress.steps)\n const result = this.getTestCaseResult(steps)\n testProgress.result = {\n ...result,\n startTime: prevResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n }\n testProgress.webLog = this.logs\n testProgress.networkLog = this.networkLog\n testProgress.initialAriaSnapshot = this.initialAriaSnapshot\n this.initialAriaSnapshot = ''\n this.networkLog = []\n this.logs = []\n return await this.uploadTestCase(testProgress, reRunId)\n }\n private async uploadTestCase(testCase: JsonTestProgress, rerunId?: string) {\n let runId = ''\n let projectId = ''\n if (!process.env.UPLOADING_TEST_CASE) {\n process.env.UPLOADING_TEST_CASE = '[]'\n }\n const anyRemArr = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n const randomID = Math.random().toString(36).substring(7)\n anyRemArr.push(randomID)\n let data\n process.env.UPLOADING_TEST_CASE = JSON.stringify(anyRemArr)\n try {\n if (\n process.env.RUN_ID &&\n process.env.PROJECT_ID &&\n !process.env.IGNORE_ENV_VARIABLES\n ) {\n runId = process.env.RUN_ID\n projectId = process.env.PROJECT_ID\n } else {\n const runDoc = await this.uploadService.createRunDocument(this.runName)\n runId = runDoc._id\n projectId = runDoc.project_id\n if (!process.env.IGNORE_ENV_VARIABLES) {\n process.env.RUN_ID = runId\n process.env.PROJECT_ID = projectId\n }\n }\n data = await this.uploadService.uploadTestCase(\n testCase,\n runId,\n projectId,\n this.reportFolder,\n rerunId\n )\n this.writeTestCaseReportToDisk(testCase)\n } catch (e) {\n console.error('Error uploading test case:', e)\n } finally {\n const arrRem = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n arrRem.splice(arrRem.indexOf(randomID), 1)\n process.env.UPLOADING_TEST_CASE = JSON.stringify(arrRem)\n }\n return data ? data : null\n }\n private writeTestCaseReportToDisk(testCase: JsonTestProgress) {\n try {\n let i = 0\n while (fs.existsSync(path.join(this.reportFolder, `${i}`))) {\n i++\n }\n fs.mkdirSync(path.join(this.reportFolder, `${i}`))\n //exclude network log from the saved report\n const networkLog = testCase.networkLog\n delete testCase.networkLog\n fs.writeFileSync(\n path.join(this.reportFolder, `${i}`, `report.json`),\n JSON.stringify(testCase, null, 2)\n )\n fs.writeFileSync(\n path.join(this.reportFolder, `${i}`, `network.json`),\n JSON.stringify(networkLog, null, 2)\n )\n } catch (error) {\n console.error('Error writing test case report to disk:', error)\n }\n }\n private onTestRunFinished(testRunFinished: messages.TestRunFinished) {\n const { timestamp, success, message } = testRunFinished\n const prevResult = this.report.result as {\n status: 'STARTED'\n startTime: JsonTimestamp\n }\n this.report.result = {\n status: success ? 'PASSED' : 'FAILED',\n startTime: prevResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n message,\n // exception,\n }\n }\n}\n"]}
@@ -1,5 +1,16 @@
1
1
  import FormData from 'form-data';
2
2
  import { JsonTestProgress } from './report_generator';
3
+ export interface RootCauseProps {
4
+ status: boolean;
5
+ analysis: string;
6
+ failedStep: number;
7
+ failClass: string;
8
+ }
9
+ export interface FinishTestCaseResponse {
10
+ status: true;
11
+ rootCause: RootCauseProps;
12
+ report: JsonTestProgress;
13
+ }
3
14
  declare class RunUploadService {
4
15
  private runsApiBaseURL;
5
16
  private accessToken;
@@ -7,7 +18,7 @@ declare class RunUploadService {
7
18
  createRunDocument(name: string): Promise<any>;
8
19
  upload(formData: FormData): Promise<void>;
9
20
  getPreSignedUrls(fileUris: string[], runId: string): Promise<any>;
10
- uploadTestCase(testCaseReport: JsonTestProgress, runId: string, projectId: string, reportFolder: string): Promise<void>;
21
+ uploadTestCase(testCaseReport: JsonTestProgress, runId: string, projectId: string, reportFolder: string, rerunId?: string): Promise<FinishTestCaseResponse>;
11
22
  uploadFile(filePath: string, preSignedUrl: string): Promise<boolean>;
12
23
  uploadComplete(runId: string, projectId: string): Promise<void>;
13
24
  modifyTestCase(runId: string, projectId: string, testProgressReport: JsonTestProgress): Promise<void>;
@@ -87,7 +87,7 @@ class RunUploadService {
87
87
  }
88
88
  return response.data.uploadUrls;
89
89
  }
90
- async uploadTestCase(testCaseReport, runId, projectId, reportFolder) {
90
+ async uploadTestCase(testCaseReport, runId, projectId, reportFolder, rerunId) {
91
91
  const fileUris = [];
92
92
  //iterate over all the files in the JsonCommand.screenshotId and insert them into the fileUris array
93
93
  for (const step of testCaseReport.steps) {
@@ -116,12 +116,13 @@ class RunUploadService {
116
116
  console.error('Failed to upload file:', fileUri);
117
117
  }));
118
118
  }
119
- await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/createNewTestCase', {
119
+ const { data } = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/createNewTestCase', {
120
120
  runId,
121
121
  projectId,
122
122
  testProgressReport: testCaseReport,
123
123
  mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',
124
124
  browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',
125
+ rerunId,
125
126
  }, {
126
127
  headers: {
127
128
  Authorization: 'Bearer ' + this.accessToken,
@@ -143,9 +144,11 @@ class RunUploadService {
143
144
  // no event tracking
144
145
  }
145
146
  (0, bvt_analysis_formatter_1.logReportLink)(runId, projectId);
147
+ return data;
146
148
  }
147
149
  catch (e) {
148
150
  console.error(`failed to upload the test case: ${testCaseReport.id} ${e}`);
151
+ return null;
149
152
  }
150
153
  }
151
154
  async uploadFile(filePath, preSignedUrl) {
@@ -1 +1 @@
1
- {"version":3,"file":"upload_serivce.js","sourceRoot":"","sources":["../../../src/formatter/helpers/upload_serivce.ts"],"names":[],"mappings":";;;;;;;AAEA,2BAAiD;AACjD,2DAA4B;AAG5B,mEAA8D;AAC9D,gDAAuB;AACvB,sEAAyD;AACzD,2CAAwD;AAExD,MAAM,kBAAkB,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,kBAAkB,mCAAI,GAAG,CAAA;AAChE,MAAM,UAAU,GAAG,EAAE,CAAA;AACrB,MAAM,WAAW,GAAG,CAAC,CAAA;AACrB,MAAM,oBAAoB,GACxB,MAAA,OAAO,CAAC,GAAG,CAAC,KAAK,mCAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA;AACvD,MAAM,gBAAgB;IACpB,YAAoB,cAAsB,EAAU,WAAmB;QAAnD,mBAAc,GAAd,cAAc,CAAQ;QAAU,gBAAW,GAAX,WAAW,CAAQ;IAAG,CAAC;IAC3E,KAAK,CAAC,iBAAiB,CAAC,IAAY;QAClC,IAAI;YACF,MAAM,YAAY,GAAG,MAAM,0BAAW,CAAC,IAAI,CACzC,IAAI,CAAC,cAAc,GAAG,uBAAuB,EAC7C;gBACE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM;aAC3B,EACD;gBACE,OAAO,EAAE;oBACP,aAAa,EAAE,SAAS,GAAG,IAAI,CAAC,WAAW;oBAC3C,UAAU,EAAE,aAAa;iBAC1B;aACF,CACF,CAAA;YACD,IAAI,YAAY,CAAC,MAAM,KAAK,GAAG,EAAE;gBAC/B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;aAC/D;YACD,IAAI,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AI;YACF,MAAM,GAAG,GAAG,MAAM,0BAAW,CAAC,IAAI,CAChC,IAAI,CAAC,cAAc,GAAG,+BAA+B,EACrD;gBACE,KAAK;gBACL,SAAS;gBACT,kBAAkB;aACnB,EACD;gBACE,OAAO,EAAE;oBACP,aAAa,EAAE,SAAS,GAAG,IAAI,CAAC,WAAW;oBAC3C,UAAU,EAAE,aAAa;iBAC1B;aACF,CACF,CAAA;YACD,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;gBACtB,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAA;aACpB;YACD,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE;gBAC5B,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAA;aACpB;YACD,IAAA,sCAAa,EAAC,KAAK,EAAE,SAAS,CAAC,CAAA;SAChC;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CACX,mCAAmC,kBAAkB,CAAC,EAAE,IAAI,CAAC,EAAE,CAChE,CAAA;SACF;IACH,CAAC;CACF;AAEQ,4CAAgB","sourcesContent":["/* eslint-disable no-console */\nimport FormData from 'form-data'\nimport { createReadStream, existsSync } from 'fs'\nimport fs from 'fs/promises'\n\nimport { JsonReport, JsonTestProgress } from './report_generator'\nimport { axiosClient } from '../../configuration/axios_client'\nimport path from 'path'\nimport { logReportLink } from '../bvt_analysis_formatter'\nimport { ActionEvents, SERVICES_URI } from './constants'\n\nconst REPORT_SERVICE_URL = process.env.REPORT_SERVICE_URL ?? URL\nconst BATCH_SIZE = 10\nconst MAX_RETRIES = 3\nconst REPORT_SERVICE_TOKEN =\n process.env.TOKEN ?? process.env.REPORT_SERVICE_TOKEN\nclass RunUploadService {\n constructor(private runsApiBaseURL: string, private accessToken: string) {}\n async createRunDocument(name: string) {\n try {\n const runDocResult = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/create',\n {\n name: name ? name : 'TEST',\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (runDocResult.status !== 200) {\n throw new Error('Failed to create run document in the server')\n }\n if (runDocResult.data.status !== true) {\n throw new Error('Failed to create run document in the server')\n }\n return runDocResult.data.run\n } catch (error) {\n if (error.response && error.response.status === 403) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot create or upload reports.'\n )\n process.exit(1)\n }\n throw new Error('Failed to create run document in the server: ' + error)\n }\n }\n async upload(formData: FormData) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/upload',\n formData,\n {\n headers: {\n ...formData.getHeaders(),\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status === 401) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n throw new Error(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n }\n if (response.status !== 200) {\n throw new Error('Failed to upload run to the server')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to upload run to the server')\n }\n }\n async getPreSignedUrls(fileUris: string[], runId: string) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/generateuploadurls',\n {\n fileUris,\n runId,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status === 403) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n throw new Error(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n }\n if (response.status !== 200) {\n throw new Error('Failed to get pre-signed urls for the files')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to get pre-signed urls for the files')\n }\n\n return response.data.uploadUrls\n }\n\n async uploadTestCase(\n testCaseReport: JsonTestProgress,\n runId: string,\n projectId: string,\n reportFolder: string\n ) {\n const fileUris = []\n //iterate over all the files in the JsonCommand.screenshotId and insert them into the fileUris array\n for (const step of testCaseReport.steps) {\n for (const command of step.commands) {\n if (command.screenshotId) {\n fileUris.push(\n 'screenshots' + '/' + String(command.screenshotId) + '.png'\n )\n }\n }\n }\n const preSignedUrls = await this.getPreSignedUrls(fileUris, runId)\n //upload all the files in the fileUris array\n try {\n for (let i = 0; i < fileUris.length; i += BATCH_SIZE) {\n const batch = fileUris.slice(\n i,\n Math.min(i + BATCH_SIZE, fileUris.length)\n )\n await Promise.all(\n batch\n .filter((fileUri) => preSignedUrls[fileUri])\n .map(async (fileUri) => {\n for (let j = 0; j < MAX_RETRIES; j++) {\n if (existsSync(path.join(reportFolder, fileUri))) {\n const success = await this.uploadFile(\n path.join(reportFolder, fileUri),\n preSignedUrls[fileUri]\n )\n if (success) {\n return\n }\n }\n }\n console.error('Failed to upload file:', fileUri)\n })\n )\n }\n await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/createNewTestCase',\n {\n runId,\n projectId,\n testProgressReport: testCaseReport,\n mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',\n browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n\n try {\n await axiosClient.post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event: ActionEvents.upload_report,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n 'x-bvt-project-id': projectId,\n },\n }\n )\n } catch (error) {\n // no event tracking\n }\n logReportLink(runId, projectId)\n } catch (e) {\n console.error(`failed to upload the test case: ${testCaseReport.id} ${e}`)\n }\n }\n async uploadFile(filePath: string, preSignedUrl: string) {\n const fileStream = createReadStream(filePath)\n let success = true\n try {\n const fileStats = await fs.stat(filePath)\n const fileSize = fileStats.size\n\n await axiosClient.put(preSignedUrl, fileStream, {\n headers: {\n 'Content-Type': 'application/octet-stream',\n 'Content-Length': fileSize,\n },\n })\n } catch (error) {\n if (process.env.NODE_ENV_BLINQ === 'dev') {\n console.error('Error uploading file:', error)\n }\n success = false\n } finally {\n fileStream.close()\n }\n return success\n }\n async uploadComplete(runId: string, projectId: string) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/uploadCompletion',\n {\n runId,\n projectId,\n mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',\n browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status !== 200) {\n throw new Error('Failed to mark run as complete')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to mark run as complete')\n }\n\n try {\n await axiosClient.post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event: ActionEvents.upload_report,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n 'x-bvt-project-id': projectId,\n },\n }\n )\n } catch (error) {\n // no event tracking\n }\n }\n async modifyTestCase(\n runId: string,\n projectId: string,\n testProgressReport: JsonTestProgress\n ) {\n try {\n const res = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/modifyTestCase',\n {\n runId,\n projectId,\n testProgressReport,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (res.status !== 200) {\n throw new Error('')\n }\n if (res.data.status !== true) {\n throw new Error('')\n }\n logReportLink(runId, projectId)\n } catch (e) {\n console.error(\n `failed to modify the test case: ${testProgressReport.id} ${e}`\n )\n }\n }\n}\n\nexport { RunUploadService }\n"]}
1
+ {"version":3,"file":"upload_serivce.js","sourceRoot":"","sources":["../../../src/formatter/helpers/upload_serivce.ts"],"names":[],"mappings":";;;;;;;AAEA,2BAAiD;AACjD,2DAA4B;AAG5B,mEAA8D;AAC9D,gDAAuB;AACvB,sEAAyD;AACzD,2CAAwD;AAExD,MAAM,kBAAkB,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,kBAAkB,mCAAI,GAAG,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AE,CAAC,CAAA;aACpB;YACD,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE;gBAC5B,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAA;aACpB;YACD,IAAA,sCAAa,EAAC,KAAK,EAAE,SAAS,CAAC,CAAA;SAChC;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CACX,mCAAmC,kBAAkB,CAAC,EAAE,IAAI,CAAC,EAAE,CAChE,CAAA;SACF;IACH,CAAC;CACF;AAEQ,4CAAgB","sourcesContent":["/* eslint-disable no-console */\nimport FormData from 'form-data'\nimport { createReadStream, existsSync } from 'fs'\nimport fs from 'fs/promises'\n\nimport { JsonReport, JsonTestProgress } from './report_generator'\nimport { axiosClient } from '../../configuration/axios_client'\nimport path from 'path'\nimport { logReportLink } from '../bvt_analysis_formatter'\nimport { ActionEvents, SERVICES_URI } from './constants'\n\nconst REPORT_SERVICE_URL = process.env.REPORT_SERVICE_URL ?? URL\nconst BATCH_SIZE = 10\nconst MAX_RETRIES = 3\nconst REPORT_SERVICE_TOKEN =\n process.env.TOKEN ?? process.env.REPORT_SERVICE_TOKEN\n\nexport interface RootCauseProps {\n status: boolean\n analysis: string\n failedStep: number\n failClass: string\n}\n\nexport interface FinishTestCaseResponse {\n status: true\n rootCause: RootCauseProps\n report: JsonTestProgress\n}\n\nclass RunUploadService {\n constructor(private runsApiBaseURL: string, private accessToken: string) {}\n async createRunDocument(name: string) {\n try {\n const runDocResult = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/create',\n {\n name: name ? name : 'TEST',\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (runDocResult.status !== 200) {\n throw new Error('Failed to create run document in the server')\n }\n if (runDocResult.data.status !== true) {\n throw new Error('Failed to create run document in the server')\n }\n return runDocResult.data.run\n } catch (error) {\n if (error.response && error.response.status === 403) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot create or upload reports.'\n )\n process.exit(1)\n }\n throw new Error('Failed to create run document in the server: ' + error)\n }\n }\n async upload(formData: FormData) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/upload',\n formData,\n {\n headers: {\n ...formData.getHeaders(),\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status === 401) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n throw new Error(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n }\n if (response.status !== 200) {\n throw new Error('Failed to upload run to the server')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to upload run to the server')\n }\n }\n async getPreSignedUrls(fileUris: string[], runId: string) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/generateuploadurls',\n {\n fileUris,\n runId,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status === 403) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n throw new Error(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n }\n if (response.status !== 200) {\n throw new Error('Failed to get pre-signed urls for the files')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to get pre-signed urls for the files')\n }\n\n return response.data.uploadUrls\n }\n\n async uploadTestCase(\n testCaseReport: JsonTestProgress,\n runId: string,\n projectId: string,\n reportFolder: string,\n rerunId?: string\n ) {\n const fileUris = []\n //iterate over all the files in the JsonCommand.screenshotId and insert them into the fileUris array\n for (const step of testCaseReport.steps) {\n for (const command of step.commands) {\n if (command.screenshotId) {\n fileUris.push(\n 'screenshots' + '/' + String(command.screenshotId) + '.png'\n )\n }\n }\n }\n const preSignedUrls = await this.getPreSignedUrls(fileUris, runId)\n //upload all the files in the fileUris array\n try {\n for (let i = 0; i < fileUris.length; i += BATCH_SIZE) {\n const batch = fileUris.slice(\n i,\n Math.min(i + BATCH_SIZE, fileUris.length)\n )\n await Promise.all(\n batch\n .filter((fileUri) => preSignedUrls[fileUri])\n .map(async (fileUri) => {\n for (let j = 0; j < MAX_RETRIES; j++) {\n if (existsSync(path.join(reportFolder, fileUri))) {\n const success = await this.uploadFile(\n path.join(reportFolder, fileUri),\n preSignedUrls[fileUri]\n )\n if (success) {\n return\n }\n }\n }\n console.error('Failed to upload file:', fileUri)\n })\n )\n }\n const { data } = await axiosClient.post<FinishTestCaseResponse>(\n this.runsApiBaseURL + '/cucumber-runs/createNewTestCase',\n {\n runId,\n projectId,\n testProgressReport: testCaseReport,\n mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',\n browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',\n rerunId,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n\n try {\n await axiosClient.post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event: ActionEvents.upload_report,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n 'x-bvt-project-id': projectId,\n },\n }\n )\n } catch (error) {\n // no event tracking\n }\n logReportLink(runId, projectId)\n return data\n } catch (e) {\n console.error(`failed to upload the test case: ${testCaseReport.id} ${e}`)\n return null\n }\n }\n async uploadFile(filePath: string, preSignedUrl: string) {\n const fileStream = createReadStream(filePath)\n let success = true\n try {\n const fileStats = await fs.stat(filePath)\n const fileSize = fileStats.size\n\n await axiosClient.put(preSignedUrl, fileStream, {\n headers: {\n 'Content-Type': 'application/octet-stream',\n 'Content-Length': fileSize,\n },\n })\n } catch (error) {\n if (process.env.NODE_ENV_BLINQ === 'dev') {\n console.error('Error uploading file:', error)\n }\n success = false\n } finally {\n fileStream.close()\n }\n return success\n }\n async uploadComplete(runId: string, projectId: string) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/uploadCompletion',\n {\n runId,\n projectId,\n mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',\n browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status !== 200) {\n throw new Error('Failed to mark run as complete')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to mark run as complete')\n }\n\n try {\n await axiosClient.post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event: ActionEvents.upload_report,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n 'x-bvt-project-id': projectId,\n },\n }\n )\n } catch (error) {\n // no event tracking\n }\n }\n async modifyTestCase(\n runId: string,\n projectId: string,\n testProgressReport: JsonTestProgress\n ) {\n try {\n const res = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/modifyTestCase',\n {\n runId,\n projectId,\n testProgressReport,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (res.status !== 200) {\n throw new Error('')\n }\n if (res.data.status !== true) {\n throw new Error('')\n }\n logReportLink(runId, projectId)\n } catch (e) {\n console.error(\n `failed to modify the test case: ${testProgressReport.id} ${e}`\n )\n }\n }\n}\n\nexport { RunUploadService }\n"]}
@@ -37,6 +37,7 @@ export default class TestCaseRunner {
37
37
  private testStepResults;
38
38
  private world;
39
39
  private readonly worldParameters;
40
+ private reportGenerator;
40
41
  constructor({ eventBroadcaster, stopwatch, gherkinDocument, newId, pickle, testCase, retries, skip, filterStackTraces, supportCodeLibrary, worldParameters, }: INewTestCaseRunnerOptions);
41
42
  resetTestProgressData(): void;
42
43
  getBeforeStepHookDefinitions(): TestStepHookDefinition[];
@@ -32,6 +32,8 @@ const step_runner_1 = __importDefault(require("./step_runner"));
32
32
  const messages = __importStar(require("@cucumber/messages"));
33
33
  const messages_1 = require("@cucumber/messages");
34
34
  const value_checker_1 = require("../value_checker");
35
+ const report_generator_1 = __importDefault(require("../formatter/helpers/report_generator"));
36
+ const bvt_analysis_formatter_1 = __importDefault(require("../formatter/bvt_analysis_formatter"));
35
37
  class TestCaseRunner {
36
38
  constructor({ eventBroadcaster, stopwatch, gherkinDocument, newId, pickle, testCase, retries = 0, skip, filterStackTraces, supportCodeLibrary, worldParameters, }) {
37
39
  this.attachmentManager = new attachment_manager_1.default(({ data, media, fileName }) => {
@@ -62,6 +64,7 @@ class TestCaseRunner {
62
64
  this.supportCodeLibrary = supportCodeLibrary;
63
65
  this.worldParameters = worldParameters;
64
66
  this.resetTestProgressData();
67
+ this.reportGenerator = new report_generator_1.default();
65
68
  }
66
69
  resetTestProgressData() {
67
70
  this.world = new this.supportCodeLibrary.World({
@@ -187,7 +190,13 @@ class TestCaseRunner {
187
190
  willBeRetried,
188
191
  },
189
192
  };
190
- this.eventBroadcaster.emit('envelope', testCaseFinished);
193
+ const rerunId = bvt_analysis_formatter_1.default.reRunFailedStepsIndex
194
+ ? bvt_analysis_formatter_1.default.reRunFailedStepsIndex[0].testCaseId
195
+ : null;
196
+ const data = bvt_analysis_formatter_1.default.reportGenerator
197
+ ? await bvt_analysis_formatter_1.default.reportGenerator.handleMessage(testCaseFinished, rerunId)
198
+ : null;
199
+ this.eventBroadcaster.emit('envelope', testCaseFinished, data);
191
200
  return willBeRetried;
192
201
  }
193
202
  async runHook(hookDefinition, hookParameter, isBeforeHook) {
@@ -1 +1 @@
1
- {"version":3,"file":"test_case_runner.js","sourceRoot":"","sources":["../../src/runtime/test_case_runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAqD;AACrD,8EAAoD;AACpD,gEAAsC;AACtC,6DAA8C;AAC9C,iDAAwE;AAUxE,oDAAkE;AAkBlE,MAAqB,cAAc;IAkBjC,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,KAAK,EACL,MAAM,EACN,QAAQ,EACR,OAAO,GAAG,CAAC,EACX,IAAI,EACJ,iBAAiB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AAC,CAAC,CAAA;QACrE,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE;YAChC,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,YAAY,CAClD,aAAa,EACb,MAAM,CAAC,QAAQ,CAChB,CAAA;SACF;QACD,eAAe,CAAC,QAAQ,GAAG,aAAa,CAAA;QACxC,OAAO,eAAe,CAAA;IACxB,CAAC;CACF;AAlUD,iCAkUC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAuC;IAEvC,OAAO;QACL,GAAG,kBAAkB,CAAC,6BAA6B;QACnD,GAAG,kBAAkB,CAAC,4BAA4B;KACnD,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAuC;IAEvC,OAAO,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAC5C,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CACrC,CAAA;AACH,CAAC","sourcesContent":["import { getAmbiguousStepException } from './helpers'\nimport AttachmentManager from './attachment_manager'\nimport StepRunner from './step_runner'\nimport * as messages from '@cucumber/messages'\nimport { getWorstTestStepResult, IdGenerator } from '@cucumber/messages'\nimport { EventEmitter } from 'events'\nimport {\n ISupportCodeLibrary,\n ITestCaseHookParameter,\n ITestStepHookParameter,\n} from '../support_code_library_builder/types'\nimport TestCaseHookDefinition from '../models/test_case_hook_definition'\nimport TestStepHookDefinition from '../models/test_step_hook_definition'\nimport { IDefinition } from '../models/definition'\nimport { doesHaveValue, doesNotHaveValue } from '../value_checker'\nimport { IStopwatch } from './stopwatch'\nimport StepDefinition from '../models/step_definition'\n\nexport interface INewTestCaseRunnerOptions {\n eventBroadcaster: EventEmitter\n stopwatch: IStopwatch\n gherkinDocument: messages.GherkinDocument\n newId: IdGenerator.NewId\n pickle: messages.Pickle\n testCase: messages.TestCase\n retries: number\n skip: boolean\n filterStackTraces: boolean\n supportCodeLibrary: ISupportCodeLibrary\n worldParameters: any\n}\n\nexport default class TestCaseRunner {\n private readonly attachmentManager: AttachmentManager\n private currentTestCaseStartedId: string\n private currentTestStepId: string\n private readonly eventBroadcaster: EventEmitter\n private readonly stopwatch: IStopwatch\n private readonly gherkinDocument: messages.GherkinDocument\n private readonly newId: IdGenerator.NewId\n private readonly pickle: messages.Pickle\n private readonly testCase: messages.TestCase\n private readonly maxAttempts: number\n private readonly skip: boolean\n private readonly filterStackTraces: boolean\n private readonly supportCodeLibrary: ISupportCodeLibrary\n private testStepResults: messages.TestStepResult[]\n private world: any\n private readonly worldParameters: any\n\n constructor({\n eventBroadcaster,\n stopwatch,\n gherkinDocument,\n newId,\n pickle,\n testCase,\n retries = 0,\n skip,\n filterStackTraces,\n supportCodeLibrary,\n worldParameters,\n }: INewTestCaseRunnerOptions) {\n this.attachmentManager = new AttachmentManager(\n ({ data, media, fileName }) => {\n if (doesNotHaveValue(this.currentTestStepId)) {\n throw new Error(\n 'Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish.'\n )\n }\n const attachment: messages.Envelope = {\n attachment: {\n body: data,\n contentEncoding: media.encoding,\n mediaType: media.contentType,\n fileName,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n },\n }\n this.eventBroadcaster.emit('envelope', attachment)\n }\n )\n this.eventBroadcaster = eventBroadcaster\n this.stopwatch = stopwatch\n this.gherkinDocument = gherkinDocument\n this.maxAttempts = 1 + (skip ? 0 : retries)\n this.newId = newId\n this.pickle = pickle\n this.testCase = testCase\n this.skip = skip\n this.filterStackTraces = filterStackTraces\n this.supportCodeLibrary = supportCodeLibrary\n this.worldParameters = worldParameters\n this.resetTestProgressData()\n }\n\n resetTestProgressData(): void {\n this.world = new this.supportCodeLibrary.World({\n attach: this.attachmentManager.create.bind(this.attachmentManager),\n log: this.attachmentManager.log.bind(this.attachmentManager),\n parameters: this.worldParameters,\n })\n this.testStepResults = []\n }\n\n getBeforeStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.beforeTestStepHookDefinitions.filter(\n (hookDefinition) => hookDefinition.appliesToTestCase(this.pickle)\n )\n }\n\n getAfterStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.afterTestStepHookDefinitions\n .slice(0)\n .reverse()\n .filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle))\n }\n\n getWorstStepResult(): messages.TestStepResult {\n if (this.testStepResults.length === 0) {\n return {\n status: this.skip\n ? messages.TestStepResultStatus.SKIPPED\n : messages.TestStepResultStatus.PASSED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n return getWorstTestStepResult(this.testStepResults)\n }\n\n async invokeStep(\n step: messages.PickleStep,\n stepDefinition: IDefinition,\n hookParameter?: any\n ): Promise<messages.TestStepResult> {\n return await StepRunner.run({\n defaultTimeout: this.supportCodeLibrary.defaultTimeout,\n filterStackTraces: this.filterStackTraces,\n hookParameter,\n step,\n stepDefinition,\n world: this.world,\n })\n }\n\n isSkippingSteps(): boolean {\n return (\n this.getWorstStepResult().status !== messages.TestStepResultStatus.PASSED\n )\n }\n\n shouldSkipHook(isBeforeHook: boolean): boolean {\n return this.skip || (this.isSkippingSteps() && isBeforeHook)\n }\n\n async aroundTestStep(\n testStepId: string,\n runStepFn: () => Promise<messages.TestStepResult>\n ): Promise<void> {\n const testStepStarted: messages.Envelope = {\n testStepStarted: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepStarted)\n this.currentTestStepId = testStepId\n const testStepResult = await runStepFn()\n this.currentTestStepId = null\n this.testStepResults.push(testStepResult)\n const testStepFinished: messages.Envelope = {\n testStepFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n testStepResult,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepFinished)\n }\n\n async run(): Promise<messages.TestStepResultStatus> {\n for (let attempt = 0; attempt < this.maxAttempts; attempt++) {\n const moreAttemptsRemaining = attempt + 1 < this.maxAttempts\n\n const willBeRetried = await this.runAttempt(\n attempt,\n moreAttemptsRemaining\n )\n\n if (!willBeRetried) {\n break\n }\n this.resetTestProgressData()\n }\n return this.getWorstStepResult().status\n }\n\n async runAttempt(\n attempt: number,\n moreAttemptsRemaining: boolean\n ): Promise<boolean> {\n this.currentTestCaseStartedId = this.newId()\n const testCaseStarted: messages.Envelope = {\n testCaseStarted: {\n attempt,\n testCaseId: this.testCase.id,\n id: this.currentTestCaseStartedId,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testCaseStarted)\n // used to determine whether a hook is a Before or After\n let didWeRunStepsYet = false\n for (const testStep of this.testCase.testSteps) {\n await this.aroundTestStep(testStep.id, async () => {\n if (doesHaveValue(testStep.hookId)) {\n const hookParameter: ITestCaseHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n testCaseStartedId: this.currentTestCaseStartedId,\n }\n if (didWeRunStepsYet) {\n hookParameter.result = this.getWorstStepResult()\n hookParameter.willBeRetried =\n this.getWorstStepResult().status ===\n messages.TestStepResultStatus.FAILED && moreAttemptsRemaining\n }\n return await this.runHook(\n findHookDefinition(testStep.hookId, this.supportCodeLibrary),\n hookParameter,\n !didWeRunStepsYet\n )\n } else {\n const pickleStep = this.pickle.steps.find(\n (pickleStep) => pickleStep.id === testStep.pickleStepId\n )\n const testStepResult = await this.runStep(pickleStep, testStep)\n didWeRunStepsYet = true\n return testStepResult\n }\n })\n }\n\n const willBeRetried =\n this.getWorstStepResult().status ===\n messages.TestStepResultStatus.FAILED && moreAttemptsRemaining\n const testCaseFinished: messages.Envelope = {\n testCaseFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n timestamp: this.stopwatch.timestamp(),\n willBeRetried,\n },\n }\n this.eventBroadcaster.emit('envelope', testCaseFinished)\n\n return willBeRetried\n }\n\n async runHook(\n hookDefinition: TestCaseHookDefinition,\n hookParameter: ITestCaseHookParameter,\n isBeforeHook: boolean\n ): Promise<messages.TestStepResult> {\n if (this.shouldSkipHook(isBeforeHook)) {\n return {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n return await this.invokeStep(null, hookDefinition, hookParameter)\n }\n\n async runStepHooks(\n stepHooks: TestStepHookDefinition[],\n pickleStep: messages.PickleStep,\n stepResult?: messages.TestStepResult\n ): Promise<messages.TestStepResult[]> {\n const stepHooksResult = []\n const hookParameter: ITestStepHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n pickleStep,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n result: stepResult,\n }\n for (const stepHookDefinition of stepHooks) {\n stepHooksResult.push(\n await this.invokeStep(null, stepHookDefinition, hookParameter)\n )\n }\n return stepHooksResult\n }\n\n async runStep(\n pickleStep: messages.PickleStep,\n testStep: messages.TestStep\n ): Promise<messages.TestStepResult> {\n const stepDefinitions = testStep.stepDefinitionIds.map(\n (stepDefinitionId) => {\n return findStepDefinition(stepDefinitionId, this.supportCodeLibrary)\n }\n )\n if (stepDefinitions.length === 0) {\n return {\n status: messages.TestStepResultStatus.UNDEFINED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n } else if (stepDefinitions.length > 1) {\n return {\n message: getAmbiguousStepException(stepDefinitions),\n status: messages.TestStepResultStatus.AMBIGUOUS,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n } else if (this.isSkippingSteps()) {\n return {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n\n let stepResult\n let stepResults = await this.runStepHooks(\n this.getBeforeStepHookDefinitions(),\n pickleStep\n )\n if (\n getWorstTestStepResult(stepResults).status !==\n messages.TestStepResultStatus.FAILED\n ) {\n stepResult = await this.invokeStep(pickleStep, stepDefinitions[0])\n stepResults.push(stepResult)\n }\n const afterStepHookResults = await this.runStepHooks(\n this.getAfterStepHookDefinitions(),\n pickleStep,\n stepResult\n )\n stepResults = stepResults.concat(afterStepHookResults)\n\n const finalStepResult = getWorstTestStepResult(stepResults)\n let finalDuration = messages.TimeConversion.millisecondsToDuration(0)\n for (const result of stepResults) {\n finalDuration = messages.TimeConversion.addDurations(\n finalDuration,\n result.duration\n )\n }\n finalStepResult.duration = finalDuration\n return finalStepResult\n }\n}\n\nfunction findHookDefinition(\n id: string,\n supportCodeLibrary: ISupportCodeLibrary\n): TestCaseHookDefinition {\n return [\n ...supportCodeLibrary.beforeTestCaseHookDefinitions,\n ...supportCodeLibrary.afterTestCaseHookDefinitions,\n ].find((definition) => definition.id === id)\n}\n\nfunction findStepDefinition(\n id: string,\n supportCodeLibrary: ISupportCodeLibrary\n): StepDefinition {\n return supportCodeLibrary.stepDefinitions.find(\n (definition) => definition.id === id\n )\n}\n"]}
1
+ {"version":3,"file":"test_case_runner.js","sourceRoot":"","sources":["../../src/runtime/test_case_runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAqD;AACrD,8EAAoD;AACpD,gEAAsC;AACtC,6DAA8C;AAC9C,iDAAwE;AAUxE,oDAAkE;AAGlE,6FAAmE;AACnE,iGAAsE;AAgBtE,MAAqB,cAAc;IAmBjC,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,KAAK,EACL,MAAM,EACN,QAAQ,EACR,OAAO,GAAG,CAAC,EACX,IAAI,EACJ,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GACW;QAC1B,IAAI,CAAC,iBAAiB,GAAG,IAAI,4BAAiB,CAC5C,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;YAC5B,IAAI,IAAA,gCAAgB,EAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;gBAC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M,CAAC,oBAAoB,CAAC,CAAA;QAEtD,MAAM,eAAe,GAAG,IAAA,iCAAsB,EAAC,WAAW,CAAC,CAAA;QAC3D,IAAI,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAA;QACrE,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE;YAChC,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,YAAY,CAClD,aAAa,EACb,MAAM,CAAC,QAAQ,CAChB,CAAA;SACF;QACD,eAAe,CAAC,QAAQ,GAAG,aAAa,CAAA;QACxC,OAAO,eAAe,CAAA;IACxB,CAAC;CACF;AAhVD,iCAgVC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAuC;IAEvC,OAAO;QACL,GAAG,kBAAkB,CAAC,6BAA6B;QACnD,GAAG,kBAAkB,CAAC,4BAA4B;KACnD,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAuC;IAEvC,OAAO,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAC5C,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CACrC,CAAA;AACH,CAAC","sourcesContent":["import { getAmbiguousStepException } from './helpers'\nimport AttachmentManager from './attachment_manager'\nimport StepRunner from './step_runner'\nimport * as messages from '@cucumber/messages'\nimport { getWorstTestStepResult, IdGenerator } from '@cucumber/messages'\nimport { EventEmitter } from 'events'\nimport {\n ISupportCodeLibrary,\n ITestCaseHookParameter,\n ITestStepHookParameter,\n} from '../support_code_library_builder/types'\nimport TestCaseHookDefinition from '../models/test_case_hook_definition'\nimport TestStepHookDefinition from '../models/test_step_hook_definition'\nimport { IDefinition } from '../models/definition'\nimport { doesHaveValue, doesNotHaveValue } from '../value_checker'\nimport { IStopwatch } from './stopwatch'\nimport StepDefinition from '../models/step_definition'\nimport ReportGenerator from '../formatter/helpers/report_generator'\nimport BVTAnalysisFormatter from '../formatter/bvt_analysis_formatter'\n\nexport interface INewTestCaseRunnerOptions {\n eventBroadcaster: EventEmitter\n stopwatch: IStopwatch\n gherkinDocument: messages.GherkinDocument\n newId: IdGenerator.NewId\n pickle: messages.Pickle\n testCase: messages.TestCase\n retries: number\n skip: boolean\n filterStackTraces: boolean\n supportCodeLibrary: ISupportCodeLibrary\n worldParameters: any\n}\n\nexport default class TestCaseRunner {\n private readonly attachmentManager: AttachmentManager\n private currentTestCaseStartedId: string\n private currentTestStepId: string\n private readonly eventBroadcaster: EventEmitter\n private readonly stopwatch: IStopwatch\n private readonly gherkinDocument: messages.GherkinDocument\n private readonly newId: IdGenerator.NewId\n private readonly pickle: messages.Pickle\n private readonly testCase: messages.TestCase\n private readonly maxAttempts: number\n private readonly skip: boolean\n private readonly filterStackTraces: boolean\n private readonly supportCodeLibrary: ISupportCodeLibrary\n private testStepResults: messages.TestStepResult[]\n private world: any\n private readonly worldParameters: any\n private reportGenerator: ReportGenerator\n\n constructor({\n eventBroadcaster,\n stopwatch,\n gherkinDocument,\n newId,\n pickle,\n testCase,\n retries = 0,\n skip,\n filterStackTraces,\n supportCodeLibrary,\n worldParameters,\n }: INewTestCaseRunnerOptions) {\n this.attachmentManager = new AttachmentManager(\n ({ data, media, fileName }) => {\n if (doesNotHaveValue(this.currentTestStepId)) {\n throw new Error(\n 'Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish.'\n )\n }\n const attachment: messages.Envelope = {\n attachment: {\n body: data,\n contentEncoding: media.encoding,\n mediaType: media.contentType,\n fileName,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n },\n }\n this.eventBroadcaster.emit('envelope', attachment)\n }\n )\n this.eventBroadcaster = eventBroadcaster\n this.stopwatch = stopwatch\n this.gherkinDocument = gherkinDocument\n this.maxAttempts = 1 + (skip ? 0 : retries)\n this.newId = newId\n this.pickle = pickle\n this.testCase = testCase\n this.skip = skip\n this.filterStackTraces = filterStackTraces\n this.supportCodeLibrary = supportCodeLibrary\n this.worldParameters = worldParameters\n this.resetTestProgressData()\n this.reportGenerator = new ReportGenerator()\n }\n\n resetTestProgressData(): void {\n this.world = new this.supportCodeLibrary.World({\n attach: this.attachmentManager.create.bind(this.attachmentManager),\n log: this.attachmentManager.log.bind(this.attachmentManager),\n parameters: this.worldParameters,\n })\n this.testStepResults = []\n }\n\n getBeforeStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.beforeTestStepHookDefinitions.filter(\n (hookDefinition) => hookDefinition.appliesToTestCase(this.pickle)\n )\n }\n\n getAfterStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.afterTestStepHookDefinitions\n .slice(0)\n .reverse()\n .filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle))\n }\n\n getWorstStepResult(): messages.TestStepResult {\n if (this.testStepResults.length === 0) {\n return {\n status: this.skip\n ? messages.TestStepResultStatus.SKIPPED\n : messages.TestStepResultStatus.PASSED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n return getWorstTestStepResult(this.testStepResults)\n }\n\n async invokeStep(\n step: messages.PickleStep,\n stepDefinition: IDefinition,\n hookParameter?: any\n ): Promise<messages.TestStepResult> {\n return await StepRunner.run({\n defaultTimeout: this.supportCodeLibrary.defaultTimeout,\n filterStackTraces: this.filterStackTraces,\n hookParameter,\n step,\n stepDefinition,\n world: this.world,\n })\n }\n\n isSkippingSteps(): boolean {\n return (\n this.getWorstStepResult().status !== messages.TestStepResultStatus.PASSED\n )\n }\n\n shouldSkipHook(isBeforeHook: boolean): boolean {\n return this.skip || (this.isSkippingSteps() && isBeforeHook)\n }\n\n async aroundTestStep(\n testStepId: string,\n runStepFn: () => Promise<messages.TestStepResult>\n ): Promise<void> {\n const testStepStarted: messages.Envelope = {\n testStepStarted: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepStarted)\n this.currentTestStepId = testStepId\n const testStepResult = await runStepFn()\n this.currentTestStepId = null\n this.testStepResults.push(testStepResult)\n const testStepFinished: messages.Envelope = {\n testStepFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n testStepResult,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepFinished)\n }\n\n async run(): Promise<messages.TestStepResultStatus> {\n for (let attempt = 0; attempt < this.maxAttempts; attempt++) {\n const moreAttemptsRemaining = attempt + 1 < this.maxAttempts\n\n const willBeRetried = await this.runAttempt(\n attempt,\n moreAttemptsRemaining\n )\n\n if (!willBeRetried) {\n break\n }\n this.resetTestProgressData()\n }\n return this.getWorstStepResult().status\n }\n\n async runAttempt(\n attempt: number,\n moreAttemptsRemaining: boolean\n ): Promise<boolean> {\n this.currentTestCaseStartedId = this.newId()\n const testCaseStarted: messages.Envelope = {\n testCaseStarted: {\n attempt,\n testCaseId: this.testCase.id,\n id: this.currentTestCaseStartedId,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testCaseStarted)\n // used to determine whether a hook is a Before or After\n let didWeRunStepsYet = false\n for (const testStep of this.testCase.testSteps) {\n await this.aroundTestStep(testStep.id, async () => {\n if (doesHaveValue(testStep.hookId)) {\n const hookParameter: ITestCaseHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n testCaseStartedId: this.currentTestCaseStartedId,\n }\n if (didWeRunStepsYet) {\n hookParameter.result = this.getWorstStepResult()\n hookParameter.willBeRetried =\n this.getWorstStepResult().status ===\n messages.TestStepResultStatus.FAILED && moreAttemptsRemaining\n }\n return await this.runHook(\n findHookDefinition(testStep.hookId, this.supportCodeLibrary),\n hookParameter,\n !didWeRunStepsYet\n )\n } else {\n const pickleStep = this.pickle.steps.find(\n (pickleStep) => pickleStep.id === testStep.pickleStepId\n )\n const testStepResult = await this.runStep(pickleStep, testStep)\n didWeRunStepsYet = true\n return testStepResult\n }\n })\n }\n\n const willBeRetried =\n this.getWorstStepResult().status ===\n messages.TestStepResultStatus.FAILED && moreAttemptsRemaining\n const testCaseFinished: messages.Envelope = {\n testCaseFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n timestamp: this.stopwatch.timestamp(),\n willBeRetried,\n },\n }\n\n const rerunId = BVTAnalysisFormatter.reRunFailedStepsIndex\n ? BVTAnalysisFormatter.reRunFailedStepsIndex[0].testCaseId\n : null\n\n const data = BVTAnalysisFormatter.reportGenerator\n ? await BVTAnalysisFormatter.reportGenerator.handleMessage(\n testCaseFinished,\n rerunId\n )\n : null\n\n this.eventBroadcaster.emit('envelope', testCaseFinished, data)\n\n return willBeRetried\n }\n\n async runHook(\n hookDefinition: TestCaseHookDefinition,\n hookParameter: ITestCaseHookParameter,\n isBeforeHook: boolean\n ): Promise<messages.TestStepResult> {\n if (this.shouldSkipHook(isBeforeHook)) {\n return {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n return await this.invokeStep(null, hookDefinition, hookParameter)\n }\n\n async runStepHooks(\n stepHooks: TestStepHookDefinition[],\n pickleStep: messages.PickleStep,\n stepResult?: messages.TestStepResult\n ): Promise<messages.TestStepResult[]> {\n const stepHooksResult = []\n const hookParameter: ITestStepHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n pickleStep,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n result: stepResult,\n }\n for (const stepHookDefinition of stepHooks) {\n stepHooksResult.push(\n await this.invokeStep(null, stepHookDefinition, hookParameter)\n )\n }\n return stepHooksResult\n }\n\n async runStep(\n pickleStep: messages.PickleStep,\n testStep: messages.TestStep\n ): Promise<messages.TestStepResult> {\n const stepDefinitions = testStep.stepDefinitionIds.map(\n (stepDefinitionId) => {\n return findStepDefinition(stepDefinitionId, this.supportCodeLibrary)\n }\n )\n if (stepDefinitions.length === 0) {\n return {\n status: messages.TestStepResultStatus.UNDEFINED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n } else if (stepDefinitions.length > 1) {\n return {\n message: getAmbiguousStepException(stepDefinitions),\n status: messages.TestStepResultStatus.AMBIGUOUS,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n } else if (this.isSkippingSteps()) {\n return {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n\n let stepResult\n let stepResults = await this.runStepHooks(\n this.getBeforeStepHookDefinitions(),\n pickleStep\n )\n if (\n getWorstTestStepResult(stepResults).status !==\n messages.TestStepResultStatus.FAILED\n ) {\n stepResult = await this.invokeStep(pickleStep, stepDefinitions[0])\n stepResults.push(stepResult)\n }\n const afterStepHookResults = await this.runStepHooks(\n this.getAfterStepHookDefinitions(),\n pickleStep,\n stepResult\n )\n stepResults = stepResults.concat(afterStepHookResults)\n\n const finalStepResult = getWorstTestStepResult(stepResults)\n let finalDuration = messages.TimeConversion.millisecondsToDuration(0)\n for (const result of stepResults) {\n finalDuration = messages.TimeConversion.addDurations(\n finalDuration,\n result.duration\n )\n }\n finalStepResult.duration = finalDuration\n return finalStepResult\n }\n}\n\nfunction findHookDefinition(\n id: string,\n supportCodeLibrary: ISupportCodeLibrary\n): TestCaseHookDefinition {\n return [\n ...supportCodeLibrary.beforeTestCaseHookDefinitions,\n ...supportCodeLibrary.afterTestCaseHookDefinitions,\n ].find((definition) => definition.id === id)\n}\n\nfunction findStepDefinition(\n id: string,\n supportCodeLibrary: ISupportCodeLibrary\n): StepDefinition {\n return supportCodeLibrary.stepDefinitions.find(\n (definition) => definition.id === id\n )\n}\n"]}
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.0.96";
1
+ export declare const version = "1.0.97";
package/lib/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // Generated by genversion.
5
- exports.version = '1.0.96';
5
+ exports.version = '1.0.97';
6
6
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AACd,QAAA,OAAO,GAAG,QAAQ,CAAA","sourcesContent":["// Generated by genversion.\nexport const version = '1.0.96'\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AACd,QAAA,OAAO,GAAG,QAAQ,CAAA","sourcesContent":["// Generated by genversion.\nexport const version = '1.0.97'\n"]}
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "gherkin",
9
9
  "tests"
10
10
  ],
11
- "version": "1.0.96",
11
+ "version": "1.0.97",
12
12
  "homepage": "https://github.com/blinq-io/cucumber-js",
13
13
  "author": "blinq.io",
14
14
  "contributors": [