@dev-blinq/cucumber-js 1.0.54 → 1.0.55-stage

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/bin/download-install.js +51 -10
  2. package/lib/api/gherkin.js +6 -1
  3. package/lib/api/gherkin.js.map +1 -1
  4. package/lib/configuration/axios_client.d.ts +1 -0
  5. package/lib/configuration/axios_client.js +40 -0
  6. package/lib/configuration/axios_client.js.map +1 -0
  7. package/lib/formatter/api.d.ts +2 -0
  8. package/lib/formatter/api.js +53 -0
  9. package/lib/formatter/api.js.map +1 -0
  10. package/lib/formatter/bvt_analysis_formatter.d.ts +4 -1
  11. package/lib/formatter/bvt_analysis_formatter.js +125 -36
  12. package/lib/formatter/bvt_analysis_formatter.js.map +1 -1
  13. package/lib/formatter/feature_data_format.d.ts +2 -2
  14. package/lib/formatter/feature_data_format.js +52 -7
  15. package/lib/formatter/feature_data_format.js.map +1 -1
  16. package/lib/formatter/helpers/constants.d.ts +44 -0
  17. package/lib/formatter/helpers/constants.js +50 -0
  18. package/lib/formatter/helpers/constants.js.map +1 -0
  19. package/lib/formatter/helpers/report_generator.d.ts +33 -1
  20. package/lib/formatter/helpers/report_generator.js +193 -4
  21. package/lib/formatter/helpers/report_generator.js.map +1 -1
  22. package/lib/formatter/helpers/test_case_attempt_formatter.js +1 -1
  23. package/lib/formatter/helpers/test_case_attempt_formatter.js.map +1 -1
  24. package/lib/formatter/helpers/upload_serivce.d.ts +5 -3
  25. package/lib/formatter/helpers/upload_serivce.js +148 -22
  26. package/lib/formatter/helpers/upload_serivce.js.map +1 -1
  27. package/lib/formatter/helpers/uploader.d.ts +2 -1
  28. package/lib/formatter/helpers/uploader.js +88 -15
  29. package/lib/formatter/helpers/uploader.js.map +1 -1
  30. package/lib/version.d.ts +1 -1
  31. package/lib/version.js +1 -1
  32. package/lib/version.js.map +1 -1
  33. package/package.json +5 -2
@@ -1,9 +1,14 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ /* eslint-disable no-console */
3
+ /* eslint-disable no-undef */
1
4
  const { argv } = require('node:process')
2
5
  const fs = require('fs')
3
6
  const path = require('path')
4
7
  const JSZip = require('jszip')
5
8
  const { mkdirSync, writeFileSync } = require('node:fs')
6
9
  const axios = require('axios').default
10
+ const tunnel = require('tunnel')
11
+
7
12
  let token = null
8
13
  let extractPath = null
9
14
  const getSSoUrl = () => {
@@ -12,17 +17,40 @@ const getSSoUrl = () => {
12
17
  return 'http://localhost:5000/api/auth'
13
18
  case 'dev':
14
19
  return 'https://dev.api.blinq.io/api/auth'
20
+ case 'stage':
21
+ return 'https://stage.api.blinq.io/api/auth'
15
22
  default:
16
23
  return 'https://api.blinq.io/api/auth'
17
24
  }
18
25
  }
19
26
 
