@dev-blinq/cucumber-js 1.0.95 → 1.0.96-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.
- package/bin/download-install.js +14 -2
- package/lib/cli/validate_node_engine_version.js +3 -1
- package/lib/cli/validate_node_engine_version.js.map +1 -1
- package/lib/formatter/api.js +7 -1
- package/lib/formatter/api.js.map +1 -1
- package/lib/formatter/bvt_analysis_formatter.d.ts +11 -1
- package/lib/formatter/bvt_analysis_formatter.js +144 -56
- package/lib/formatter/bvt_analysis_formatter.js.map +1 -1
- package/lib/formatter/feature_data_format.js +0 -1
- package/lib/formatter/feature_data_format.js.map +1 -1
- package/lib/formatter/helpers/constants.d.ts +6 -0
- package/lib/formatter/helpers/constants.js +13 -3
- package/lib/formatter/helpers/constants.js.map +1 -1
- package/lib/formatter/helpers/report_generator.d.ts +17 -1
- package/lib/formatter/helpers/report_generator.js +236 -22
- package/lib/formatter/helpers/report_generator.js.map +1 -1
- package/lib/formatter/helpers/upload_serivce.d.ts +14 -1
- package/lib/formatter/helpers/upload_serivce.js +57 -4
- package/lib/formatter/helpers/upload_serivce.js.map +1 -1
- package/lib/formatter/helpers/uploader.js +11 -14
- package/lib/formatter/helpers/uploader.js.map +1 -1
- package/lib/formatter/summary_formatter.js +4 -0
- package/lib/formatter/summary_formatter.js.map +1 -1
- package/lib/runtime/test_case_runner.d.ts +1 -0
- package/lib/runtime/test_case_runner.js +10 -1
- package/lib/runtime/test_case_runner.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +3 -1
package/bin/download-install.js
CHANGED
|
@@ -19,8 +19,14 @@ const getSSoUrl = () => {
|
|
|
19
19
|
return 'https://dev.api.blinq.io/api/auth'
|
|
20
20
|
case 'stage':
|
|
21
21
|
return 'https://stage.api.blinq.io/api/auth'
|
|
22
|
-
|
|
22
|
+
case 'prod':
|
|
23
|
+
return 'https://api.blinq.io/api/auth'
|
|
24
|
+
case null:
|
|
23
25
|
return 'https://api.blinq.io/api/auth'
|
|
26
|
+
case undefined:
|
|
27
|
+
return 'https://api.blinq.io/api/auth'
|
|
28
|
+
default:
|
|
29
|
+
return `${process.env.NODE_ENV_BLINQ}/api/auth`
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
32
|
|
|
@@ -51,8 +57,14 @@ const getWorkSpaceUrl = () => {
|
|
|
51
57
|
return 'https://dev.api.blinq.io/api/workspace'
|
|
52
58
|
case "stage":
|
|
53
59
|
return 'https://stage.api.blinq.io/api/workspace'
|
|
54
|
-
|
|
60
|
+
case 'prod':
|
|
61
|
+
return 'https://api.blinq.io/api/workspace'
|
|
62
|
+
case null:
|
|
55
63
|
return 'https://api.blinq.io/api/workspace'
|
|
64
|
+
case undefined:
|
|
65
|
+
return 'https://api.blinq.io/api/workspace'
|
|
66
|
+
default:
|
|
67
|
+
return `${process.env.NODE_ENV_BLINQ}/api/workspace`
|
|
56
68
|
}
|
|
57
69
|
}
|
|
58
70
|
|
|
@@ -17,7 +17,9 @@ function validateNodeEngineVersion(currentVersion, onError, onWarning, readPacka
|
|
|
17
17
|
onError(`Cucumber can only run on Node.js versions ${requiredVersions}. This Node.js version is ${currentVersion}`);
|
|
18
18
|
}
|
|
19
19
|
else if (!semver_1.default.satisfies(currentVersion, testedVersions)) {
|
|
20
|
-
onWarning(
|
|
20
|
+
// onWarning(
|
|
21
|
+
// `This Node.js version (${currentVersion}) has not been tested with this version of Cucumber; it should work normally, but please raise an issue if you see anything unexpected.`
|
|
22
|
+
// )
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
exports.validateNodeEngineVersion = validateNodeEngineVersion;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate_node_engine_version.js","sourceRoot":"","sources":["../../src/cli/validate_node_engine_version.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,oDAA2B;AAO3B,MAAM,qBAAqB,GAAsB,GAAG,EAAE,CACpD,IAAI,CAAC,KAAK,CACR,YAAE;KACC,YAAY,CAAC,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;KACjE,QAAQ,EAAE,CACd,CAAA;AAEH,SAAgB,yBAAyB,CACvC,cAAsB,EACtB,OAAkC,EAClC,SAAoC,EACpC,kBAAqC,qBAAqB;IAE1D,MAAM,gBAAgB,GAAG,eAAe,EAAE,CAAC,OAAO,CAAC,IAAI,CAAA;IACvD,MAAM,cAAc,GAAG,eAAe,EAAE,CAAC,aAAa,CAAC,IAAI,CAAA;IAC3D,IAAI,CAAC,gBAAM,CAAC,SAAS,CAAC,cAAc,EAAE,gBAAgB,CAAC,EAAE;QACvD,OAAO,CACL,6CAA6C,gBAAgB,6BAA6B,cAAc,EAAE,CAC3G,CAAA;KACF;SAAM,IAAI,CAAC,gBAAM,CAAC,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE;QAC5D,
|
|
1
|
+
{"version":3,"file":"validate_node_engine_version.js","sourceRoot":"","sources":["../../src/cli/validate_node_engine_version.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,oDAA2B;AAO3B,MAAM,qBAAqB,GAAsB,GAAG,EAAE,CACpD,IAAI,CAAC,KAAK,CACR,YAAE;KACC,YAAY,CAAC,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;KACjE,QAAQ,EAAE,CACd,CAAA;AAEH,SAAgB,yBAAyB,CACvC,cAAsB,EACtB,OAAkC,EAClC,SAAoC,EACpC,kBAAqC,qBAAqB;IAE1D,MAAM,gBAAgB,GAAG,eAAe,EAAE,CAAC,OAAO,CAAC,IAAI,CAAA;IACvD,MAAM,cAAc,GAAG,eAAe,EAAE,CAAC,aAAa,CAAC,IAAI,CAAA;IAC3D,IAAI,CAAC,gBAAM,CAAC,SAAS,CAAC,cAAc,EAAE,gBAAgB,CAAC,EAAE;QACvD,OAAO,CACL,6CAA6C,gBAAgB,6BAA6B,cAAc,EAAE,CAC3G,CAAA;KACF;SAAM,IAAI,CAAC,gBAAM,CAAC,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE;QAC5D,aAAa;QACb,qLAAqL;QACrL,IAAI;KACL;AACH,CAAC;AAjBD,8DAiBC","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport semver from 'semver'\n\ntype PackageJSON = {\n engines: { node: string }\n enginesTested: { node: string }\n}\n\nconst readActualPackageJSON: () => PackageJSON = () =>\n JSON.parse(\n fs\n .readFileSync(path.resolve(__dirname, '..', '..', 'package.json'))\n .toString()\n )\n\nexport function validateNodeEngineVersion(\n currentVersion: string,\n onError: (message: string) => void,\n onWarning: (message: string) => void,\n readPackageJSON: () => PackageJSON = readActualPackageJSON\n): void {\n const requiredVersions = readPackageJSON().engines.node\n const testedVersions = readPackageJSON().enginesTested.node\n if (!semver.satisfies(currentVersion, requiredVersions)) {\n onError(\n `Cucumber can only run on Node.js versions ${requiredVersions}. This Node.js version is ${currentVersion}`\n )\n } else if (!semver.satisfies(currentVersion, testedVersions)) {\n // onWarning(\n // `This Node.js version (${currentVersion}) has not been tested with this version of Cucumber; it should work normally, but please raise an issue if you see anything unexpected.`\n // )\n }\n}\n"]}
|
package/lib/formatter/api.js
CHANGED
|
@@ -14,8 +14,14 @@ const getSSoUrl = () => {
|
|
|
14
14
|
return 'https://dev.api.blinq.io/api/auth';
|
|
15
15
|
case 'stage':
|
|
16
16
|
return 'https://stage.api.blinq.io/api/auth';
|
|
17
|
-
|
|
17
|
+
case 'prod':
|
|
18
|
+
return 'https://api.blinq.io/api/auth';
|
|
19
|
+
case null:
|
|
18
20
|
return 'https://api.blinq.io/api/auth';
|
|
21
|
+
case undefined:
|
|
22
|
+
return 'https://api.blinq.io/api/auth';
|
|
23
|
+
default:
|
|
24
|
+
return `${process.env.NODE_ENV_BLINQ}/api/auth`;
|
|
19
25
|
}
|
|
20
26
|
};
|
|
21
27
|
const getProxy = () => {
|
package/lib/formatter/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/formatter/api.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,oDAA2B;AAE3B,MAAM,SAAS,GAAG,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/formatter/api.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,oDAA2B;AAE3B,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,QAAQ,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE;QAClC,KAAK,OAAO;YACV,OAAO,gCAAgC,CAAA;QACzC,KAAK,KAAK;YACR,OAAO,mCAAmC,CAAA;QAC5C,KAAK,OAAO;YACV,OAAO,qCAAqC,CAAA;QAC9C,KAAK,MAAM;YACT,OAAO,+BAA+B,CAAA;QACxC,KAAK,IAAI;YACP,OAAO,+BAA+B,CAAA;QACxC,KAAK,SAAS;YACZ,OAAO,+BAA+B,CAAA;QACxC;YACE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,WAAW,CAAA;KAClD;AACH,CAAC,CAAA;AACD,MAAM,QAAQ,GAAG,GAAG,EAAE;IACpB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE;QACtB,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA;IAC/B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,MAAM,WAAW,GAAG;QAClB,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,YAAY;QACZ,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,qBAAqB,GAAG,KAAK,EAAE,UAAkB,EAAE,EAAE;IACzD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,YAAY,GAAG,GAAG,MAAM,wBAAwB,CAAA;IACtD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,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,CAAA;AAEQ,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 case 'prod':\n return 'https://api.blinq.io/api/auth'\n case null:\n return 'https://api.blinq.io/api/auth'\n case undefined:\n return 'https://api.blinq.io/api/auth'\n default:\n return `${process.env.NODE_ENV_BLINQ}/api/auth`\n }\n}\nconst 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\nconst 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\nexport { getProjectByAccessKey }\n"]}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import Formatter, { IFormatterOptions } from '.';
|
|
2
|
+
import ReportGenerator, { JsonTestResult } from './helpers/report_generator';
|
|
3
|
+
export declare let globalReportLink: string;
|
|
2
4
|
export default class BVTAnalysisFormatter extends Formatter {
|
|
5
|
+
static reportGenerator: ReportGenerator;
|
|
6
|
+
static reRunFailedStepsIndex: {
|
|
7
|
+
testCaseId: string;
|
|
8
|
+
failedStepIndex: number;
|
|
9
|
+
}[] | null;
|
|
3
10
|
private reportGenerator;
|
|
4
11
|
private uploader;
|
|
5
12
|
private exit;
|
|
6
13
|
private START;
|
|
7
14
|
private runName;
|
|
15
|
+
private failedStepsIndex;
|
|
8
16
|
private summaryFormatter;
|
|
17
|
+
private rootCauseArray;
|
|
9
18
|
constructor(options: IFormatterOptions);
|
|
10
19
|
private sendEvent;
|
|
11
20
|
private uploadReport;
|
|
@@ -15,7 +24,8 @@ export default class BVTAnalysisFormatter extends Formatter {
|
|
|
15
24
|
private processTestCase;
|
|
16
25
|
private uploadFinalReport;
|
|
17
26
|
private retrain;
|
|
27
|
+
private rerun;
|
|
18
28
|
private call_cucumber_client;
|
|
19
29
|
private getAppDataDir;
|
|
20
30
|
}
|
|
21
|
-
export declare function logReportLink(runId: string, projectId: string):
|
|
31
|
+
export declare function logReportLink(runId: string, projectId: string, status: JsonTestResult): string;
|
|
@@ -3,7 +3,7 @@ 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
|
+
exports.logReportLink = exports.globalReportLink = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
9
|
const promises_1 = require("fs/promises");
|
|
@@ -18,30 +18,51 @@ const api_1 = require("./api");
|
|
|
18
18
|
const summary_formatter_1 = __importDefault(require("./summary_formatter"));
|
|
19
19
|
const constants_1 = require("./helpers/constants");
|
|
20
20
|
const axios_client_1 = require("../configuration/axios_client");
|
|
21
|
+
const util_1 = require("util");
|
|
22
|
+
const child_process_2 = require("child_process");
|
|
21
23
|
//User token
|
|
22
24
|
const TOKEN = process.env.TOKEN;
|
|
25
|
+
exports.globalReportLink = '';
|
|
23
26
|
class BVTAnalysisFormatter extends _1.default {
|
|
24
27
|
constructor(options) {
|
|
25
28
|
super(options);
|
|
26
29
|
this.reportGenerator = new report_generator_1.default();
|
|
27
30
|
this.uploader = new uploader_1.default(this.reportGenerator);
|
|
28
31
|
this.exit = false;
|
|
32
|
+
this.rootCauseArray = [];
|
|
29
33
|
this.summaryFormatter = new summary_formatter_1.default(options);
|
|
34
|
+
BVTAnalysisFormatter.reportGenerator = this.reportGenerator;
|
|
35
|
+
this.rootCauseArray = [];
|
|
36
|
+
this.failedStepsIndex = [];
|
|
37
|
+
BVTAnalysisFormatter.reRunFailedStepsIndex = process.env.RERUN
|
|
38
|
+
? JSON.parse(process.env.RERUN)
|
|
39
|
+
: null;
|
|
30
40
|
if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {
|
|
31
41
|
throw new Error('TOKEN must be set');
|
|
32
42
|
}
|
|
33
43
|
this.sendEvent(constants_1.ActionEvents.cli_run_tests);
|
|
34
|
-
options.eventBroadcaster.on('envelope', async (envelope) => {
|
|
44
|
+
options.eventBroadcaster.on('envelope', async (envelope, data) => {
|
|
45
|
+
if ((0, value_checker_1.doesHaveValue)(envelope.testCaseFinished) && data) {
|
|
46
|
+
const { rootCause, report } = data;
|
|
47
|
+
if (!rootCause.status) {
|
|
48
|
+
console.error(`Root cause: ${rootCause.failClass}\n, ${rootCause.analysis}\nfailing step: ${rootCause.failedStep}`);
|
|
49
|
+
this.rootCauseArray.push({ rootCause, report });
|
|
50
|
+
this.failedStepsIndex.push({
|
|
51
|
+
testCaseId: report.id,
|
|
52
|
+
failedStepIndex: rootCause.failedStep,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
35
57
|
await this.reportGenerator.handleMessage(envelope);
|
|
36
58
|
if ((0, value_checker_1.doesHaveValue)(envelope.meta) &&
|
|
37
59
|
(0, value_checker_1.doesHaveValue)(envelope.meta.runName)) {
|
|
38
60
|
this.runName = envelope.meta.runName;
|
|
39
61
|
}
|
|
40
62
|
if ((0, value_checker_1.doesHaveValue)(envelope.testRunFinished)) {
|
|
41
|
-
const report = this.reportGenerator.getReport();
|
|
42
63
|
this.START = Date.now();
|
|
43
64
|
if (process.env.BVT_FORMATTER === 'ANALYSIS') {
|
|
44
|
-
await this.analyzeReport(
|
|
65
|
+
await this.analyzeReport();
|
|
45
66
|
}
|
|
46
67
|
else {
|
|
47
68
|
// await this.uploadReport(report)
|
|
@@ -94,10 +115,10 @@ class BVTAnalysisFormatter extends _1.default {
|
|
|
94
115
|
}, 100); // check every 100ms
|
|
95
116
|
});
|
|
96
117
|
}
|
|
97
|
-
async analyzeReport(
|
|
98
|
-
if (
|
|
118
|
+
async analyzeReport() {
|
|
119
|
+
if (this.rootCauseArray.length === 0 ||
|
|
99
120
|
process.env.NO_RETRAIN === 'false') {
|
|
100
|
-
if (
|
|
121
|
+
if (this.rootCauseArray.length === 0) {
|
|
101
122
|
this.log('No test failed. No need to retrain\n');
|
|
102
123
|
}
|
|
103
124
|
if (process.env.NO_RETRAIN === 'false') {
|
|
@@ -110,63 +131,44 @@ class BVTAnalysisFormatter extends _1.default {
|
|
|
110
131
|
}
|
|
111
132
|
//checking if the type of report.result is JsonResultFailed or not
|
|
112
133
|
this.log('Some tests failed, starting the retraining...\n');
|
|
113
|
-
|
|
114
|
-
this.log('Unknown error occured,not retraining\n');
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
await this.processTestCases(report);
|
|
134
|
+
await this.processTestCases();
|
|
118
135
|
if (this.reportGenerator.getReport().result.status === 'FAILED') {
|
|
119
136
|
process.exit(1);
|
|
120
137
|
}
|
|
121
138
|
process.exit(0);
|
|
122
139
|
}
|
|
123
|
-
async processTestCases(
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const modifiedTestCase = await this.processTestCase(testCase, report);
|
|
127
|
-
finalTestCases.push(modifiedTestCase);
|
|
140
|
+
async processTestCases() {
|
|
141
|
+
for (const { rootCause, report } of this.rootCauseArray) {
|
|
142
|
+
await this.processTestCase(rootCause, report);
|
|
128
143
|
}
|
|
129
|
-
const finalResult = finalTestCases.some((tc) => tc.result.status !== 'PASSED')
|
|
130
|
-
? report.result
|
|
131
|
-
: {
|
|
132
|
-
...report.result,
|
|
133
|
-
status: 'PASSED',
|
|
134
|
-
};
|
|
135
|
-
return {
|
|
136
|
-
result: finalResult,
|
|
137
|
-
testCases: finalTestCases,
|
|
138
|
-
env: report.env,
|
|
139
|
-
};
|
|
140
144
|
}
|
|
141
|
-
async processTestCase(
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
async processTestCase(rootCause, report) {
|
|
146
|
+
const failedTestSteps = rootCause.failedStep;
|
|
147
|
+
if (BVTAnalysisFormatter.reRunFailedStepsIndex &&
|
|
148
|
+
BVTAnalysisFormatter.reRunFailedStepsIndex.length > 0) {
|
|
149
|
+
const previousRun = BVTAnalysisFormatter.reRunFailedStepsIndex[0];
|
|
150
|
+
if (previousRun.failedStepIndex === failedTestSteps) {
|
|
151
|
+
console.log('Same step has failed again, skipping retraining');
|
|
152
|
+
BVTAnalysisFormatter.reRunFailedStepsIndex.shift();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
BVTAnalysisFormatter.reRunFailedStepsIndex.shift();
|
|
144
156
|
}
|
|
145
|
-
const
|
|
146
|
-
.map((step, i) => step.result.status === 'FAILED' || step.result.status === 'UNDEFINED'
|
|
147
|
-
? i
|
|
148
|
-
: null)
|
|
149
|
-
.filter((i) => i !== null);
|
|
150
|
-
const retrainStats = await this.retrain(failedTestSteps, testCase);
|
|
157
|
+
const retrainStats = await this.retrain(failedTestSteps, report);
|
|
151
158
|
if (!retrainStats) {
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
if (retrainStats.result.status === 'PASSED') {
|
|
155
|
-
await this.uploader.modifyTestCase({
|
|
156
|
-
...testCase,
|
|
157
|
-
retrainStats,
|
|
158
|
-
});
|
|
159
|
+
return;
|
|
159
160
|
}
|
|
160
|
-
|
|
161
|
-
...
|
|
161
|
+
await this.uploader.modifyTestCase({
|
|
162
|
+
...report,
|
|
162
163
|
retrainStats,
|
|
163
|
-
};
|
|
164
|
+
});
|
|
165
|
+
await this.rerun(report);
|
|
164
166
|
}
|
|
165
167
|
async uploadFinalReport(finalReport) {
|
|
166
168
|
let success = true;
|
|
167
169
|
try {
|
|
168
170
|
const { projectId, runId } = await this.uploader.uploadRun(finalReport, this.runName);
|
|
169
|
-
logReportLink(runId, projectId);
|
|
171
|
+
logReportLink(runId, projectId, finalReport.result);
|
|
170
172
|
}
|
|
171
173
|
catch (err) {
|
|
172
174
|
this.log('Error uploading report\n');
|
|
@@ -195,6 +197,49 @@ class BVTAnalysisFormatter extends _1.default {
|
|
|
195
197
|
}
|
|
196
198
|
return await this.call_cucumber_client(failedTestCases, testCase);
|
|
197
199
|
}
|
|
200
|
+
async rerun(report) {
|
|
201
|
+
await new Promise((resolve) => {
|
|
202
|
+
// Default to system Node.js
|
|
203
|
+
let node_path = process.argv.shift();
|
|
204
|
+
// Use bundled Node if running from recorder app on macOS or Windows
|
|
205
|
+
const isFromRecorderApp = process.env.FROM_RECORDER_APP === 'true';
|
|
206
|
+
const isSupportedPlatform = process.platform === 'darwin' || process.platform === 'win32';
|
|
207
|
+
if (isFromRecorderApp && isSupportedPlatform) {
|
|
208
|
+
node_path = process.execPath;
|
|
209
|
+
}
|
|
210
|
+
const args = [
|
|
211
|
+
path_1.default.join(process.cwd(), 'node_modules', '@dev-blinq', 'cucumber-js', 'bin', 'cucumber.js'),
|
|
212
|
+
'--name',
|
|
213
|
+
`^${report.scenarioName}$`,
|
|
214
|
+
'--exit',
|
|
215
|
+
'--format',
|
|
216
|
+
'bvt',
|
|
217
|
+
'--run-name',
|
|
218
|
+
`${report.scenarioName}@debug`,
|
|
219
|
+
path_1.default.join(process.cwd(), report.uri),
|
|
220
|
+
];
|
|
221
|
+
const envVars = {
|
|
222
|
+
...process.env,
|
|
223
|
+
RERUN: JSON.stringify(this.failedStepsIndex),
|
|
224
|
+
};
|
|
225
|
+
// Inject Electron node env only if using bundled node
|
|
226
|
+
if (node_path === process.execPath) {
|
|
227
|
+
envVars.ELECTRON_RUN_AS_NODE = '1';
|
|
228
|
+
}
|
|
229
|
+
const cucumberClient = (0, child_process_1.spawn)(node_path, args, {
|
|
230
|
+
env: envVars,
|
|
231
|
+
});
|
|
232
|
+
cucumberClient.stdout.on('data', (data) => {
|
|
233
|
+
console.log(data.toString());
|
|
234
|
+
});
|
|
235
|
+
cucumberClient.stderr.on('data', (data) => {
|
|
236
|
+
console.error(data.toString());
|
|
237
|
+
});
|
|
238
|
+
cucumberClient.on('close', () => {
|
|
239
|
+
resolve();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
198
243
|
async call_cucumber_client(stepsToRetrain, testCase) {
|
|
199
244
|
return new Promise((resolve, reject) => {
|
|
200
245
|
const cucumber_client_path = path_1.default.resolve(process.cwd(), 'node_modules', '@dev-blinq', 'cucumber_client', 'bin', 'client', 'cucumber.js');
|
|
@@ -203,7 +248,7 @@ class BVTAnalysisFormatter extends _1.default {
|
|
|
203
248
|
path_1.default.join(process.cwd(), testCase.uri),
|
|
204
249
|
`${testCase.scenarioName}`,
|
|
205
250
|
'undefined',
|
|
206
|
-
`${stepsToRetrain
|
|
251
|
+
`${stepsToRetrain},`,
|
|
207
252
|
];
|
|
208
253
|
if (process.env.BLINQ_ENV) {
|
|
209
254
|
args.push(`--env=${process.env.BLINQ_ENV}`);
|
|
@@ -216,12 +261,24 @@ class BVTAnalysisFormatter extends _1.default {
|
|
|
216
261
|
(0, tmp_1.tmpName)(async (err, name) => {
|
|
217
262
|
const tempFile = path_1.default.join(this.getAppDataDir(), 'blinq.io', '.temp', path_1.default.basename(name));
|
|
218
263
|
console.log('File path: ', tempFile);
|
|
264
|
+
if (!(0, fs_1.existsSync)(path_1.default.dirname(tempFile))) {
|
|
265
|
+
await (0, promises_1.mkdir)(path_1.default.dirname(tempFile), { recursive: true });
|
|
266
|
+
}
|
|
219
267
|
await (0, promises_1.writeFile)(tempFile, '', 'utf-8');
|
|
220
268
|
args.push(`--temp-file=${tempFile}`);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
269
|
+
// Determine node path
|
|
270
|
+
const isFromRecorderApp = process.env.FROM_RECORDER_APP === 'true';
|
|
271
|
+
const isSupportedPlatform = process.platform === 'darwin' || process.platform === 'win32';
|
|
272
|
+
const node_path = isFromRecorderApp && isSupportedPlatform ? process.execPath : 'node';
|
|
273
|
+
const envVars = {
|
|
274
|
+
...process.env,
|
|
275
|
+
TEMP_FILE_PATH: tempFile,
|
|
276
|
+
};
|
|
277
|
+
if (node_path === process.execPath) {
|
|
278
|
+
envVars.ELECTRON_RUN_AS_NODE = '1';
|
|
279
|
+
}
|
|
280
|
+
const cucumberClient = (0, child_process_1.spawn)(node_path, [cucumber_client_path, ...args], {
|
|
281
|
+
env: envVars,
|
|
225
282
|
});
|
|
226
283
|
cucumberClient.stdout.on('data', (data) => {
|
|
227
284
|
console.log(data.toString());
|
|
@@ -238,7 +295,16 @@ class BVTAnalysisFormatter extends _1.default {
|
|
|
238
295
|
}
|
|
239
296
|
else {
|
|
240
297
|
this.log('Error retraining\n');
|
|
241
|
-
|
|
298
|
+
try {
|
|
299
|
+
const reportData = (0, fs_1.readFileSync)(tempFile, 'utf-8');
|
|
300
|
+
const retrainStats = JSON.parse(reportData);
|
|
301
|
+
await (0, promises_1.unlink)(tempFile);
|
|
302
|
+
resolve(retrainStats);
|
|
303
|
+
}
|
|
304
|
+
catch (e) {
|
|
305
|
+
this.log('Error reading scenario report\n ' + e);
|
|
306
|
+
resolve(null);
|
|
307
|
+
}
|
|
242
308
|
}
|
|
243
309
|
});
|
|
244
310
|
});
|
|
@@ -264,7 +330,7 @@ class BVTAnalysisFormatter extends _1.default {
|
|
|
264
330
|
}
|
|
265
331
|
}
|
|
266
332
|
exports.default = BVTAnalysisFormatter;
|
|
267
|
-
function logReportLink(runId, projectId) {
|
|
333
|
+
function logReportLink(runId, projectId, status) {
|
|
268
334
|
let reportLinkBaseUrl = 'https://app.blinq.io';
|
|
269
335
|
if (process.env.NODE_ENV_BLINQ === 'local') {
|
|
270
336
|
reportLinkBaseUrl = 'http://localhost:3000';
|
|
@@ -275,8 +341,30 @@ function logReportLink(runId, projectId) {
|
|
|
275
341
|
else if (process.env.NODE_ENV_BLINQ === 'stage') {
|
|
276
342
|
reportLinkBaseUrl = 'https://stage.app.blinq.io';
|
|
277
343
|
}
|
|
344
|
+
else if (process.env.NODE_ENV_BLINQ === 'prod') {
|
|
345
|
+
reportLinkBaseUrl = 'https://app.blinq.io';
|
|
346
|
+
}
|
|
347
|
+
else if (!process.env.NODE_ENV_BLINQ) {
|
|
348
|
+
reportLinkBaseUrl = 'https://app.blinq.io';
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
reportLinkBaseUrl = process.env.NODE_ENV_BLINQ.replace('api', 'app');
|
|
352
|
+
}
|
|
278
353
|
const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`;
|
|
279
|
-
|
|
354
|
+
exports.globalReportLink = reportLink;
|
|
355
|
+
try {
|
|
356
|
+
publishReportLinkToGuacServer(reportLink, status.status === 'PASSED');
|
|
357
|
+
}
|
|
358
|
+
catch (err) {
|
|
359
|
+
// Error with events, ignoring
|
|
360
|
+
}
|
|
361
|
+
return reportLink;
|
|
280
362
|
}
|
|
281
363
|
exports.logReportLink = logReportLink;
|
|
364
|
+
function publishReportLinkToGuacServer(reportLink, result) {
|
|
365
|
+
if ((0, fs_1.existsSync)('/tmp/report_publish.sh')) {
|
|
366
|
+
const execAsync = (0, util_1.promisify)(child_process_2.exec);
|
|
367
|
+
execAsync('sh /tmp/report_publish.sh ' + reportLink + ' ' + result);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
282
370
|
//# sourceMappingURL=bvt_analysis_formatter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bvt_analysis_formatter.js","sourceRoot":"","sources":["../../src/formatter/bvt_analysis_formatter.ts"],"names":[],"mappings":";;;;;;AACA,iDAAqC;AACrC,2BAA4D;AAC5D,0CAAsD;AACtD,gDAAuB;AACvB,6BAA6B;AAC7B,yCAAgD;AAChD,oDAAgD;AAChD,kFAKmC;AACnC,kEAA+C;AAC/C,4CAAmB;AACnB,+BAA6C;AAC7C,4EAAkD;AAClD,mDAAgE;AAChE,gEAA2D;AAC3D,YAAY;AACZ,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA;AAQ/B,MAAqB,oBAAqB,SAAQ,UAAS;IAQzD,YAAY,OAA0B;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QARR,oBAAe,GAAG,IAAI,0BAAe,EAAE,CAAA;QACvC,aAAQ,GAAG,IAAI,kBAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACnD,SAAI,GAAG,KAAK,CAAA;QAOlB,IAAI,CAAC,gBAAgB,GAAG,IAAI,2BAAgB,CAAC,OAAO,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AAC,iBAAiB,EAAE;YACjC,OAAO,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAA;SACrC;QAED,IAAI,UAAkB,CAAA;QAEtB,QAAQ,OAAO,CAAC,QAAQ,EAAE;YACxB,KAAK,OAAO;gBACV,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,OAAQ,CAAA;gBACjC,MAAK;YACP,KAAK,QAAQ;gBACX,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,qBAAqB,CAAC,CAAA;gBACtE,MAAK;YACP;gBACE,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;gBAC/C,MAAK;SACR;QACD,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AArTD,uCAqTC;AAED,SAAgB,aAAa,CAAC,KAAa,EAAE,SAAiB;IAC5D,IAAI,iBAAiB,GAAG,sBAAsB,CAAA;IAC9C,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO,EAAE;QAC1C,iBAAiB,GAAG,uBAAuB,CAAA;KAC5C;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,KAAK,EAAE;QAC/C,iBAAiB,GAAG,0BAA0B,CAAA;KAC/C;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO,EAAE;QACjD,iBAAiB,GAAG,4BAA4B,CAAA;KACjD;IACD,MAAM,UAAU,GAAG,GAAG,iBAAiB,IAAI,SAAS,eAAe,KAAK,EAAE,CAAA;IAC1E,OAAO,CAAC,GAAG,CAAC,gBAAgB,UAAU,IAAI,CAAC,CAAA;AAC7C,CAAC;AAXD,sCAWC","sourcesContent":["import { Envelope, Meta } from '@cucumber/messages'\nimport { spawn } from 'child_process'\nimport { readFileSync, existsSync, writeFileSync } from 'fs'\nimport { mkdir, unlink, writeFile } from 'fs/promises'\nimport path from 'path'\nimport { tmpName } from 'tmp'\nimport Formatter, { IFormatterOptions } from '.'\nimport { doesHaveValue } from '../value_checker'\nimport ReportGenerator, {\n JsonReport,\n JsonTestProgress,\n JsonTestResult,\n RetrainStats,\n} from './helpers/report_generator'\nimport ReportUploader from './helpers/uploader'\nimport os from 'os'\nimport { getProjectByAccessKey } from './api'\nimport SummaryFormatter from './summary_formatter'\nimport { ActionEvents, SERVICES_URI } from './helpers/constants'\nimport { axiosClient } from '../configuration/axios_client'\n//User token\nconst TOKEN = process.env.TOKEN\ninterface MetaMessage extends Meta {\n runName: string\n}\n\ninterface EnvelopeWithMetaMessage extends Envelope {\n meta: MetaMessage\n}\nexport default class BVTAnalysisFormatter extends Formatter {\n private reportGenerator = new ReportGenerator()\n private uploader = new ReportUploader(this.reportGenerator)\n private exit = false\n private START: number\n private runName: string\n private summaryFormatter: SummaryFormatter\n\n constructor(options: IFormatterOptions) {\n super(options)\n this.summaryFormatter = new SummaryFormatter(options)\n if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {\n throw new Error('TOKEN must be set')\n }\n this.sendEvent(ActionEvents.cli_run_tests)\n options.eventBroadcaster.on(\n 'envelope',\n async (envelope: EnvelopeWithMetaMessage) => {\n await this.reportGenerator.handleMessage(envelope)\n if (\n doesHaveValue(envelope.meta) &&\n doesHaveValue(envelope.meta.runName)\n ) {\n this.runName = envelope.meta.runName\n }\n if (doesHaveValue(envelope.testRunFinished)) {\n const report = this.reportGenerator.getReport()\n this.START = Date.now()\n if (process.env.BVT_FORMATTER === 'ANALYSIS') {\n await this.analyzeReport(report)\n } else {\n // await this.uploadReport(report)\n }\n this.exit = true\n }\n }\n )\n }\n\n private sendEvent(event: ActionEvents) {\n axiosClient\n .post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event,\n },\n {\n headers: {\n Authorization: `Bearer ${TOKEN}`,\n 'x-source': 'cucumber_js',\n },\n }\n )\n .catch((err) => {\n // Error with events, ignoring\n })\n }\n\n private async uploadReport(report: JsonReport) {\n const uploadSuccessful = await this.uploadFinalReport(report)\n if (uploadSuccessful && report.result.status !== 'FAILED') {\n process.exit(0)\n }\n process.exit(1)\n }\n\n async finished(): Promise<any> {\n await new Promise((resolve) => {\n const checkInterval = setInterval(() => {\n let anyRem\n if (process.env.UPLOADING_TEST_CASE) {\n anyRem = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n } else {\n anyRem = undefined\n }\n\n if (this.exit && (!anyRem || anyRem.length === 0)) {\n // clearInterval(checkInterval)\n // resolve(null)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n } else {\n process.exit(0)\n }\n }\n }, 100) // check every 100ms\n })\n }\n private async analyzeReport(report: JsonReport) {\n if (\n report.result.status === 'PASSED' ||\n process.env.NO_RETRAIN === 'false'\n ) {\n if (report.result.status === 'PASSED') {\n this.log('No test failed. No need to retrain\\n')\n }\n if (process.env.NO_RETRAIN === 'false') {\n this.log(\n 'Retraining is skipped since the failed step contains an API request\\n'\n )\n }\n // const uploadSuccessful = await this.uploadFinalReport(report)\n // process.exit(0)\n this.exit = true\n return\n }\n\n //checking if the type of report.result is JsonResultFailed or not\n this.log('Some tests failed, starting the retraining...\\n')\n if (!('startTime' in report.result) || !('endTime' in report.result)) {\n this.log('Unknown error occured,not retraining\\n')\n return\n }\n await this.processTestCases(report)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n }\n process.exit(0)\n }\n private async processTestCases(report: JsonReport): Promise<JsonReport> {\n const finalTestCases = []\n for (const testCase of report.testCases) {\n const modifiedTestCase = await this.processTestCase(testCase, report)\n\n finalTestCases.push(modifiedTestCase)\n }\n const finalResult = finalTestCases.some(\n (tc) => tc.result.status !== 'PASSED'\n )\n ? report.result\n : ({\n ...report.result,\n status: 'PASSED',\n } as JsonTestResult)\n return {\n result: finalResult,\n testCases: finalTestCases,\n env: report.env,\n }\n }\n private async processTestCase(\n testCase: JsonTestProgress,\n report: JsonReport\n ): Promise<JsonTestProgress> {\n if (testCase.result.status === 'PASSED') {\n return testCase\n }\n const failedTestSteps = testCase.steps\n .map((step, i) =>\n step.result.status === 'FAILED' || step.result.status === 'UNDEFINED'\n ? i\n : null\n )\n .filter((i) => i !== null)\n const retrainStats = await this.retrain(failedTestSteps, testCase)\n\n if (!retrainStats) {\n return testCase\n }\n if (retrainStats.result.status === 'PASSED') {\n await this.uploader.modifyTestCase({\n ...testCase,\n retrainStats,\n })\n }\n\n return {\n ...testCase,\n retrainStats,\n }\n }\n\n private async uploadFinalReport(finalReport: JsonReport) {\n let success = true\n try {\n const { projectId, runId } = await this.uploader.uploadRun(\n finalReport,\n this.runName\n )\n logReportLink(runId, projectId)\n } catch (err) {\n this.log('Error uploading report\\n')\n if ('stack' in err) {\n this.log(err.stack)\n }\n success = false\n } finally {\n try {\n writeFileSync(\n path.join(this.reportGenerator.reportFolder, 'report.json'),\n JSON.stringify(finalReport, null, 2),\n 'utf-8'\n )\n } catch (e) {\n console.error('failed to write report.json to local disk')\n }\n }\n\n //this.log(JSON.stringify(finalReport, null, 2))\n return success\n }\n private async retrain(\n failedTestCases: number[],\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n const data = await getProjectByAccessKey(TOKEN)\n const currentTimestampInSeconds = Math.floor(Date.now() / 1000)\n if (data.project.expriration_date < currentTimestampInSeconds) {\n console.log(\n 'Warning: Your project has expired, retraining is restricted. Please contact sales.'\n )\n process.exit(1)\n }\n return await this.call_cucumber_client(failedTestCases, testCase)\n }\n\n private async call_cucumber_client(\n stepsToRetrain: number[],\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n return new Promise((resolve, reject) => {\n const cucumber_client_path = path.resolve(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber_client',\n 'bin',\n 'client',\n 'cucumber.js'\n )\n\n const args: string[] = [\n process.cwd(),\n path.join(process.cwd(), testCase.uri),\n `${testCase.scenarioName}`,\n 'undefined',\n `${stepsToRetrain.join(',')}`,\n ]\n\n if (process.env.BLINQ_ENV) {\n args.push(`--env=${process.env.BLINQ_ENV}`)\n }\n\n if (!existsSync(path.join(this.getAppDataDir(), 'blinq.io', '.temp'))) {\n mkdir(path.join(this.getAppDataDir(), 'blinq.io', '.temp'), {\n recursive: true,\n })\n }\n\n tmpName(async (err, name) => {\n const tempFile = path.join(\n this.getAppDataDir(),\n 'blinq.io',\n '.temp',\n path.basename(name)\n )\n console.log('File path: ', tempFile)\n await writeFile(tempFile, '', 'utf-8')\n\n args.push(`--temp-file=${tempFile}`)\n const cucumberClient = spawn('node', [cucumber_client_path, ...args], {\n env: {\n ...process.env,\n },\n })\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', async (code) => {\n if (code === 0) {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } else {\n this.log('Error retraining\\n')\n resolve(null)\n }\n })\n })\n })\n }\n\n private getAppDataDir() {\n if (process.env.BLINQ_APPDATA_DIR) {\n return process.env.BLINQ_APPDATA_DIR\n }\n\n let appDataDir: string\n\n switch (process.platform) {\n case 'win32':\n appDataDir = process.env.APPDATA!\n break\n case 'darwin':\n appDataDir = path.join(os.homedir(), 'Library', 'Application Support')\n break\n default:\n appDataDir = path.join(os.homedir(), '.config')\n break\n }\n return appDataDir\n }\n}\n\nexport function logReportLink(runId: string, projectId: string) {\n let reportLinkBaseUrl = 'https://app.blinq.io'\n if (process.env.NODE_ENV_BLINQ === 'local') {\n reportLinkBaseUrl = 'http://localhost:3000'\n } else if (process.env.NODE_ENV_BLINQ === 'dev') {\n reportLinkBaseUrl = 'https://dev.app.blinq.io'\n } else if (process.env.NODE_ENV_BLINQ === 'stage') {\n reportLinkBaseUrl = 'https://stage.app.blinq.io'\n }\n const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`\n console.log(`Report link: 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AA;IAC1E,wBAAgB,GAAG,UAAU,CAAA;IAC7B,IAAI;QACF,6BAA6B,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAA;KACtE;IAAC,OAAO,GAAG,EAAE;QACZ,8BAA8B;KAC/B;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AA3BD,sCA2BC;AAED,SAAS,6BAA6B,CAAC,UAAkB,EAAE,MAAe;IACxE,IAAI,IAAA,eAAU,EAAC,wBAAwB,CAAC,EAAE;QACxC,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAA;QACjC,SAAS,CAAC,4BAA4B,GAAG,UAAU,GAAG,GAAG,GAAG,MAAM,CAAC,CAAA;KACpE;AACH,CAAC","sourcesContent":["import { Envelope, Meta } from '@cucumber/messages'\nimport { spawn } from 'child_process'\nimport { readFileSync, existsSync, writeFileSync } from 'fs'\nimport { mkdir, unlink, writeFile } from 'fs/promises'\nimport path from 'path'\nimport { tmpName } from 'tmp'\nimport Formatter, { IFormatterOptions } from '.'\nimport { doesHaveValue } from '../value_checker'\nimport ReportGenerator, {\n JsonReport,\n JsonTestProgress,\n JsonTestResult,\n RetrainStats,\n} from './helpers/report_generator'\nimport ReportUploader from './helpers/uploader'\nimport os from 'os'\nimport { getProjectByAccessKey } from './api'\nimport SummaryFormatter from './summary_formatter'\nimport { ActionEvents, SERVICES_URI } from './helpers/constants'\nimport { axiosClient } from '../configuration/axios_client'\nimport {\n FinishTestCaseResponse,\n RootCauseProps,\n} from './helpers/upload_serivce'\nimport { promisify } from 'util'\nimport { exec } from 'child_process'\n\n//User token\nconst TOKEN = process.env.TOKEN\ninterface MetaMessage extends Meta {\n runName: string\n}\n\ninterface EnvelopeWithMetaMessage extends Envelope {\n meta: MetaMessage\n}\nexport let globalReportLink = ''\nexport default class BVTAnalysisFormatter extends Formatter {\n static reportGenerator: ReportGenerator\n static reRunFailedStepsIndex:\n | { testCaseId: string; failedStepIndex: number }[]\n | null\n private reportGenerator = new ReportGenerator()\n private uploader = new ReportUploader(this.reportGenerator)\n private exit = false\n private START: number\n private runName: string\n private failedStepsIndex: { testCaseId: string; failedStepIndex: number }[]\n private summaryFormatter: SummaryFormatter\n private rootCauseArray: {\n rootCause: RootCauseProps\n report: JsonTestProgress\n }[] = []\n\n constructor(options: IFormatterOptions) {\n super(options)\n this.summaryFormatter = new SummaryFormatter(options)\n BVTAnalysisFormatter.reportGenerator = this.reportGenerator\n this.rootCauseArray = []\n this.failedStepsIndex = []\n BVTAnalysisFormatter.reRunFailedStepsIndex = process.env.RERUN\n ? JSON.parse(process.env.RERUN)\n : null\n\n if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {\n throw new Error('TOKEN must be set')\n }\n this.sendEvent(ActionEvents.cli_run_tests)\n options.eventBroadcaster.on(\n 'envelope',\n async (envelope: EnvelopeWithMetaMessage, data?: any) => {\n if (doesHaveValue(envelope.testCaseFinished) && data) {\n const { rootCause, report } = data as FinishTestCaseResponse\n\n if (!rootCause.status) {\n console.error(\n `Root cause: ${rootCause.failClass}\\n, ${rootCause.analysis}\\nfailing step: ${rootCause.failedStep}`\n )\n this.rootCauseArray.push({ rootCause, report })\n this.failedStepsIndex.push({\n testCaseId: report.id,\n failedStepIndex: rootCause.failedStep,\n })\n }\n return\n }\n await this.reportGenerator.handleMessage(envelope)\n\n if (\n doesHaveValue(envelope.meta) &&\n doesHaveValue(envelope.meta.runName)\n ) {\n this.runName = envelope.meta.runName\n }\n if (doesHaveValue(envelope.testRunFinished)) {\n this.START = Date.now()\n if (process.env.BVT_FORMATTER === 'ANALYSIS') {\n await this.analyzeReport()\n } else {\n // await this.uploadReport(report)\n }\n this.exit = true\n }\n }\n )\n }\n\n private sendEvent(event: ActionEvents) {\n axiosClient\n .post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event,\n },\n {\n headers: {\n Authorization: `Bearer ${TOKEN}`,\n 'x-source': 'cucumber_js',\n },\n }\n )\n .catch((err) => {\n // Error with events, ignoring\n })\n }\n\n private async uploadReport(report: JsonReport) {\n const uploadSuccessful = await this.uploadFinalReport(report)\n if (uploadSuccessful && report.result.status !== 'FAILED') {\n process.exit(0)\n }\n process.exit(1)\n }\n\n async finished(): Promise<any> {\n await new Promise((resolve) => {\n const checkInterval = setInterval(() => {\n let anyRem\n if (process.env.UPLOADING_TEST_CASE) {\n anyRem = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n } else {\n anyRem = undefined\n }\n\n if (this.exit && (!anyRem || anyRem.length === 0)) {\n // clearInterval(checkInterval)\n // resolve(null)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n } else {\n process.exit(0)\n }\n }\n }, 100) // check every 100ms\n })\n }\n private async analyzeReport() {\n if (\n this.rootCauseArray.length === 0 ||\n process.env.NO_RETRAIN === 'false'\n ) {\n if (this.rootCauseArray.length === 0) {\n this.log('No test failed. No need to retrain\\n')\n }\n if (process.env.NO_RETRAIN === 'false') {\n this.log(\n 'Retraining is skipped since the failed step contains an API request\\n'\n )\n }\n // const uploadSuccessful = await this.uploadFinalReport(report)\n // process.exit(0)\n this.exit = true\n return\n }\n\n //checking if the type of report.result is JsonResultFailed or not\n\n this.log('Some tests failed, starting the retraining...\\n')\n await this.processTestCases()\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n }\n process.exit(0)\n }\n private async processTestCases() {\n for (const { rootCause, report } of this.rootCauseArray) {\n await this.processTestCase(rootCause, report)\n }\n }\n private async processTestCase(\n rootCause: RootCauseProps,\n report: JsonTestProgress\n ) {\n const failedTestSteps = rootCause.failedStep\n\n if (\n BVTAnalysisFormatter.reRunFailedStepsIndex &&\n BVTAnalysisFormatter.reRunFailedStepsIndex.length > 0\n ) {\n const previousRun = BVTAnalysisFormatter.reRunFailedStepsIndex[0]\n if (previousRun.failedStepIndex === failedTestSteps) {\n console.log('Same step has failed again, skipping retraining')\n BVTAnalysisFormatter.reRunFailedStepsIndex.shift()\n return\n }\n BVTAnalysisFormatter.reRunFailedStepsIndex.shift()\n }\n\n const retrainStats = await this.retrain(failedTestSteps, report)\n\n if (!retrainStats) {\n return\n }\n\n await this.uploader.modifyTestCase({\n ...report,\n retrainStats,\n })\n\n await this.rerun(report)\n }\n\n private async uploadFinalReport(finalReport: JsonReport) {\n let success = true\n try {\n const { projectId, runId } = await this.uploader.uploadRun(\n finalReport,\n this.runName\n )\n logReportLink(runId, projectId, finalReport.result)\n } catch (err) {\n this.log('Error uploading report\\n')\n if ('stack' in err) {\n this.log(err.stack)\n }\n success = false\n } finally {\n try {\n writeFileSync(\n path.join(this.reportGenerator.reportFolder, 'report.json'),\n JSON.stringify(finalReport, null, 2),\n 'utf-8'\n )\n } catch (e) {\n console.error('failed to write report.json to local disk')\n }\n }\n\n //this.log(JSON.stringify(finalReport, null, 2))\n return success\n }\n private async retrain(\n failedTestCases: number,\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n const data = await getProjectByAccessKey(TOKEN)\n const currentTimestampInSeconds = Math.floor(Date.now() / 1000)\n if (data.project.expriration_date < currentTimestampInSeconds) {\n console.log(\n 'Warning: Your project has expired, retraining is restricted. Please contact sales.'\n )\n process.exit(1)\n }\n return await this.call_cucumber_client(failedTestCases, testCase)\n }\n\n private async rerun(report: JsonTestProgress) {\n await new Promise<void>((resolve) => {\n // Default to system Node.js\n let node_path = process.argv.shift()\n\n // Use bundled Node if running from recorder app on macOS or Windows\n const isFromRecorderApp = process.env.FROM_RECORDER_APP === 'true'\n const isSupportedPlatform =\n process.platform === 'darwin' || process.platform === 'win32'\n\n if (isFromRecorderApp && isSupportedPlatform) {\n node_path = process.execPath\n }\n\n const args = [\n path.join(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber-js',\n 'bin',\n 'cucumber.js'\n ),\n '--name',\n `^${report.scenarioName}$`,\n '--exit',\n '--format',\n 'bvt',\n '--run-name',\n `${report.scenarioName}@debug`,\n path.join(process.cwd(), report.uri),\n ]\n\n const envVars: NodeJS.ProcessEnv = {\n ...process.env,\n RERUN: JSON.stringify(this.failedStepsIndex),\n }\n\n // Inject Electron node env only if using bundled node\n if (node_path === process.execPath) {\n envVars.ELECTRON_RUN_AS_NODE = '1'\n }\n\n const cucumberClient = spawn(node_path!, args, {\n env: envVars,\n })\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', () => {\n resolve()\n })\n })\n }\n\n private async call_cucumber_client(\n stepsToRetrain: number,\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n return new Promise((resolve, reject) => {\n const cucumber_client_path = path.resolve(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber_client',\n 'bin',\n 'client',\n 'cucumber.js'\n )\n\n const args: string[] = [\n process.cwd(),\n path.join(process.cwd(), testCase.uri),\n `${testCase.scenarioName}`,\n 'undefined',\n `${stepsToRetrain},`,\n ]\n\n if (process.env.BLINQ_ENV) {\n args.push(`--env=${process.env.BLINQ_ENV}`)\n }\n\n if (!existsSync(path.join(this.getAppDataDir(), 'blinq.io', '.temp'))) {\n mkdir(path.join(this.getAppDataDir(), 'blinq.io', '.temp'), {\n recursive: true,\n })\n }\n\n tmpName(async (err, name) => {\n const tempFile = path.join(\n this.getAppDataDir(),\n 'blinq.io',\n '.temp',\n path.basename(name)\n )\n console.log('File path: ', tempFile)\n\n if (!existsSync(path.dirname(tempFile))) {\n await mkdir(path.dirname(tempFile), { recursive: true })\n }\n await writeFile(tempFile, '', 'utf-8')\n\n args.push(`--temp-file=${tempFile}`)\n\n // Determine node path\n const isFromRecorderApp = process.env.FROM_RECORDER_APP === 'true'\n const isSupportedPlatform =\n process.platform === 'darwin' || process.platform === 'win32'\n const node_path =\n isFromRecorderApp && isSupportedPlatform ? process.execPath : 'node'\n\n const envVars: NodeJS.ProcessEnv = {\n ...process.env,\n TEMP_FILE_PATH: tempFile,\n }\n\n if (node_path === process.execPath) {\n envVars.ELECTRON_RUN_AS_NODE = '1'\n }\n\n const cucumberClient = spawn(\n node_path,\n [cucumber_client_path, ...args],\n {\n env: envVars,\n }\n )\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', async (code) => {\n if (code === 0) {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } else {\n this.log('Error retraining\\n')\n try {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } catch (e) {\n this.log('Error reading scenario report\\n ' + e)\n resolve(null)\n }\n }\n })\n })\n })\n }\n\n private getAppDataDir() {\n if (process.env.BLINQ_APPDATA_DIR) {\n return process.env.BLINQ_APPDATA_DIR\n }\n\n let appDataDir: string\n\n switch (process.platform) {\n case 'win32':\n appDataDir = process.env.APPDATA!\n break\n case 'darwin':\n appDataDir = path.join(os.homedir(), 'Library', 'Application Support')\n break\n default:\n appDataDir = path.join(os.homedir(), '.config')\n break\n }\n return appDataDir\n }\n}\n\nexport function logReportLink(\n runId: string,\n projectId: string,\n status: JsonTestResult\n) {\n let reportLinkBaseUrl = 'https://app.blinq.io'\n if (process.env.NODE_ENV_BLINQ === 'local') {\n reportLinkBaseUrl = 'http://localhost:3000'\n } else if (process.env.NODE_ENV_BLINQ === 'dev') {\n reportLinkBaseUrl = 'https://dev.app.blinq.io'\n } else if (process.env.NODE_ENV_BLINQ === 'stage') {\n reportLinkBaseUrl = 'https://stage.app.blinq.io'\n } else if (process.env.NODE_ENV_BLINQ === 'prod') {\n reportLinkBaseUrl = 'https://app.blinq.io'\n } else if (!process.env.NODE_ENV_BLINQ) {\n reportLinkBaseUrl = 'https://app.blinq.io'\n } else {\n reportLinkBaseUrl = process.env.NODE_ENV_BLINQ.replace('api', 'app')\n }\n const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`\n globalReportLink = reportLink\n try {\n publishReportLinkToGuacServer(reportLink, status.status === 'PASSED')\n } catch (err) {\n // Error with events, ignoring\n }\n return reportLink\n}\n\nfunction publishReportLinkToGuacServer(reportLink: string, result: boolean) {\n if (existsSync('/tmp/report_publish.sh')) {\n const execAsync = promisify(exec)\n execAsync('sh /tmp/report_publish.sh ' + reportLink + ' ' + result)\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature_data_format.js","sourceRoot":"","sources":["../../src/formatter/feature_data_format.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAuC;AACvC,4CAAmB;AACnB,gDAAuB;AAEvB,kDAAyB;AAEzB,MAAM,gBAAgB,GAAG,CACvB,kBAA0B,EAC1B,IAAU,EACV,QAGG,EACH,UAAmB,EACnB,EAAE;IACF,MAAM,MAAM,GAAG,2BAA2B,CAAA;IAC1C,MAAM,aAAa,GAAG,wBAAwB,CAAA;IAC9C,IAAI,UAAU,GAAG,kBAAkB,CAAA;IACnC,IAAI,KAAsB,CAAA;IAC1B,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;KAC3B;IACD,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAC7B,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,iBAAiB,CAClB,CAAA;IACD,IAAI,UAAU,GAAa,YAAE,CAAC,UAAU,CAAC,aAAa,CAAC;QACrD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC,CAAC,EAAE,CAAA;IACN,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QAC9B,UAAU,GAAG,EAAE,CAAA;KAChB;IACD,MAAM,OAAO,GAAG,EAAE,CAAA;IACl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AAM,CAAC,CAAA;SACvB;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;IAEF,IAAI,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;IAClD,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QACrC,iBAAiB,GAAG,iBAAiB,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAA;IAE3E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;AAC7B,CAAC,CAAA;AAmBC,oEAA4B;AAjB9B,MAAM,mCAAmC,GAAG,CAC1C,OAA6B,EAC7B,MAA4B,EAC5B,OAAY,EACZ,EAAE;IACF,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE;QAC3D,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE;YACnB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAA;SAC1C;QACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEF,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AAKC,kFAAmC","sourcesContent":["import { faker } from '@faker-js/faker'\nimport fs from 'fs'\nimport path from 'path'\nimport { TableCell } from '@cucumber/messages'\nimport JSON5 from 'json5'\n\nconst generateTestData = (\n featureFileContent: string,\n vars?: any,\n fakeData?: {\n var: string\n fake: string\n }[],\n projectDir?: string\n) => {\n const regexp = /\\{\\{([^}]*\\([^)]*\\))\\}\\}/g\n const variableRegex = /^([a-zA-Z0-9_]*)=(.*)/g\n let newContent = featureFileContent\n let match: RegExpExecArray\n if (!projectDir) {\n projectDir = process.cwd()\n }\n const namespacePath = path.join(\n projectDir,\n 'features',\n 'step_definitions',\n 'namespaces.json'\n )\n let namespaces: string[] = fs.existsSync(namespacePath)\n ? JSON.parse(fs.readFileSync(namespacePath, 'utf-8'))\n : []\n if (!Array.isArray(namespaces)) {\n namespaces = []\n }\n const matches = []\n // collect all matches\n while ((match = regexp.exec(featureFileContent)) !== null) {\n // match[0] is the full match, match[1] is the first capturing group\n // Eg:- match[0] = {{name}}, match[1] = name\n if (!namespaces.includes(match[1].split('.')[0])) matches.push(match)\n }\n // find all variables in the matches\n const variables: any = { ...vars }\n\n if (Object.keys(variables).length > 0) {\n for (let i = 0; i < matches.length; i++) {\n const _match = matches[i]\n const value = _match[1]\n const variableMatch = variableRegex.exec(value)\n if (variableMatch !== null) {\n newContent = newContent.replaceAll(_match[0], `{{${variableMatch[1]}}}`)\n }\n }\n\n for (const key in variables) {\n const variable = variables[key]\n newContent = newContent.replaceAll(`{{${variable.var}}}`, variable.fake)\n }\n } else {\n for (let i = 0; i < matches.length; i++) {\n const _match = matches[i]\n const value = _match[1]\n const variableMatch = variableRegex.exec(value)\n if (variableMatch !== null) {\n variables[variableMatch[1]] = {\n var: variableMatch[1],\n toFake: variableMatch[2],\n }\n newContent = newContent.replaceAll(_match[0], `{{${variableMatch[1]}}}`)\n }\n }\n\n for (const key in variables) {\n const variable = variables[key]\n const fake = getFakeString(\n variable.toFake.substring(2, variable.toFake.length - 2)\n )\n newContent = newContent.replaceAll(`{{${variable.var}}}`, fake)\n variables[key].fake = fake\n }\n }\n\n regexp.lastIndex = 0\n const otherFakeData = []\n const duplicateFakeData = fakeData ? [...fakeData] : []\n let fakeIndex = 0\n while ((match = regexp.exec(featureFileContent)) !== null) {\n if (namespaces.includes(match[1].split('.')[0])) continue\n try {\n const fake =\n duplicateFakeData &&\n duplicateFakeData.length > 0 &&\n duplicateFakeData[0].var === match[0]\n ? duplicateFakeData.shift().fake\n : getFakeString(match[0].substring(2, match[0].length - 2))\n otherFakeData.push({\n var: match[0],\n fake,\n })\n newContent = newContent.replace(match[0], fake)\n fakeIndex++\n } catch (err) {\n // eslint-disable-next-line no-console\n //console.log('unknown faker variable:' + match[0])\n }\n }\n\n return {\n newContent,\n variables,\n otherFakeData,\n changed: newContent !== featureFileContent,\n fakeIndex,\n }\n}\n\nconst getFakeString = (content: string) => {\n // content example: helpers.fromRegExp('#{2,9}')\n const faking = content.split('(')[0].split('.')\n // faking example: ['helpers', 'fromRegExp']\n const argument = content.substring(\n content.indexOf('(') + 1,\n content.lastIndexOf(')')\n )\n // argument example: '#{2,9}'\n\n let fakeFunc: any = faker\n faking.forEach((f: string) => {\n fakeFunc = fakeFunc[f]\n })\n let regexpParam = false\n if (faking.length === 2 && faking[1] === 'fromRegExp') {\n regexpParam = true\n }\n if (regexpParam) {\n return fakeFunc(new RegExp(argument))\n }\n try {\n return fakeFunc(JSON5.parse(argument))\n } catch (error) {\n if (!argument) {\n return fakeFunc()\n }\n\n return fakeFunc(argument)\n }\n}\n\nconst getDefinitionFunction = (\n feature_path: string,\n functionName: string,\n functionFile: string\n) => {\n const mjsFiles = fs\n .readdirSync(path.join(feature_path, '../step_definitions'))\n .filter((file) => file === `${functionFile}.js`)\n\n if (mjsFiles.length === 0) {\n throw new Error(`File ${functionFile} not found in step_definitions folder`)\n }\n\n const [mjsData] = mjsFiles.map((file) => {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { [functionName]: func } = require(path.join(\n feature_path,\n '../step_definitions',\n file\n ))\n if (!func)\n throw new Error(`Function ${functionName} not found in file ${file}`)\n\n return func()\n })\n\n return mjsData\n}\n\nconst generateExamplesFromFunction = (\n data: string,\n feature_path: string,\n functionName: string,\n functionFile: string\n) => {\n const examples = data.split('Examples:')[1].split('\\n').slice(1)\n const headers = examples[0]\n .split('|')\n .map((header) => header.trim())\n .filter((header) => header !== '')\n const values = examples[1]\n .split('|')\n .map((value) => value.trim())\n .filter((header) => header !== '')\n\n const mjsData = getDefinitionFunction(\n feature_path,\n functionName,\n functionFile\n )\n\n const newExamples = headers.map((header) => {\n if (mjsData[header]) {\n return mjsData[header]\n }\n return values[headers.indexOf(header)]\n })\n\n let newExamplesString = data.split('Examples:')[1]\n newExamples.forEach((example, index) => {\n newExamplesString = newExamplesString.replace(values[index], example)\n })\n\n const newData = data.replace(data.split('Examples:')[1], newExamplesString)\n\n return { newData, mjsData }\n}\n\nconst generateExamplesFromFunctionGherkin = (\n headers: readonly TableCell[],\n values: readonly TableCell[],\n mjsData: any\n) => {\n const newExamples = headers.map(({ value: header }, index) => {\n if (mjsData[header]) {\n return { header, value: mjsData[header] }\n }\n return { header, value: values[index].value }\n })\n\n return newExamples\n}\n\nexport {\n generateTestData,\n generateExamplesFromFunction,\n generateExamplesFromFunctionGherkin,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"feature_data_format.js","sourceRoot":"","sources":["../../src/formatter/feature_data_format.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAuC;AACvC,4CAAmB;AACnB,gDAAuB;AAEvB,kDAAyB;AAEzB,MAAM,gBAAgB,GAAG,CACvB,kBAA0B,EAC1B,IAAU,EACV,QAGG,EACH,UAAmB,EACnB,EAAE;IACF,MAAM,MAAM,GAAG,2BAA2B,CAAA;IAC1C,MAAM,aAAa,GAAG,wBAAwB,CAAA;IAC9C,IAAI,UAAU,GAAG,kBAAkB,CAAA;IACnC,IAAI,KAAsB,CAAA;IAC1B,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;KAC3B;IACD,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAC7B,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,iBAAiB,CAClB,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;QACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEF,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AAKC,kFAAmC","sourcesContent":["import { faker } from '@faker-js/faker'\nimport fs from 'fs'\nimport path from 'path'\nimport { TableCell } from '@cucumber/messages'\nimport JSON5 from 'json5'\n\nconst generateTestData = (\n featureFileContent: string,\n vars?: any,\n fakeData?: {\n var: string\n fake: string\n }[],\n projectDir?: string\n) => {\n const regexp = /\\{\\{([^}]*\\([^)]*\\))\\}\\}/g\n const variableRegex = /^([a-zA-Z0-9_]*)=(.*)/g\n let newContent = featureFileContent\n let match: RegExpExecArray\n if (!projectDir) {\n projectDir = process.cwd()\n }\n const namespacePath = path.join(\n projectDir,\n 'features',\n 'step_definitions',\n 'namespaces.json'\n )\n let namespaces: string[] = fs.existsSync(namespacePath)\n ? JSON.parse(fs.readFileSync(namespacePath, 'utf-8'))\n : []\n if (!Array.isArray(namespaces)) {\n namespaces = []\n }\n const matches = []\n // collect all matches\n while ((match = regexp.exec(featureFileContent)) !== null) {\n // match[0] is the full match, match[1] is the first capturing group\n // Eg:- match[0] = {{name}}, match[1] = name\n if (!namespaces.includes(match[1].split('.')[0])) matches.push(match)\n }\n // find all variables in the matches\n const variables: any = { ...vars }\n\n if (Object.keys(variables).length > 0) {\n for (let i = 0; i < matches.length; i++) {\n const _match = matches[i]\n const value = _match[1]\n const variableMatch = variableRegex.exec(value)\n if (variableMatch !== null) {\n newContent = newContent.replaceAll(_match[0], `{{${variableMatch[1]}}}`)\n }\n }\n\n for (const key in variables) {\n const variable = variables[key]\n newContent = newContent.replaceAll(`{{${variable.var}}}`, variable.fake)\n }\n } else {\n for (let i = 0; i < matches.length; i++) {\n const _match = matches[i]\n const value = _match[1]\n const variableMatch = variableRegex.exec(value)\n if (variableMatch !== null) {\n variables[variableMatch[1]] = {\n var: variableMatch[1],\n toFake: variableMatch[2],\n }\n newContent = newContent.replaceAll(_match[0], `{{${variableMatch[1]}}}`)\n }\n }\n\n for (const key in variables) {\n const variable = variables[key]\n const fake = getFakeString(\n variable.toFake.substring(2, variable.toFake.length - 2)\n )\n newContent = newContent.replaceAll(`{{${variable.var}}}`, fake)\n variables[key].fake = fake\n }\n }\n\n regexp.lastIndex = 0\n const otherFakeData = []\n const duplicateFakeData = fakeData ? [...fakeData] : []\n let fakeIndex = 0\n while ((match = regexp.exec(featureFileContent)) !== null) {\n if (namespaces.includes(match[1].split('.')[0])) continue\n try {\n const fake =\n duplicateFakeData &&\n duplicateFakeData.length > 0 &&\n duplicateFakeData[0].var === match[0]\n ? duplicateFakeData.shift().fake\n : getFakeString(match[0].substring(2, match[0].length - 2))\n otherFakeData.push({\n var: match[0],\n fake,\n })\n newContent = newContent.replace(match[0], fake)\n fakeIndex++\n } catch (err) {\n // eslint-disable-next-line no-console\n }\n }\n\n return {\n newContent,\n variables,\n otherFakeData,\n changed: newContent !== featureFileContent,\n fakeIndex,\n }\n}\n\nconst getFakeString = (content: string) => {\n // content example: helpers.fromRegExp('#{2,9}')\n const faking = content.split('(')[0].split('.')\n // faking example: ['helpers', 'fromRegExp']\n const argument = content.substring(\n content.indexOf('(') + 1,\n content.lastIndexOf(')')\n )\n // argument example: '#{2,9}'\n\n let fakeFunc: any = faker\n faking.forEach((f: string) => {\n fakeFunc = fakeFunc[f]\n })\n let regexpParam = false\n if (faking.length === 2 && faking[1] === 'fromRegExp') {\n regexpParam = true\n }\n if (regexpParam) {\n return fakeFunc(new RegExp(argument))\n }\n try {\n return fakeFunc(JSON5.parse(argument))\n } catch (error) {\n if (!argument) {\n return fakeFunc()\n }\n\n return fakeFunc(argument)\n }\n}\n\nconst getDefinitionFunction = (\n feature_path: string,\n functionName: string,\n functionFile: string\n) => {\n const mjsFiles = fs\n .readdirSync(path.join(feature_path, '../step_definitions'))\n .filter((file) => file === `${functionFile}.js`)\n\n if (mjsFiles.length === 0) {\n throw new Error(`File ${functionFile} not found in step_definitions folder`)\n }\n\n const [mjsData] = mjsFiles.map((file) => {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { [functionName]: func } = require(path.join(\n feature_path,\n '../step_definitions',\n file\n ))\n if (!func)\n throw new Error(`Function ${functionName} not found in file ${file}`)\n\n return func()\n })\n\n return mjsData\n}\n\nconst generateExamplesFromFunction = (\n data: string,\n feature_path: string,\n functionName: string,\n functionFile: string\n) => {\n const examples = data.split('Examples:')[1].split('\\n').slice(1)\n const headers = examples[0]\n .split('|')\n .map((header) => header.trim())\n .filter((header) => header !== '')\n const values = examples[1]\n .split('|')\n .map((value) => value.trim())\n .filter((header) => header !== '')\n\n const mjsData = getDefinitionFunction(\n feature_path,\n functionName,\n functionFile\n )\n\n const newExamples = headers.map((header) => {\n if (mjsData[header]) {\n return mjsData[header]\n }\n return values[headers.indexOf(header)]\n })\n\n let newExamplesString = data.split('Examples:')[1]\n newExamples.forEach((example, index) => {\n newExamplesString = newExamplesString.replace(values[index], example)\n })\n\n const newData = data.replace(data.split('Examples:')[1], newExamplesString)\n\n return { newData, mjsData }\n}\n\nconst generateExamplesFromFunctionGherkin = (\n headers: readonly TableCell[],\n values: readonly TableCell[],\n mjsData: any\n) => {\n const newExamples = headers.map(({ value: header }, index) => {\n if (mjsData[header]) {\n return { header, value: mjsData[header] }\n }\n return { header, value: values[index].value }\n })\n\n return newExamples\n}\n\nexport {\n generateTestData,\n generateExamplesFromFunction,\n generateExamplesFromFunctionGherkin,\n}\n"]}
|