@dev-blinq/cucumber-js 1.0.90-dev → 1.0.90-main

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.
@@ -2,9 +2,22 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
+ var _a, _b;
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
7
  const fs_1 = __importDefault(require("fs"));
7
8
  const path_1 = __importDefault(require("path"));
9
+ const upload_serivce_1 = require("./upload_serivce");
10
+ const URL = process.env.NODE_ENV_BLINQ === 'dev'
11
+ ? 'https://dev.api.blinq.io/api/runs'
12
+ : process.env.NODE_ENV_BLINQ === 'local'
13
+ ? 'http://localhost:5001/api/runs'
14
+ : process.env.NODE_ENV_BLINQ === 'stage'
15
+ ? 'https://stage.api.blinq.io/api/runs'
16
+ : 'https://api.blinq.io/api/runs';
17
+ const REPORT_SERVICE_URL = (_a = process.env.REPORT_SERVICE_URL) !== null && _a !== void 0 ? _a : URL;
18
+ const BATCH_SIZE = 10;
19
+ const MAX_RETRIES = 3;
20
+ const REPORT_SERVICE_TOKEN = (_b = process.env.TOKEN) !== null && _b !== void 0 ? _b : process.env.REPORT_SERVICE_TOKEN;
8
21
  class ReportGenerator {
9
22
  constructor() {
10
23
  this.report = {
@@ -27,9 +40,14 @@ class ReportGenerator {
27
40
  this.scenarioIterationCountMap = new Map();
28
41
  this.logs = [];
29
42
  this.networkLog = [];
43
+ this.runName = '';
30
44
  this.reportFolder = null;
45
+ this.uploadService = new upload_serivce_1.RunUploadService(REPORT_SERVICE_URL, REPORT_SERVICE_TOKEN);
31
46
  }
32
- handleMessage(envelope) {
47
+ async handleMessage(envelope) {
48
+ if (envelope.meta && envelope.meta.runName) {
49
+ this.runName = envelope.meta.runName;
50
+ }
33
51
  const type = Object.keys(envelope)[0];
34
52
  switch (type) {
35
53
  // case "meta": { break}
@@ -83,7 +101,7 @@ class ReportGenerator {
83
101
  }
84
102
  case 'testCaseFinished': {
85
103
  const testCaseFinished = envelope[type];
86
- this.onTestCaseFinished(testCaseFinished);
104
+ await this.onTestCaseFinished(testCaseFinished);
87
105
  break;
88
106
  }
89
107
  // case "hook": { break} // After Hook
@@ -236,6 +254,10 @@ class ReportGenerator {
236
254
  },
237
255
  webLog: [],
238
256
  networkLog: [],
257
+ env: {
258
+ name: this.report.env.name,
259
+ baseUrl: this.report.env.baseUrl,
260
+ },
239
261
  });
240
262
  this.report.testCases.push(this.testCaseReportMap.get(id));
241
263
  }
@@ -261,6 +283,10 @@ class ReportGenerator {
261
283
  if (mediaType === 'application/json+env') {
262
284
  const data = JSON.parse(body);
263
285
  this.report.env = data;
286
+ this.report.testCases.map((testCase) => {
287
+ testCase.env = data;
288
+ return testCase;
289
+ });
264
290
  }
265
291
  if (mediaType === 'application/json+log') {
266
292
  const log = JSON.parse(body);
@@ -362,7 +388,7 @@ class ReportGenerator {
362
388
  status: 'PASSED',
363
389
  };
364
390
  }
365
- onTestCaseFinished(testCaseFinished) {
391
+ async onTestCaseFinished(testCaseFinished) {
366
392
  const { testCaseStartedId, timestamp } = testCaseFinished;
367
393
  const testProgress = this.testCaseReportMap.get(testCaseStartedId);
368
394
  const prevResult = testProgress.result;
@@ -377,6 +403,40 @@ class ReportGenerator {
377
403
  testProgress.networkLog = this.networkLog;
378
404
  this.networkLog = [];
379
405
  this.logs = [];
406
+ await this.uploadTestCase(testProgress);
407
+ }
408
+ async uploadTestCase(testCase) {
409
+ let runId = '';
410
+ let projectId = '';
411
+ if (!process.env.UPLOADING_TEST_CASE) {
412
+ process.env.UPLOADING_TEST_CASE = '[]';
413
+ }
414
+ const anyRemArr = JSON.parse(process.env.UPLOADING_TEST_CASE);
415
+ const randomID = Math.random().toString(36).substring(7);
416
+ anyRemArr.push(randomID);
417
+ process.env.UPLOADING_TEST_CASE = JSON.stringify(anyRemArr);
418
+ try {
419
+ if (process.env.RUN_ID && process.env.PROJECT_ID) {
420
+ runId = process.env.RUN_ID;
421
+ projectId = process.env.PROJECT_ID;
422
+ }
423
+ else {
424
+ const runDoc = await this.uploadService.createRunDocument(this.runName);
425
+ runId = runDoc._id;
426
+ projectId = runDoc.project_id;
427
+ process.env.RUN_ID = runId;
428
+ process.env.PROJECT_ID = projectId;
429
+ }
430
+ await this.uploadService.uploadTestCase(testCase, runId, projectId, this.reportFolder);
431
+ }
432
+ catch (e) {
433
+ console.error('Error uploading test case:', e);
434
+ }
435
+ finally {
436
+ const arrRem = JSON.parse(process.env.UPLOADING_TEST_CASE);
437
+ arrRem.splice(arrRem.indexOf(randomID), 1);
438
+ process.env.UPLOADING_TEST_CASE = JSON.stringify(arrRem);
439
+ }
380
440
  }
381
441
  onTestRunFinished(testRunFinished) {
382
442
  const { timestamp, success, message } = testRunFinished;
@@ -1 +1 @@
1
- {"version":3,"file":"report_generator.js","sourceRoot":"","sources":["../../../src/formatter/helpers/report_generator.ts"],"names":[],"mappings":";;;;;AACA,4CAAmB;AACnB,gDAAuB;AAkHvB,MAAqB,eAAe;IAApC;QACU,WAAM,GAAe;YAC3B,MAAM,EAAE;gBACN,MAAM,EAAE,SAAS;aAClB;YACD,SAAS,EAAE,EAAwB;YACnC,GAAG,EAAE;gBACH,IAAI,EAAE,EAAE;gBACR,OAAO,EAAE,EAAE;aACZ;SACF,CAAA;QACO,uBAAkB,GAAG,IAAI,GAAG,EAAoC,CAAA;QAChE,YAAO,GAAG,IAAI,GAAG,EAAyB,CAAA;QAC1C,cAAS,GAAG,IAAI,GAAG,EAA2B,CAAA;QAC9C,gBAAW,GAAG,IAAI,GAAG,EAA6B,CAAA;QAClD,gBAAW,GAAG,IAAI,GAAG,EAA6B,CAAA;QAClD,kBAAa,GAAG,IAAI,GAAG,EAAoB,CAAA;QAC3C,sBAAiB,GAAG,IAAI,GAAG,EAA4B,CAAA;QACvD,8BAAyB,GAAG,IAAI,GAAG,EAAkB,CAAA;QACrD,SAAI,GAAa,EAAE,CAAA;QACn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GAAG,EAAE,CAAA;IAChB,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;AAlZD,kCAkZC","sourcesContent":["import * as messages from '@cucumber/messages'\nimport fs from 'fs'\nimport path from 'path'\n// type JsonException = messages.Exception\ntype JsonTimestamp = number //messages.Timestamp\ntype JsonStepType = 'Unknown' | 'Context' | 'Action' | 'Outcome' | 'Conjunction'\n\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 webLog?: webLog[]\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 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}\n\nexport type JsonReport = {\n testCases: JsonTestProgress[]\n result: JsonReportResult\n env: {\n name: string\n baseUrl: string\n }\n}\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 reportFolder: null | string = null\n\n handleMessage(envelope: messages.Envelope) {\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 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 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 })\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 })\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 }\n if (mediaType === 'application/json+log') {\n const log: webLog = JSON.parse(body)\n if (this.logs.length < 1000) this.logs.push(log)\n }\n if (mediaType === 'application/json+network') {\n const networkLog = JSON.parse(body)\n if (this.networkLog.length < 1000) this.networkLog.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 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 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 stepProgess.result = {\n status: testStepResult.status,\n startTime: prevStepResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n message: testStepResult.message,\n // exception: testStepResult.exception,\n }\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 onTestCaseFinished(testCaseFinished: messages.TestCaseFinished) {\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 }\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":";;;;;;AACA,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,CAAC,qCAAqC;YACvC,CAAC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vE,KAAK,GAAG,MAAM,CAAC,GAAG,CAAA;gBAClB,SAAS,GAAG,MAAM,CAAC,UAAU,CAAA;gBAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,KAAK,CAAA;gBAC1B,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,SAAS,CAAA;aACnC;YACD,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CACrC,QAAQ,EACR,KAAK,EACL,SAAS,EACT,IAAI,CAAC,YAAY,CAClB,CAAA;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,CAAC,CAAC,CAAA;SAC/C;gBAAS;YACR,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAa,CAAA;YACtE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;YAC1C,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;SACzD;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;AAzcD,kCAycC","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 webLog?: webLog[]\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 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 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 })\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) this.logs.push(log)\n }\n if (mediaType === 'application/json+network') {\n const networkLog = JSON.parse(body)\n if (this.networkLog.length < 1000) this.networkLog.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 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 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 stepProgess.result = {\n status: testStepResult.status,\n startTime: prevStepResult.startTime,\n endTime: this.getTimeStamp(timestamp),\n message: testStepResult.message,\n // exception: testStepResult.exception,\n }\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 (process.env.RUN_ID && process.env.PROJECT_ID) {\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 process.env.RUN_ID = runId\n process.env.PROJECT_ID = projectId\n }\n await this.uploadService.uploadTestCase(\n testCase,\n runId,\n projectId,\n this.reportFolder\n )\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 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,4 +1,5 @@
1
1
  import FormData from 'form-data';
2
+ import { JsonTestProgress } from './report_generator';
2
3
  declare class RunUploadService {
3
4
  private runsApiBaseURL;
4
5
  private accessToken;
@@ -6,7 +7,9 @@ declare class RunUploadService {
6
7
  createRunDocument(name: string): Promise<any>;
7
8
  upload(formData: FormData): Promise<void>;
8
9
  getPreSignedUrls(fileUris: string[], runId: string): Promise<any>;
10
+ uploadTestCase(testCaseReport: JsonTestProgress, runId: string, projectId: string, reportFolder: string): Promise<void>;
9
11
  uploadFile(filePath: string, preSignedUrl: string): Promise<boolean>;
10
12
  uploadComplete(runId: string, projectId: string): Promise<void>;
13
+ modifyTestCase(runId: string, projectId: string, testProgressReport: JsonTestProgress): Promise<void>;
11
14
  }
12
15
  export { RunUploadService };
@@ -2,36 +2,48 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
+ var _a, _b;
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
7
  exports.RunUploadService = void 0;
7
8
  const fs_1 = require("fs");
8
9
  const promises_1 = __importDefault(require("fs/promises"));
9
10
  const axios_client_1 = require("../../configuration/axios_client");
11
+ const path_1 = __importDefault(require("path"));
12
+ const bvt_analysis_formatter_1 = require("../bvt_analysis_formatter");
13
+ const REPORT_SERVICE_URL = (_a = process.env.REPORT_SERVICE_URL) !== null && _a !== void 0 ? _a : URL;
14
+ const BATCH_SIZE = 10;
15
+ const MAX_RETRIES = 3;
16
+ const REPORT_SERVICE_TOKEN = (_b = process.env.TOKEN) !== null && _b !== void 0 ? _b : process.env.REPORT_SERVICE_TOKEN;
10
17
  class RunUploadService {
11
18
  constructor(runsApiBaseURL, accessToken) {
12
19
  this.runsApiBaseURL = runsApiBaseURL;
13
20
  this.accessToken = accessToken;
14
21
  }
15
22
  async createRunDocument(name) {
16
- const runDocResult = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/create', {
17
- name: name ? name : 'TEST',
18
- }, {
19
- headers: {
20
- Authorization: 'Bearer ' + this.accessToken,
21
- 'x-source': 'cucumber_js',
22
- },
23
- });
24
- if (runDocResult.status === 403) {
25
- console.log('Warning: Your trial plan has ended. Cannot create or upload reports');
26
- throw new Error('Warning: Your trial plan has ended. Cannot create or upload reports');
27
- }
28
- if (runDocResult.status !== 200) {
29
- throw new Error('Failed to create run document in the server');
23
+ try {
24
+ const runDocResult = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/create', {
25
+ name: name ? name : 'TEST',
26
+ }, {
27
+ headers: {
28
+ Authorization: 'Bearer ' + this.accessToken,
29
+ 'x-source': 'cucumber_js',
30
+ },
31
+ });
32
+ if (runDocResult.status !== 200) {
33
+ throw new Error('Failed to create run document in the server');
34
+ }
35
+ if (runDocResult.data.status !== true) {
36
+ throw new Error('Failed to create run document in the server');
37
+ }
38
+ return runDocResult.data.run;
30
39
  }
31
- if (runDocResult.data.status !== true) {
32
- throw new Error('Failed to create run document in the server');
40
+ catch (error) {
41
+ if (error.response && error.response.status === 403) {
42
+ console.log('Warning: Your trial plan has ended. Cannot create or upload reports.');
43
+ process.exit(1);
44
+ }
45
+ throw new Error('Failed to create run document in the server: ' + error);
33
46
  }
34
- return runDocResult.data.run;
35
47
  }
36
48
  async upload(formData) {
37
49
  const response = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/upload', formData, {
@@ -74,6 +86,51 @@ class RunUploadService {
74
86
  }
75
87
  return response.data.uploadUrls;
76
88
  }
89
+ async uploadTestCase(testCaseReport, runId, projectId, reportFolder) {
90
+ const fileUris = [];
91
+ //iterate over all the files in the JsonCommand.screenshotId and insert them into the fileUris array
92
+ for (const step of testCaseReport.steps) {
93
+ for (const command of step.commands) {
94
+ if (command.screenshotId) {
95
+ fileUris.push('screenshots' + '/' + String(command.screenshotId) + '.png');
96
+ }
97
+ }
98
+ }
99
+ const preSignedUrls = await this.getPreSignedUrls(fileUris, runId);
100
+ //upload all the files in the fileUris array
101
+ try {
102
+ for (let i = 0; i < fileUris.length; i += BATCH_SIZE) {
103
+ const batch = fileUris.slice(i, Math.min(i + BATCH_SIZE, fileUris.length));
104
+ await Promise.all(batch
105
+ .filter((fileUri) => preSignedUrls[fileUri])
106
+ .map(async (fileUri) => {
107
+ for (let j = 0; j < MAX_RETRIES; j++) {
108
+ if ((0, fs_1.existsSync)(path_1.default.join(reportFolder, fileUri))) {
109
+ const success = await this.uploadFile(path_1.default.join(reportFolder, fileUri), preSignedUrls[fileUri]);
110
+ if (success) {
111
+ return;
112
+ }
113
+ }
114
+ }
115
+ console.error('Failed to upload file:', fileUri);
116
+ }));
117
+ }
118
+ await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/createNewTestCase', {
119
+ runId,
120
+ projectId,
121
+ testProgressReport: testCaseReport,
122
+ }, {
123
+ headers: {
124
+ Authorization: 'Bearer ' + this.accessToken,
125
+ 'x-source': 'cucumber_js',
126
+ },
127
+ });
128
+ (0, bvt_analysis_formatter_1.logReportLink)(runId, projectId);
129
+ }
130
+ catch (e) {
131
+ console.error(`failed to upload the test case: ${testCaseReport.id} ${e}`);
132
+ }
133
+ }
77
134
  async uploadFile(filePath, preSignedUrl) {
78
135
  const fileStream = (0, fs_1.createReadStream)(filePath);
79
136
  let success = true;
@@ -115,6 +172,30 @@ class RunUploadService {
115
172
  throw new Error('Failed to mark run as complete');
116
173
  }
117
174
  }
175
+ async modifyTestCase(runId, projectId, testProgressReport) {
176
+ try {
177
+ const res = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/modifyTestCase', {
178
+ runId,
179
+ projectId,
180
+ testProgressReport,
181
+ }, {
182
+ headers: {
183
+ Authorization: 'Bearer ' + this.accessToken,
184
+ 'x-source': 'cucumber_js',
185
+ },
186
+ });
187
+ if (res.status !== 200) {
188
+ throw new Error('');
189
+ }
190
+ if (res.data.status !== true) {
191
+ throw new Error('');
192
+ }
193
+ (0, bvt_analysis_formatter_1.logReportLink)(runId, projectId);
194
+ }
195
+ catch (e) {
196
+ console.error(`failed to modify the test case: ${testProgressReport.id} ${e}`);
197
+ }
198
+ }
118
199
  }
119
200
  exports.RunUploadService = RunUploadService;
120
201
  //# sourceMappingURL=upload_serivce.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload_serivce.js","sourceRoot":"","sources":["../../../src/formatter/helpers/upload_serivce.ts"],"names":[],"mappings":";;;;;;AAEA,2BAAqC;AACrC,2DAA4B;AAE5B,mEAA8D;AAE9D,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,MAAM,YAAY,GAAG,MAAM,0BAAW,CAAC,IAAI,CACzC,IAAI,CAAC,cAAc,GAAG,uBAAuB,EAC7C;YACE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM;SAC3B,EACD;YACE,OAAO,EAAE;gBACP,aAAa,EAAE,SAAS,GAAG,IAAI,CAAC,WAAW;gBAC3C,UAAU,EAAE,aAAa;aAC1B;SACF,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C,CAAA;aAC9C;YACD,OAAO,GAAG,KAAK,CAAA;SAChB;gBAAS;YACR,UAAU,CAAC,KAAK,EAAE,CAAA;SACnB;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IACD,KAAK,CAAC,cAAc,CAAC,KAAa,EAAE,SAAiB;QACnD,MAAM,QAAQ,GAAG,MAAM,0BAAW,CAAC,IAAI,CACrC,IAAI,CAAC,cAAc,GAAG,iCAAiC,EACvD;YACE,KAAK;YACL,SAAS;SACV,EACD;YACE,OAAO,EAAE;gBACP,aAAa,EAAE,SAAS,GAAG,IAAI,CAAC,WAAW;gBAC3C,UAAU,EAAE,aAAa;aAC1B;SACF,CACF,CAAA;QACD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;SAClD;QACD,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;SAClD;IACH,CAAC;CACF;AAEQ,4CAAgB","sourcesContent":["/* eslint-disable no-console */\nimport FormData from 'form-data'\nimport { createReadStream } from 'fs'\nimport fs from 'fs/promises'\nimport { JsonReport } from './report_generator'\nimport { axiosClient } from '../../configuration/axios_client'\n\nclass RunUploadService {\n constructor(private runsApiBaseURL: string, private accessToken: string) {}\n async createRunDocument(name: string) {\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 === 403) {\n console.log('Warning: Your trial plan has ended. Cannot create or upload reports');\n throw new Error('Warning: Your trial plan has ended. Cannot create or upload reports');\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 }\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('Warning: Your trial plan has ended. Cannot upload reports and perform retraining');\n throw new Error('Warning: Your trial plan has ended. Cannot upload reports and perform retraining')\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('Warning: Your trial plan has ended. Cannot upload reports and perform retraining');\n throw new Error('Warning: Your trial plan has ended. Cannot upload reports and perform retraining')\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 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 },\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}\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;AAEzD,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,YAAY,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE;gBACrC,MAAM,IAAI,KAAK,CAAC,6CAA6C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B,EACjB,kBAAoC;QAEpC,IAAI;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'\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 },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\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 },\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 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,4 +1,4 @@
1
- import ReportGenerator, { JsonReport } from './report_generator';
1
+ import ReportGenerator, { JsonReport, JsonTestProgress } from './report_generator';
2
2
  export default class ReportUploader {
3
3
  private uploadService;
4
4
  private reportGenerator;
@@ -7,5 +7,6 @@ export default class ReportUploader {
7
7
  runId: any;
8
8
  projectId: any;
9
9
  }>;
10
+ modifyTestCase(testCase: JsonTestProgress): Promise<void>;
10
11
  createZip(reportFolder: string | null, report: JsonReport): Promise<string>;
11
12
  }
@@ -32,11 +32,20 @@ const form_data_1 = __importDefault(require("form-data"));
32
32
  const fs_1 = __importStar(require("fs"));
33
33
  const jszip_1 = __importDefault(require("jszip"));
34
34
  const path_1 = __importDefault(require("path"));
35
- const URL = process.env.NODE_ENV_BLINQ === 'dev'
36
- ? 'https://dev.api.blinq.io/api/runs'
37
- : process.env.NODE_ENV_BLINQ === 'local'
38
- ? 'http://localhost:5001/api/runs'
39
- : 'https://api.blinq.io/api/runs';
35
+ let URL;
36
+ switch (process.env.NODE_ENV_BLINQ) {
37
+ case 'stage':
38
+ URL = 'https://stage.api.blinq.io/api/runs';
39
+ break;
40
+ case 'dev':
41
+ URL = 'https://dev.api.blinq.io/api/runs';
42
+ break;
43
+ case 'local':
44
+ URL = 'http://localhost:5001/api/runs';
45
+ break;
46
+ default:
47
+ URL = 'https://api.blinq.io/api/runs';
48
+ }
40
49
  const REPORT_SERVICE_URL = (_a = process.env.REPORT_SERVICE_URL) !== null && _a !== void 0 ? _a : URL;
41
50
  const BATCH_SIZE = 10;
42
51
  const MAX_RETRIES = 3;
@@ -65,8 +74,10 @@ class ReportUploader {
65
74
  }
66
75
  else {
67
76
  const fileUris = [
68
- ...getFileUrisScreenShotDir(reportFolder),
77
+ ...getFileUris(reportFolder, 'screenshots'),
78
+ ...getFileUris(reportFolder, 'trace'),
69
79
  'report.json',
80
+ 'network.json',
70
81
  ];
71
82
  try {
72
83
  const preSignedUrls = await this.uploadService.getPreSignedUrls(fileUris, runDocId);
@@ -92,6 +103,17 @@ class ReportUploader {
92
103
  }
93
104
  return { runId: runDoc._id, projectId: runDoc.project_id };
94
105
  }
106
+ async modifyTestCase(testCase) {
107
+ const runId = process.env.RUN_ID;
108
+ if (!runId) {
109
+ return;
110
+ }
111
+ const projectId = process.env.PROJECT_ID;
112
+ if (!projectId) {
113
+ return;
114
+ }
115
+ await this.uploadService.modifyTestCase(runId, projectId, testCase);
116
+ }
95
117
  async createZip(reportFolder, report) {
96
118
  if (reportFolder === null) {
97
119
  console.error('report folder is empty');
@@ -108,7 +130,7 @@ class ReportUploader {
108
130
  const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' });
109
131
  // save zip file
110
132
  const zipPath = path_1.default.join(reportFolder, 'report.zip');
111
- fs_1.default.writeFileSync(zipPath, zipBuffer);
133
+ fs_1.default.writeFileSync(zipPath, new Uint8Array(zipBuffer));
112
134
  fs_1.default.writeFileSync(path_1.default.join(reportFolder, 'report.json'), JSON.stringify(report, null, 2));
113
135
  return zipPath;
114
136
  }
@@ -118,4 +140,12 @@ const getFileUrisScreenShotDir = (reportFolder) => {
118
140
  const files = fs_1.default.readdirSync(path_1.default.join(reportFolder, 'screenshots'));
119
141
  return files.map((file) => ['screenshots', file].join('/'));
120
142
  };
143
+ const getFileUris = (reportFolder, targetFolder) => {
144
+ const resultFolder = path_1.default.join(reportFolder, targetFolder);
145
+ if (!fs_1.default.existsSync(resultFolder)) {
146
+ return [];
147
+ }
148
+ const files = fs_1.default.readdirSync(resultFolder);
149
+ return files.map((file) => [targetFolder, file].join('/'));
150
+ };
121
151
  //# sourceMappingURL=uploader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uploader.js","sourceRoot":"","sources":["../../../src/formatter/helpers/uploader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAAmD;AAEnD,0DAAgC;AAChC,yCAAsC;AACtC,kDAAyB;AACzB,gDAAuB;AACvB,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,+BAA+B,CAAA;AAErC,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;AAEvD,MAAqB,cAAc;IAMjC,YAAY,eAAgC;QALpC,kBAAa,GAAG,IAAI,iCAAgB,CAC1C,kBAAkB,EAClB,oBAAoB,CACrB,CAAA;QAGC,IAAI,CAAC,kBAAkB,IAAI,CAAC,oBAAoB,EAAE;YAChD,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;SAC3E;QACD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAkB,EAAE,OAAe;QACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CA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["import ReportGenerator, { JsonReport } from './report_generator'\nimport { RunUploadService } from './upload_serivce'\n\nimport FormData from 'form-data'\nimport fs, { writeFileSync } from 'fs'\nimport JSZip from 'jszip'\nimport path from 'path'\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 : '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\n\nexport default class ReportUploader {\n private uploadService = new RunUploadService(\n REPORT_SERVICE_URL,\n REPORT_SERVICE_TOKEN\n )\n private reportGenerator: ReportGenerator\n constructor(reportGenerator: ReportGenerator) {\n if (!REPORT_SERVICE_URL || !REPORT_SERVICE_TOKEN) {\n throw new Error('REPORT_SERVICE_URL and REPORT_SERVICE_TOKEN must be set')\n }\n this.reportGenerator = reportGenerator\n }\n\n async uploadRun(report: JsonReport, runName: string) {\n const runDoc = await this.uploadService.createRunDocument(runName)\n const runDocId = runDoc._id\n const reportFolder = this.reportGenerator.reportFolder\n if (!fs.existsSync(reportFolder)) {\n fs.mkdirSync(reportFolder)\n }\n writeFileSync(\n path.join(reportFolder, 'report.json'),\n JSON.stringify(report, null, 2)\n )\n if (process.env.NODE_ENV_BLINQ === 'local') {\n const formData = new FormData()\n const zipPath = await this.createZip(reportFolder, report)\n formData.append(runDocId, fs.readFileSync(zipPath), 'report.zip')\n await this.uploadService.upload(formData)\n } else {\n const fileUris = [\n ...getFileUrisScreenShotDir(reportFolder),\n 'report.json',\n ]\n try {\n const preSignedUrls = await this.uploadService.getPreSignedUrls(\n fileUris,\n runDocId\n )\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 const success = await this.uploadService.uploadFile(\n path.join(reportFolder, fileUri),\n preSignedUrls[fileUri]\n )\n if (success) {\n return\n }\n }\n console.error('Failed to upload file:', fileUri)\n })\n )\n }\n await this.uploadService.uploadComplete(runDocId, runDoc.project_id)\n } catch (err) {\n throw new Error('Failed to upload all the files')\n }\n }\n return { runId: runDoc._id, projectId: runDoc.project_id }\n }\n async createZip(reportFolder: string | null, report: JsonReport) {\n if (reportFolder === null) {\n console.error('report folder is empty')\n console.error('it is likey that there are no scenarios to run')\n throw new Error('Empty report folder')\n }\n const zip = new JSZip()\n zip.file('report.json', JSON.stringify(report, null, 2))\n const folder = zip.folder('screenshots')\n const files = fs.readdirSync(path.join(reportFolder, 'screenshots'))\n files.forEach((file) => {\n folder.file(\n file,\n fs.readFileSync(path.join(reportFolder, 'screenshots', file))\n )\n })\n const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' })\n // save zip file\n const zipPath = path.join(reportFolder, 'report.zip')\n fs.writeFileSync(zipPath, zipBuffer)\n fs.writeFileSync(\n path.join(reportFolder, 'report.json'),\n JSON.stringify(report, null, 2)\n )\n return zipPath\n }\n}\nconst getFileUrisScreenShotDir = (reportFolder: string) => {\n const files = fs.readdirSync(path.join(reportFolder, 'screenshots'))\n\n return files.map((file) => ['screenshots', file].join('/'))\n}\n"]}
1
+ {"version":3,"file":"uploader.js","sourceRoot":"","sources":["../../../src/formatter/helpers/uploader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,qDAAmD;AAEnD,0DAAgC;AAChC,yCAAsC;AACtC,kDAAyB;AACzB,gDAAuB;AAEvB,IAAI,GAAG,CAAA;AAEP,QAAQ,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE;IAClC,KAAK,OAAO;QACV,GAAG,GAAG,qCAAqC,CAAA;Q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AAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,YAAoB,EAAE,YAAoB,EAAE,EAAE;IACjE,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;IAC1D,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;QAChC,OAAO,EAAE,CAAA;KACV;IACD,MAAM,KAAK,GAAG,YAAE,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;IAC1C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAC5D,CAAC,CAAA","sourcesContent":["import axios from 'axios'\nimport ReportGenerator, {\n JsonReport,\n JsonTestProgress,\n} from './report_generator'\nimport { RunUploadService } from './upload_serivce'\n\nimport FormData from 'form-data'\nimport fs, { writeFileSync } from 'fs'\nimport JSZip from 'jszip'\nimport path from 'path'\n\nlet URL\n\nswitch (process.env.NODE_ENV_BLINQ) {\n case 'stage':\n URL = 'https://stage.api.blinq.io/api/runs'\n break\n case 'dev':\n URL = 'https://dev.api.blinq.io/api/runs'\n break\n case 'local':\n URL = 'http://localhost:5001/api/runs'\n break\n default:\n URL = 'https://api.blinq.io/api/runs'\n}\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 default class ReportUploader {\n private uploadService = new RunUploadService(\n REPORT_SERVICE_URL,\n REPORT_SERVICE_TOKEN\n )\n private reportGenerator: ReportGenerator\n constructor(reportGenerator: ReportGenerator) {\n if (!REPORT_SERVICE_URL || !REPORT_SERVICE_TOKEN) {\n throw new Error('REPORT_SERVICE_URL and REPORT_SERVICE_TOKEN must be set')\n }\n this.reportGenerator = reportGenerator\n }\n\n async uploadRun(report: JsonReport, runName: string) {\n const runDoc = await this.uploadService.createRunDocument(runName)\n const runDocId = runDoc._id\n const reportFolder = this.reportGenerator.reportFolder\n if (!fs.existsSync(reportFolder)) {\n fs.mkdirSync(reportFolder)\n }\n writeFileSync(\n path.join(reportFolder, 'report.json'),\n JSON.stringify(report, null, 2)\n )\n if (process.env.NODE_ENV_BLINQ === 'local') {\n const formData = new FormData()\n const zipPath = await this.createZip(reportFolder, report)\n formData.append(runDocId, fs.readFileSync(zipPath), 'report.zip')\n await this.uploadService.upload(formData)\n } else {\n const fileUris = [\n ...getFileUris(reportFolder, 'screenshots'),\n ...getFileUris(reportFolder, 'trace'),\n 'report.json',\n 'network.json',\n ]\n try {\n const preSignedUrls = await this.uploadService.getPreSignedUrls(\n fileUris,\n runDocId\n )\n\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 const success = await this.uploadService.uploadFile(\n path.join(reportFolder, fileUri),\n preSignedUrls[fileUri]\n )\n if (success) {\n return\n }\n }\n console.error('Failed to upload file:', fileUri)\n })\n )\n }\n await this.uploadService.uploadComplete(runDocId, runDoc.project_id)\n } catch (err) {\n throw new Error('Failed to upload all the files')\n }\n }\n return { runId: runDoc._id, projectId: runDoc.project_id }\n }\n\n async modifyTestCase(testCase: JsonTestProgress) {\n const runId = process.env.RUN_ID\n if (!runId) {\n return\n }\n const projectId = process.env.PROJECT_ID\n if (!projectId) {\n return\n }\n await this.uploadService.modifyTestCase(runId, projectId, testCase)\n }\n async createZip(reportFolder: string | null, report: JsonReport) {\n if (reportFolder === null) {\n console.error('report folder is empty')\n console.error('it is likey that there are no scenarios to run')\n throw new Error('Empty report folder')\n }\n const zip = new JSZip()\n zip.file('report.json', JSON.stringify(report, null, 2))\n const folder = zip.folder('screenshots')\n const files = fs.readdirSync(path.join(reportFolder, 'screenshots'))\n files.forEach((file) => {\n folder.file(\n file,\n fs.readFileSync(path.join(reportFolder, 'screenshots', file))\n )\n })\n const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' })\n // save zip file\n const zipPath = path.join(reportFolder, 'report.zip')\n fs.writeFileSync(zipPath, new Uint8Array(zipBuffer))\n fs.writeFileSync(\n path.join(reportFolder, 'report.json'),\n JSON.stringify(report, null, 2)\n )\n return zipPath\n }\n}\n\nconst getFileUrisScreenShotDir = (reportFolder: string) => {\n const files = fs.readdirSync(path.join(reportFolder, 'screenshots'))\n\n return files.map((file) => ['screenshots', file].join('/'))\n}\n\nconst getFileUris = (reportFolder: string, targetFolder: string) => {\n const resultFolder = path.join(reportFolder, targetFolder)\n if (!fs.existsSync(resultFolder)) {\n return []\n }\n const files = fs.readdirSync(resultFolder)\n return files.map((file) => [targetFolder, file].join('/'))\n}\n"]}
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.0.90-dev";
1
+ export declare const version = "1.0.90-main";