27
+ const getProxy = () => {
28
+ if (!process.env.PROXY) {
29
+ return null
30
+ }
31
+
32
+ const proxy = process.env.PROXY
33
+ const url = new URL(proxy)
34
+ const proxyObject = {
35
+ host: url.hostname,
36
+ port: Number(url.port),
37
+ }
38
+
39
+ const { username, password } = url
40
+
41
+ if (username && password) {
42
+ proxyObject.proxyAuth = `${username}:${password}`
43
+ }
44
+ return tunnel.httpsOverHttp({ proxy: proxyObject })
45
+ }
20
46
  const getWorkSpaceUrl = () => {
21
47
  switch (process.env.NODE_ENV_BLINQ) {
22
48
  case 'local':
23
49
  return 'http://localhost:6000/api/workspace'
24
50
  case 'dev':
25
51
  return 'https://dev.api.blinq.io/api/workspace'
52
+ case "stage":
53
+ return 'https://stage.api.blinq.io/api/workspace'
26
54
  default:
27
55
  return 'https://api.blinq.io/api/workspace'
28
56
  }
@@ -77,26 +105,34 @@ const dirExists = (path) => {
77
105
  }
78
106
  const ssoUrl = getSSoUrl()
79
107
 
108
+ const getProjectByAccessKey = async (access_key) => {
109
+ const accessKeyUrl = `${ssoUrl}/getProjectByAccessKey`
110
+ const response = await axios.post(accessKeyUrl, {
111
+ access_key,
112
+ httpAgent: getProxy(),
113
+ proxy: false,
114
+ })
115
+ if (response.status !== 200) {
116
+ console.error('Error: Invalid access key')
117
+ process.exit(1)
118
+ }
119
+ return response.data
120
+ };
121
+
80
122
  const downloadAndInstall = async (extractPath, token) => {
81
123
  if (!dirExists(extractPath)) {
82
124
  fs.mkdirSync(extractPath, { recursive: true })
83
125
  }
84
126
  try {
85
- const accessKeyUrl = `${ssoUrl}/getProjectByAccessKey`
86
- const response = await axios.post(accessKeyUrl, {
87
- access_key: token,
88
- })
89
- if(response.status !== 200){
90
- console.error('Error: Invalid access key')
91
- process.exit(1)
92
- }
127
+ const data = await getProjectByAccessKey(token)
93
128
 
94
129
  const workspaceUrl = getWorkSpaceUrl() + '/pull-workspace'
95
-
96
130
  const res = await axios.get(workspaceUrl, {
97
131
  params: {
98
- projectId: response.data.project._id,
132
+ projectId: data.project._id,
99
133
  },
134
+ httpAgent: getProxy(),
135
+ proxy: false,
100
136
  responseType: 'arraybuffer',
101
137
  headers: {
102
138
  Authorization: `Bearer ${token}`,
@@ -104,6 +140,11 @@ const downloadAndInstall = async (extractPath, token) => {
104
140
  },
105
141
  })
106
142
 
143
+ if (res.status !== 200) {
144
+ console.error('Error: Unable to fetch workspace')
145
+ process.exit(1)
146
+ }
147
+
107
148
  const zip = await JSZip.loadAsync(res.data)
108
149
  for (const filename of Object.keys(zip.files)) {
109
150
  const fileData = zip.files[filename]
@@ -9,6 +9,7 @@ const gherkin_utils_1 = require("@cucumber/gherkin-utils");
9
9
  const pickle_filter_1 = __importDefault(require("../pickle_filter"));
10
10
  const helpers_1 = require("../cli/helpers");
11
11
  const feature_data_format_1 = require("../formatter/feature_data_format");
12
+ const node_path_1 = __importDefault(require("node:path"));
12
13
  async function getFilteredPicklesAndErrors({ newId, cwd, logger, unexpandedFeaturePaths, featurePaths, coordinates, onEnvelope, }) {
13
14
  const gherkinQuery = new gherkin_utils_1.Query();
14
15
  const parseErrors = [];
@@ -16,6 +17,10 @@ async function getFilteredPicklesAndErrors({ newId, cwd, logger, unexpandedFeatu
16
17
  let dataFunction = null;
17
18
  let functionVars = null;
18
19
  let mjsDataFiles = null;
20
+ let projectDir = process.cwd();
21
+ if (featurePaths.length > 0) {
22
+ projectDir = node_path_1.default.join(node_path_1.default.dirname(featurePaths[0]), '..', '..');
23
+ }
19
24
  await gherkinFromPaths(featurePaths, {
20
25
  newId,
21
26
  relativeTo: cwd,
@@ -30,7 +35,7 @@ async function getFilteredPicklesAndErrors({ newId, cwd, logger, unexpandedFeatu
30
35
  newDataAfterExamplesModify = newData;
31
36
  mjsDataFiles = mjsData;
32
37
  }
33
- const data = (0, feature_data_format_1.generateTestData)(newDataAfterExamplesModify);
38
+ const data = (0, feature_data_format_1.generateTestData)(newDataAfterExamplesModify, undefined, undefined, projectDir);
34
39
  envelope.source.data = data.newContent;
35
40
  variables = data.variables;
36
41
  fakeData = data.otherFakeData;
@@ -1 +1 @@
1
- {"version":3,"file":"gherkin.js","sourceRoot":"","sources":["../../src/api/gherkin.ts"],"names":[],"mappings":";;;;;;AAAA,+DAGkC;AASlC,2DAA+D;AAC/D,qEAA2C;AAC3C,4CAA6C;AAG7C,0EAIyC;AAmBlC,KAAK,UAAU,2BAA2B,CAAC,EAChD,KAAK,EACL,GAAG,EACH,MAAM,EACN,sBAAsB,EACtB,YAAY,EACZ,WAAW,EACX,UAAU,GASX;IAIC,MAAM,YAAY,GAAG,IAAI,qBAAY,EAAE,CAAA;IACvC,MAAM,WAAW,GAAiB,EAAE,CAAA;IACpC,IAAI,SAAc,EAChB,QAGG,EACH,WAAW,GAAG,CAAC,CAAA;IACjB,IAAI,YAAY,GAAkB,IAAI,CAAA;IACtC,IAAI,YAAY,GAAwB,IAAI,CAAA;IAC5C,IAAI,YAAY,GAAQ,IAAI,CAAA;IAE5B,MAAM,gBAAgB,CACpB,YAAY,EACZ;QACE,KAAK;QACL,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,WAAW,CAAC,cAAc;KAC3C,EACD,CAAC,QAAQ,EAAE,EAAE;QACX,IAAI,QAA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AAO;QACL,eAAe;QACf,WAAW;KACZ,CAAA;AACH,CAAC;AAzLD,kEAyLC;AAED,KAAK,UAAU,gBAAgB,CAC7B,KAAe,EACf,OAA8B,EAC9B,UAAwC;IAExC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,oBAAoB,GAAG,gCAAc,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACrE,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;QAC3C,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACvC,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {\n GherkinStreams,\n IGherkinStreamOptions,\n} from '@cucumber/gherkin-streams'\nimport {\n Envelope,\n GherkinDocument,\n IdGenerator,\n Location,\n ParseError,\n Pickle,\n} from '@cucumber/messages'\nimport { Query as GherkinQuery } from '@cucumber/gherkin-utils'\nimport PickleFilter from '../pickle_filter'\nimport { orderPickles } from '../cli/helpers'\nimport { ISourcesCoordinates } from './types'\nimport { ILogger } from '../logger'\nimport {\n generateExamplesFromFunction,\n generateTestData,\n generateExamplesFromFunctionGherkin,\n} from '../formatter/feature_data_format'\n\ninterface PickleWithDocument {\n gherkinDocument: GherkinDocument\n location: Location\n pickle: Pickle\n}\n\ninterface FunctionVars {\n previous: {\n header: string\n value: any\n }[]\n new: {\n header: string\n value: any\n }[]\n}\n\nexport async function getFilteredPicklesAndErrors({\n newId,\n cwd,\n logger,\n unexpandedFeaturePaths,\n featurePaths,\n coordinates,\n onEnvelope,\n}: {\n newId: IdGenerator.NewId\n cwd: string\n logger: ILogger\n unexpandedFeaturePaths: string[]\n featurePaths: string[]\n coordinates: ISourcesCoordinates\n onEnvelope?: (envelope: Envelope) => void\n}): Promise<{\n filteredPickles: PickleWithDocument[]\n parseErrors: ParseError[]\n}> {\n const gherkinQuery = new GherkinQuery()\n const parseErrors: ParseError[] = []\n let variables: any,\n fakeData: {\n var: string\n fake: string\n }[],\n pickleIndex = 0\n let dataFunction: string | null = null\n let functionVars: FunctionVars | null = null\n let mjsDataFiles: any = null\n\n await gherkinFromPaths(\n featurePaths,\n {\n newId,\n relativeTo: cwd,\n defaultDialect: coordinates.defaultDialect,\n },\n (envelope) => {\n if (envelope.source) {\n let newDataAfterExamplesModify = envelope.source.data\n const functionMatch = envelope.source.data.match(\n /@data:function:(.*?)\\.(.*)/\n )\n\n if (functionMatch) {\n dataFunction = functionMatch[2]\n const { newData, mjsData } = generateExamplesFromFunction(\n envelope.source.data,\n featurePaths[0],\n dataFunction,\n functionMatch[1]\n )\n newDataAfterExamplesModify = newData\n mjsDataFiles = mjsData\n }\n\n const data = generateTestData(newDataAfterExamplesModify)\n envelope.source.data = data.newContent\n variables = data.variables\n fakeData = data.otherFakeData\n }\n\n if (envelope.gherkinDocument && envelope.gherkinDocument.feature) {\n envelope.gherkinDocument.feature.children =\n envelope.gherkinDocument.feature.children.map((scenario) => {\n if (scenario.scenario) {\n if (dataFunction) {\n const { tableHeader, tableBody } = scenario.scenario.examples[0]\n\n functionVars = {\n previous: tableHeader.cells.map((cell, index) => ({\n header: cell.value,\n value: tableBody[0].cells[index].value,\n })),\n new: [],\n }\n\n const generateResult = generateExamplesFromFunctionGherkin(\n tableHeader.cells,\n tableBody[0].cells,\n mjsDataFiles\n )\n\n functionVars.new = generateResult\n\n generateResult.map(\n ({ value }, index) =>\n (scenario.scenario.examples[0].tableBody[0].cells[\n index\n ].value = value)\n )\n }\n let fakeDataIdx = 0\n scenario.scenario.examples.forEach((example) => {\n example.tableBody.forEach((row) => {\n row.cells.forEach((cell, index) => {\n if (\n fakeDataIdx < fakeData.length &&\n fakeData[fakeDataIdx].var === cell.value\n ) {\n cell.value = fakeData[fakeDataIdx].fake\n fakeDataIdx++\n }\n })\n })\n })\n scenario.scenario.steps = scenario.scenario.steps.map((step) => {\n step.text = generateTestData(\n step.text,\n variables,\n fakeData\n ).newContent\n return step\n })\n }\n return scenario\n })\n }\n\n if (envelope.pickle) {\n envelope.pickle.steps = envelope.pickle.steps.map((step) => {\n if (functionVars) {\n functionVars.new.forEach(({ value }, index) => {\n step.text = step.text.replace(\n functionVars.previous[index].value,\n value\n )\n })\n }\n const generateData = generateTestData(step.text, variables, fakeData)\n step.text = generateData.newContent\n pickleIndex =\n generateData.fakeIndex > pickleIndex\n ? generateData.fakeIndex\n : pickleIndex\n return step\n })\n\n for (let i = 0; i < pickleIndex; i++) {\n fakeData.shift()\n }\n pickleIndex = 0\n }\n\n gherkinQuery.update(envelope)\n if (envelope.parseError) {\n parseErrors.push(envelope.parseError)\n }\n onEnvelope?.(envelope)\n }\n )\n const pickleFilter = new PickleFilter({\n cwd,\n featurePaths: unexpandedFeaturePaths,\n names: coordinates.names,\n tagExpression: coordinates.tagExpression,\n })\n const filteredPickles: PickleWithDocument[] = gherkinQuery\n .getPickles()\n .filter((pickle) => {\n const gherkinDocument = gherkinQuery\n .getGherkinDocuments()\n .find((doc) => doc.uri === pickle.uri)\n return pickleFilter.matches({ gherkinDocument, pickle })\n })\n .map((pickle) => {\n const gherkinDocument = gherkinQuery\n .getGherkinDocuments()\n .find((doc) => doc.uri === pickle.uri)\n const location = gherkinQuery.getLocation(\n pickle.astNodeIds[pickle.astNodeIds.length - 1]\n )\n return {\n gherkinDocument,\n location,\n pickle,\n }\n })\n orderPickles(filteredPickles, coordinates.order, logger)\n return {\n filteredPickles,\n parseErrors,\n }\n}\n\nasync function gherkinFromPaths(\n paths: string[],\n options: IGherkinStreamOptions,\n onEnvelope: (envelope: Envelope) => void\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const gherkinMessageStream = GherkinStreams.fromPaths(paths, options)\n gherkinMessageStream.on('data', onEnvelope)\n gherkinMessageStream.on('end', resolve)\n gherkinMessageStream.on('error', reject)\n })\n}\n"]}
1
+ {"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,EAAE,OAAO,CAAC,CAAA;QACrE,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;QAC3C,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACvC,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {\n GherkinStreams,\n IGherkinStreamOptions,\n} from '@cucumber/gherkin-streams'\nimport {\n Envelope,\n GherkinDocument,\n IdGenerator,\n Location,\n ParseError,\n Pickle,\n} from '@cucumber/messages'\nimport { Query as GherkinQuery } from '@cucumber/gherkin-utils'\nimport PickleFilter from '../pickle_filter'\nimport { orderPickles } from '../cli/helpers'\nimport { ISourcesCoordinates } from './types'\nimport { ILogger } from '../logger'\nimport {\n generateExamplesFromFunction,\n generateTestData,\n generateExamplesFromFunctionGherkin,\n} from '../formatter/feature_data_format'\nimport path from 'node:path'\ninterface PickleWithDocument {\n gherkinDocument: GherkinDocument\n location: Location\n pickle: Pickle\n}\n\ninterface FunctionVars {\n previous: {\n header: string\n value: any\n }[]\n new: {\n header: string\n value: any\n }[]\n}\n\nexport async function getFilteredPicklesAndErrors({\n newId,\n cwd,\n logger,\n unexpandedFeaturePaths,\n featurePaths,\n coordinates,\n onEnvelope,\n}: {\n newId: IdGenerator.NewId\n cwd: string\n logger: ILogger\n unexpandedFeaturePaths: string[]\n featurePaths: string[]\n coordinates: ISourcesCoordinates\n onEnvelope?: (envelope: Envelope) => void\n}): Promise<{\n filteredPickles: PickleWithDocument[]\n parseErrors: ParseError[]\n}> {\n const gherkinQuery = new GherkinQuery()\n const parseErrors: ParseError[] = []\n let variables: any,\n fakeData: {\n var: string\n fake: string\n }[],\n pickleIndex = 0\n let dataFunction: string | null = null\n let functionVars: FunctionVars | null = null\n let mjsDataFiles: any = null\n let projectDir = process.cwd()\n if (featurePaths.length > 0) {\n projectDir = path.join(path.dirname(featurePaths[0]), '..', '..')\n }\n await gherkinFromPaths(\n featurePaths,\n {\n newId,\n relativeTo: cwd,\n defaultDialect: coordinates.defaultDialect,\n },\n (envelope) => {\n if (envelope.source) {\n let newDataAfterExamplesModify = envelope.source.data\n const functionMatch = envelope.source.data.match(\n /@data:function:(.*?)\\.(.*)/\n )\n\n if (functionMatch) {\n dataFunction = functionMatch[2]\n const { newData, mjsData } = generateExamplesFromFunction(\n envelope.source.data,\n featurePaths[0],\n dataFunction,\n functionMatch[1]\n )\n newDataAfterExamplesModify = newData\n mjsDataFiles = mjsData\n }\n\n const data = generateTestData(\n newDataAfterExamplesModify,\n undefined,\n undefined,\n projectDir\n )\n envelope.source.data = data.newContent\n variables = data.variables\n fakeData = data.otherFakeData\n }\n\n if (envelope.gherkinDocument && envelope.gherkinDocument.feature) {\n envelope.gherkinDocument.feature.children =\n envelope.gherkinDocument.feature.children.map((scenario) => {\n if (scenario.scenario) {\n if (dataFunction) {\n const { tableHeader, tableBody } = scenario.scenario.examples[0]\n\n functionVars = {\n previous: tableHeader.cells.map((cell, index) => ({\n header: cell.value,\n value: tableBody[0].cells[index].value,\n })),\n new: [],\n }\n\n const generateResult = generateExamplesFromFunctionGherkin(\n tableHeader.cells,\n tableBody[0].cells,\n mjsDataFiles\n )\n\n functionVars.new = generateResult\n\n generateResult.map(\n ({ value }, index) =>\n (scenario.scenario.examples[0].tableBody[0].cells[\n index\n ].value = value)\n )\n }\n let fakeDataIdx = 0\n scenario.scenario.examples.forEach((example) => {\n example.tableBody.forEach((row) => {\n row.cells.forEach((cell, index) => {\n if (\n fakeDataIdx < fakeData.length &&\n fakeData[fakeDataIdx].var === cell.value\n ) {\n cell.value = fakeData[fakeDataIdx].fake\n fakeDataIdx++\n }\n })\n })\n })\n scenario.scenario.steps = scenario.scenario.steps.map((step) => {\n step.text = generateTestData(\n step.text,\n variables,\n fakeData\n ).newContent\n return step\n })\n }\n return scenario\n })\n }\n\n if (envelope.pickle) {\n envelope.pickle.steps = envelope.pickle.steps.map((step) => {\n if (functionVars) {\n functionVars.new.forEach(({ value }, index) => {\n step.text = step.text.replace(\n functionVars.previous[index].value,\n value\n )\n })\n }\n const generateData = generateTestData(step.text, variables, fakeData)\n step.text = generateData.newContent\n pickleIndex =\n generateData.fakeIndex > pickleIndex\n ? generateData.fakeIndex\n : pickleIndex\n return step\n })\n\n for (let i = 0; i < pickleIndex; i++) {\n fakeData.shift()\n }\n pickleIndex = 0\n }\n\n gherkinQuery.update(envelope)\n if (envelope.parseError) {\n parseErrors.push(envelope.parseError)\n }\n onEnvelope?.(envelope)\n }\n )\n const pickleFilter = new PickleFilter({\n cwd,\n featurePaths: unexpandedFeaturePaths,\n names: coordinates.names,\n tagExpression: coordinates.tagExpression,\n })\n const filteredPickles: PickleWithDocument[] = gherkinQuery\n .getPickles()\n .filter((pickle) => {\n const gherkinDocument = gherkinQuery\n .getGherkinDocuments()\n .find((doc) => doc.uri === pickle.uri)\n return pickleFilter.matches({ gherkinDocument, pickle })\n })\n .map((pickle) => {\n const gherkinDocument = gherkinQuery\n .getGherkinDocuments()\n .find((doc) => doc.uri === pickle.uri)\n const location = gherkinQuery.getLocation(\n pickle.astNodeIds[pickle.astNodeIds.length - 1]\n )\n return {\n gherkinDocument,\n location,\n pickle,\n }\n })\n orderPickles(filteredPickles, coordinates.order, logger)\n return {\n filteredPickles,\n parseErrors,\n }\n}\n\nasync function gherkinFromPaths(\n paths: string[],\n options: IGherkinStreamOptions,\n onEnvelope: (envelope: Envelope) => void\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const gherkinMessageStream = GherkinStreams.fromPaths(paths, options)\n gherkinMessageStream.on('data', onEnvelope)\n gherkinMessageStream.on('end', resolve)\n gherkinMessageStream.on('error', reject)\n })\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const axiosClient: import("axios").AxiosInstance;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.axiosClient = void 0;
7
+ /* eslint-disable no-console */
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const tunnel_1 = __importDefault(require("tunnel"));
10
+ const getProxy = () => {
11
+ if (!process.env.PROXY) {
12
+ return null;
13
+ }
14
+ const proxy = process.env.PROXY;
15
+ const url = new URL(proxy);
16
+ const proxyObject = {
17
+ host: url.hostname,
18
+ port: Number(url.port),
19
+ };
20
+ const { username, password } = url;
21
+ if (username && password) {
22
+ proxyObject.proxyAuth = `${username}:${password}`;
23
+ }
24
+ return tunnel_1.default.httpsOverHttp({ proxy: proxyObject });
25
+ };
26
+ const createAxiosClient = () => {
27
+ try {
28
+ const agent = getProxy();
29
+ return axios_1.default.create({
30
+ httpsAgent: agent,
31
+ proxy: false,
32
+ });
33
+ }
34
+ catch (error) {
35
+ console.log(error.message);
36
+ throw new Error(`Error creating axios client ${error instanceof Error ? error.message : error.response.data}`);
37
+ }
38
+ };
39
+ exports.axiosClient = createAxiosClient();
40
+ //# sourceMappingURL=axios_client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios_client.js","sourceRoot":"","sources":["../../src/configuration/axios_client.ts"],"names":[],"mappings":";;;;;;AAAA,+BAA+B;AAC/B,kDAAyB;AACzB,oDAA6C;AAG7C,MAAM,QAAQ,GAAG,GAAiB,EAAE;IAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE;QACtB,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,KAAK,GAAkB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA;IAC9C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,MAAM,WAAW,GAAiB;QAChC,IAAI,EAAE,GAAG,CAAC,QAAQ;QAClB,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;KACvB,CAAA;IAED,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAA;IAElC,IAAI,QAAQ,IAAI,QAAQ,EAAE;QACxB,WAAW,CAAC,SAAS,GAAG,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAA;KAClD;IACD,OAAO,gBAAM,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAA;AACrD,CAAC,CAAA;AAED,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC7B,IAAI;QACF,MAAM,KAAK,GAAmB,QAAQ,EAAE,CAAA;QACxC,OAAO,eAAK,CAAC,MAAM,CAAC;YAClB,UAAU,EAAE,KAAK;YACjB,KAAK,EAAE,KAAK;SACb,CAAC,CAAA;KACH;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC1B,MAAM,IAAI,KAAK,CACb,+BACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAC1D,EAAE,CACH,CAAA;KACF;AACH,CAAC,CAAA;AAEY,QAAA,WAAW,GAAG,iBAAiB,EAAE,CAAA","sourcesContent":["/* eslint-disable no-console */\nimport axios from 'axios'\nimport tunnel, { ProxyOptions } from 'tunnel'\nimport { Agent } from 'http'\n\nconst getProxy = (): Agent | null => {\n if (!process.env.PROXY) {\n return null\n }\n\n const proxy: string | null = process.env.PROXY\n const url = new URL(proxy)\n const proxyObject: ProxyOptions = {\n host: url.hostname,\n port: Number(url.port),\n }\n\n const { username, password } = url\n\n if (username && password) {\n proxyObject.proxyAuth = `${username}:${password}`\n }\n return tunnel.httpsOverHttp({ proxy: proxyObject })\n}\n\nconst createAxiosClient = () => {\n try {\n const agent: string | Agent = getProxy()\n return axios.create({\n httpsAgent: agent,\n proxy: false,\n })\n } catch (error) {\n console.log(error.message)\n throw new Error(\n `Error creating axios client ${\n error instanceof Error ? error.message : error.response.data\n }`\n )\n }\n}\n\nexport const axiosClient = createAxiosClient()\n"]}
@@ -0,0 +1,2 @@
1
+ declare const getProjectByAccessKey: (access_key: string) => Promise<any>;
2
+ export { getProjectByAccessKey };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getProjectByAccessKey = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const tunnel_1 = __importDefault(require("tunnel"));
9
+ const getSSoUrl = () => {
10
+ switch (process.env.NODE_ENV_BLINQ) {
11
+ case 'local':
12
+ return 'http://localhost:5000/api/auth';
13
+ case 'dev':
14
+ return 'https://dev.api.blinq.io/api/auth';
15
+ case 'stage':
16
+ return 'https://stage.api.blinq.io/api/auth';
17
+ default:
18
+ return 'https://api.blinq.io/api/auth';
19
+ }
20
+ };
21
+ const getProxy = () => {
22
+ if (!process.env.PROXY) {
23
+ return null;
24
+ }
25
+ const proxy = process.env.PROXY;
26
+ const url = new URL(proxy);
27
+ const proxyObject = {
28
+ host: url.hostname,
29
+ port: Number(url.port),
30
+ };
31
+ const { username, password } = url;
32
+ if (username && password) {
33
+ //@ts-ignore
34
+ proxyObject.proxyAuth = `${username}:${password}`;
35
+ }
36
+ return tunnel_1.default.httpsOverHttp({ proxy: proxyObject });
37
+ };
38
+ const getProjectByAccessKey = async (access_key) => {
39
+ const ssoUrl = getSSoUrl();
40
+ const accessKeyUrl = `${ssoUrl}/getProjectByAccessKey`;
41
+ const response = await axios_1.default.post(accessKeyUrl, {
42
+ access_key,
43
+ httpAgent: getProxy(),
44
+ proxy: false,
45
+ });
46
+ if (response.status !== 200) {
47
+ console.error('Error: Invalid access key');
48
+ process.exit(1);
49
+ }
50
+ return response.data;
51
+ };
52
+ exports.getProjectByAccessKey = getProjectByAccessKey;
53
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1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YAAY,EAAE;QAC9C,UAAU;QACV,SAAS,EAAE,QAAQ,EAAE;QACrB,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;IACF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAChB;IACD,OAAO,QAAQ,CAAC,IAAI,CAAA;AACtB,CAAC,CAAC;AAEO,sDAAqB","sourcesContent":["import axios from 'axios'\nimport tunnel from 'tunnel'\n\nconst getSSoUrl = () => {\n switch (process.env.NODE_ENV_BLINQ) {\n case 'local':\n return 'http://localhost:5000/api/auth'\n case 'dev':\n return 'https://dev.api.blinq.io/api/auth'\n case 'stage':\n return 'https://stage.api.blinq.io/api/auth'\n default:\n return 'https://api.blinq.io/api/auth'\n }\n }\n const getProxy = () => {\n if (!process.env.PROXY) {\n return null\n }\n \n const proxy = process.env.PROXY\n const url = new URL(proxy)\n const proxyObject = {\n host: url.hostname,\n port: Number(url.port),\n }\n \n const { username, password } = url\n \n if (username && password) {\n //@ts-ignore\n proxyObject.proxyAuth = `${username}:${password}`\n }\n return tunnel.httpsOverHttp({ proxy: proxyObject })\n }\n \n const getProjectByAccessKey = async (access_key:string) => {\n const ssoUrl = getSSoUrl()\n const accessKeyUrl = `${ssoUrl}/getProjectByAccessKey`\n const response = await axios.post(accessKeyUrl, {\n access_key,\n httpAgent: getProxy(),\n proxy: false,\n })\n if (response.status !== 200) {\n console.error('Error: Invalid access key')\n process.exit(1)\n }\n return response.data\n };\n\n export { getProjectByAccessKey };"]}
@@ -5,7 +5,9 @@ export default class BVTAnalysisFormatter extends Formatter {
5
5
  private exit;
6
6
  private START;
7
7
  private runName;
8
+ private summaryFormatter;
8
9
  constructor(options: IFormatterOptions);
10
+ private sendEvent;
9
11
  private uploadReport;
10
12
  finished(): Promise<any>;
11
13
  private analyzeReport;
@@ -14,5 +16,6 @@ export default class BVTAnalysisFormatter extends Formatter {
14
16
  private uploadFinalReport;
15
17
  private retrain;
16
18
  private call_cucumber_client;
17
- private logReportLink;
19
+ private getAppDataDir;
18
20
  }
21
+ export declare function logReportLink(runId: string, projectId: string): void;
@@ -3,14 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.logReportLink = void 0;
6
7
  const child_process_1 = require("child_process");
8
+ const fs_1 = require("fs");
9
+ const promises_1 = require("fs/promises");
7
10
  const path_1 = __importDefault(require("path"));
11
+ const tmp_1 = require("tmp");
8
12
  const _1 = __importDefault(require("."));
9
13
  const value_checker_1 = require("../value_checker");
10
14
  const report_generator_1 = __importDefault(require("./helpers/report_generator"));
11
15
  const uploader_1 = __importDefault(require("./helpers/uploader"));
12
- const fs_1 = require("fs");
13
- const tmp_promise_1 = require("tmp-promise");
16
+ const os_1 = __importDefault(require("os"));
17
+ const api_1 = require("./api");
18
+ const summary_formatter_1 = __importDefault(require("./summary_formatter"));
19
+ const constants_1 = require("./helpers/constants");
20
+ const axios_client_1 = require("../configuration/axios_client");
14
21
  //User token
15
22
  const TOKEN = process.env.TOKEN;
16
23
  class BVTAnalysisFormatter extends _1.default {
@@ -19,11 +26,13 @@ class BVTAnalysisFormatter extends _1.default {
19
26
  this.reportGenerator = new report_generator_1.default();
20
27
  this.uploader = new uploader_1.default(this.reportGenerator);
21
28
  this.exit = false;
29
+ this.summaryFormatter = new summary_formatter_1.default(options);
22
30
  if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {
23
31
  throw new Error('TOKEN must be set');
24
32
  }
33
+ this.sendEvent(constants_1.ActionEvents.cli_run_tests);
25
34
  options.eventBroadcaster.on('envelope', async (envelope) => {
26
- this.reportGenerator.handleMessage(envelope);
35
+ await this.reportGenerator.handleMessage(envelope);
27
36
  if ((0, value_checker_1.doesHaveValue)(envelope.meta) &&
28
37
  (0, value_checker_1.doesHaveValue)(envelope.meta.runName)) {
29
38
  this.runName = envelope.meta.runName;
@@ -35,12 +44,26 @@ class BVTAnalysisFormatter extends _1.default {
35
44
  await this.analyzeReport(report);
36
45
  }
37
46
  else {
38
- await this.uploadReport(report);
47
+ // await this.uploadReport(report)
39
48
  }
40
49
  this.exit = true;
41
50
  }
42
51
  });
43
52
  }
53
+ sendEvent(event) {
54
+ axios_client_1.axiosClient
55
+ .post(`${constants_1.SERVICES_URI.STORAGE}/event`, {
56
+ event,
57
+ }, {
58
+ headers: {
59
+ Authorization: `Bearer ${TOKEN}`,
60
+ 'x-source': 'cucumber_js',
61
+ },
62
+ })
63
+ .catch((err) => {
64
+ // Error with events, ignoring
65
+ });
66
+ }
44
67
  async uploadReport(report) {
45
68
  const uploadSuccessful = await this.uploadFinalReport(report);
46
69
  if (uploadSuccessful && report.result.status !== 'FAILED') {
@@ -51,37 +74,51 @@ class BVTAnalysisFormatter extends _1.default {
51
74
  async finished() {
52
75
  await new Promise((resolve) => {
53
76
  const checkInterval = setInterval(() => {
54
- if (this.exit) {
55
- clearInterval(checkInterval);
56
- resolve(null);
77
+ let anyRem;
78
+ if (process.env.UPLOADING_TEST_CASE) {
79
+ anyRem = JSON.parse(process.env.UPLOADING_TEST_CASE);
80
+ }
81
+ else {
82
+ anyRem = undefined;
83
+ }
84
+ if (this.exit && (!anyRem || anyRem.length === 0)) {
85
+ // clearInterval(checkInterval)
86
+ // resolve(null)
87
+ if (this.reportGenerator.getReport().result.status === 'FAILED') {
88
+ process.exit(1);
89
+ }
90
+ else {
91
+ process.exit(0);
92
+ }
57
93
  }
58
94
  }, 100); // check every 100ms
59
95
  });
60
96
  }
61
97
  async analyzeReport(report) {
62
- if (report.result.status === 'PASSED') {
63
- this.log('All tests passed. No need to retrain\n');
64
- const uploadSuccessful = await this.uploadFinalReport(report);
65
- if (uploadSuccessful) {
66
- process.exit(0);
98
+ if (report.result.status === 'PASSED' ||
99
+ process.env.NO_RETRAIN === 'false') {
100
+ if (report.result.status === 'PASSED') {
101
+ this.log('No test failed. No need to retrain\n');
67
102
  }
68
- process.exit(1);
103
+ if (process.env.NO_RETRAIN === 'false') {
104
+ this.log('Retraining is skipped since the failed step contains an API request\n');
105
+ }
106
+ // const uploadSuccessful = await this.uploadFinalReport(report)
107
+ // process.exit(0)
108
+ this.exit = true;
109
+ return;
69
110
  }
70
111
  //checking if the type of report.result is JsonResultFailed or not
71
112
  this.log('Some tests failed, starting the retraining...\n');
72
113
  if (!('startTime' in report.result) || !('endTime' in report.result)) {
73
114
  this.log('Unknown error occured,not retraining\n');
74
- await this.uploadFinalReport(report);
75
115
  return;
76
116
  }
77
- const finalReport = await this.processTestCases(report);
78
- const uploadSuccessful = await this.uploadFinalReport(finalReport);
79
- if (finalReport.result.status !== 'FAILED' && uploadSuccessful) {
80
- process.exit(0);
81
- }
82
- else {
117
+ await this.processTestCases(report);
118
+ if (this.reportGenerator.getReport().result.status === 'FAILED') {
83
119
  process.exit(1);
84
120
  }
121
+ process.exit(0);
85
122
  }
86
123
  async processTestCases(report) {
87
124
  const finalTestCases = [];
@@ -98,6 +135,7 @@ class BVTAnalysisFormatter extends _1.default {
98
135
  return {
99
136
  result: finalResult,
100
137
  testCases: finalTestCases,
138
+ env: report.env,
101
139
  };
102
140
  }
103
141
  async processTestCase(testCase, report) {
@@ -105,12 +143,20 @@ class BVTAnalysisFormatter extends _1.default {
105
143
  return testCase;
106
144
  }
107
145
  const failedTestSteps = testCase.steps
108
- .map((step, i) => (step.result.status !== 'PASSED' ? i : null))
146
+ .map((step, i) => step.result.status === 'FAILED' || step.result.status === 'UNDEFINED'
147
+ ? i
148
+ : null)
109
149
  .filter((i) => i !== null);
110
150
  const retrainStats = await this.retrain(failedTestSteps, testCase);
111
151
  if (!retrainStats) {
112
152
  return testCase;
113
153
  }
154
+ if (retrainStats.result.status === 'PASSED') {
155
+ await this.uploader.modifyTestCase({
156
+ ...testCase,
157
+ retrainStats,
158
+ });
159
+ }
114
160
  return {
115
161
  ...testCase,
116
162
  retrainStats,
@@ -120,7 +166,7 @@ class BVTAnalysisFormatter extends _1.default {
120
166
  let success = true;
121
167
  try {
122
168
  const { projectId, runId } = await this.uploader.uploadRun(finalReport, this.runName);
123
- this.logReportLink(runId, projectId);
169
+ logReportLink(runId, projectId);
124
170
  }
125
171
  catch (err) {
126
172
  this.log('Error uploading report\n');
@@ -129,12 +175,25 @@ class BVTAnalysisFormatter extends _1.default {
129
175
  }
130
176
  success = false;
131
177
  }
178
+ finally {
179
+ try {
180
+ (0, fs_1.writeFileSync)(path_1.default.join(this.reportGenerator.reportFolder, 'report.json'), JSON.stringify(finalReport, null, 2), 'utf-8');
181
+ }
182
+ catch (e) {
183
+ console.error('failed to write report.json to local disk');
184
+ }
185
+ }
132
186
  //this.log(JSON.stringify(finalReport, null, 2))
133
187
  return success;
134
188
  }
135
189
  async retrain(failedTestCases, testCase) {
136
- const stepsToRetrain = testCase.steps.map((_, i) => i);
137
- return await this.call_cucumber_client(stepsToRetrain, testCase);
190
+ const data = await (0, api_1.getProjectByAccessKey)(TOKEN);
191
+ const currentTimestampInSeconds = Math.floor(Date.now() / 1000);
192
+ if (data.project.expriration_date < currentTimestampInSeconds) {
193
+ console.log('Warning: Your project has expired, retraining is restricted. Please contact sales.');
194
+ process.exit(1);
195
+ }
196
+ return await this.call_cucumber_client(failedTestCases, testCase);
138
197
  }
139
198
  async call_cucumber_client(stepsToRetrain, testCase) {
140
199
  return new Promise((resolve, reject) => {
@@ -143,14 +202,21 @@ class BVTAnalysisFormatter extends _1.default {
143
202
  process.cwd(),
144
203
  path_1.default.join(process.cwd(), testCase.uri),
145
204
  `${testCase.scenarioName}`,
205
+ 'undefined',
146
206
  `${stepsToRetrain.join(',')}`,
147
207
  ];
148
208
  if (process.env.BLINQ_ENV) {
149
209
  args.push(`--env=${process.env.BLINQ_ENV}`);
150
210
  }
151
- // const temporaryFileTask = await import('tempy')
152
- (0, tmp_promise_1.withFile)(async ({ path: tempFile, fd }) => {
153
- // when this function returns or throws - release the file
211
+ if (!(0, fs_1.existsSync)(path_1.default.join(this.getAppDataDir(), 'blinq.io', '.temp'))) {
212
+ (0, promises_1.mkdir)(path_1.default.join(this.getAppDataDir(), 'blinq.io', '.temp'), {
213
+ recursive: true,
214
+ });
215
+ }
216
+ (0, tmp_1.tmpName)(async (err, name) => {
217
+ const tempFile = path_1.default.join(this.getAppDataDir(), 'blinq.io', '.temp', path_1.default.basename(name));
218
+ console.log('File path: ', tempFile);
219
+ await (0, promises_1.writeFile)(tempFile, '', 'utf-8');
154
220
  args.push(`--temp-file=${tempFile}`);
155
221
  const cucumberClient = (0, child_process_1.spawn)('node', [cucumber_client_path, ...args], {
156
222
  env: {
@@ -163,10 +229,11 @@ class BVTAnalysisFormatter extends _1.default {
163
229
  cucumberClient.stderr.on('data', (data) => {
164
230
  console.error(data.toString());
165
231
  });
166
- cucumberClient.on('close', (code) => {
232
+ cucumberClient.on('close', async (code) => {
167
233
  if (code === 0) {
168
234
  const reportData = (0, fs_1.readFileSync)(tempFile, 'utf-8');
169
235
  const retrainStats = JSON.parse(reportData);
236
+ await (0, promises_1.unlink)(tempFile);
170
237
  resolve(retrainStats);
171
238
  }
172
239
  else {
@@ -177,17 +244,39 @@ class BVTAnalysisFormatter extends _1.default {
177
244
  });
178
245
  });
179
246
  }
180
- logReportLink(runId, projectId) {
181
- let reportLinkBaseUrl = 'https://app.blinq.io';
182
- if (process.env.NODE_ENV_BLINQ === 'local') {
183
- reportLinkBaseUrl = 'http://localhost:3000';
247
+ getAppDataDir() {
248
+ if (process.env.BLINQ_APPDATA_DIR) {
249
+ return process.env.BLINQ_APPDATA_DIR;
184
250
  }
185
- else if (process.env.NODE_ENV_BLINQ === 'dev') {
186
- reportLinkBaseUrl = 'https://dev.app.blinq.io';
251
+ let appDataDir;
252
+ switch (process.platform) {
253
+ case 'win32':
254
+ appDataDir = process.env.APPDATA;
255
+ break;
256
+ case 'darwin':
257
+ appDataDir = path_1.default.join(os_1.default.homedir(), 'Library', 'Application Support');
258
+ break;
259
+ default:
260
+ appDataDir = path_1.default.join(os_1.default.homedir(), '.config');
261
+ break;
187
262
  }
188
- const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`;
189
- this.log(`Report link: ${reportLink}\n`);
263
+ return appDataDir;
190
264
  }
191
265
  }
192
266
  exports.default = BVTAnalysisFormatter;
267
+ function logReportLink(runId, projectId) {
268
+ let reportLinkBaseUrl = 'https://app.blinq.io';
269
+ if (process.env.NODE_ENV_BLINQ === 'local') {
270
+ reportLinkBaseUrl = 'http://localhost:3000';
271
+ }
272
+ else if (process.env.NODE_ENV_BLINQ === 'dev') {
273
+ reportLinkBaseUrl = 'https://dev.app.blinq.io';
274
+ }
275
+ else if (process.env.NODE_ENV_BLINQ === 'stage') {
276
+ reportLinkBaseUrl = 'https://stage.app.blinq.io';
277
+ }
278
+ const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`;
279
+ console.log(`Report link: ${reportLink}\n`);
280
+ }
281
+ exports.logReportLink = logReportLink;
193
282
  //# sourceMappingURL=bvt_analysis_formatter.js.map