use newman summary in memory (#857)
Co-authored-by: Tianxiang Chen <tianxchen@microsoft.com>
This commit is contained in:
Родитель
9875310b7e
Коммит
9db4046c0b
|
@ -1,11 +1,4 @@
|
|||
import {
|
||||
RequestDefinition,
|
||||
ResponseDefinition,
|
||||
ItemDefinition,
|
||||
Request,
|
||||
Response,
|
||||
DescriptionDefinition,
|
||||
} from "postman-collection";
|
||||
import { ItemDefinition, Request, Response, DescriptionDefinition } from "postman-collection";
|
||||
import {
|
||||
NewmanAssertion,
|
||||
NewmanExecution,
|
||||
|
@ -32,8 +25,8 @@ interface Assertion {
|
|||
interface RawNewmanExecution {
|
||||
id: string;
|
||||
item: ItemDefinition;
|
||||
request: RequestDefinition;
|
||||
response: ResponseDefinition;
|
||||
request: Request;
|
||||
response: Response;
|
||||
assertions?: Assertion[];
|
||||
}
|
||||
|
||||
|
@ -48,8 +41,8 @@ export function parseNewmanReport(newmanReport: RawNewmanReport): NewmanReport {
|
|||
}
|
||||
|
||||
function generateExampleItem(it: RawNewmanExecution): NewmanExecution {
|
||||
const resp = new Response(it.response);
|
||||
const req = new Request(it.request);
|
||||
const resp = it.response;
|
||||
const req = it.request;
|
||||
const rawReq = parseRequest(req);
|
||||
const rawResp = parseResponse(resp);
|
||||
const annotation = JSON.parse((it.item.description as DescriptionDefinition)?.content || "{}");
|
||||
|
|
|
@ -314,7 +314,6 @@ export class NewmanReportValidator {
|
|||
try {
|
||||
return JSON.parse(body);
|
||||
} catch (e) {
|
||||
console.error(`Failed to parse body: ${body}`);
|
||||
return body ? body : undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import {
|
|||
} from "./newmanReportValidator";
|
||||
import { SwaggerAnalyzer, SwaggerAnalyzerOption } from "./swaggerAnalyzer";
|
||||
import { EnvironmentVariables, VariableEnv } from "./variableEnv";
|
||||
import { parseNewmanReport, RawNewmanReport } from "./newmanReportParser";
|
||||
import { parseNewmanReport } from "./newmanReportParser";
|
||||
import {
|
||||
defaultCollectionFileName,
|
||||
defaultEnvFileName,
|
||||
|
@ -399,8 +399,7 @@ export class PostmanCollectionGenerator {
|
|||
{
|
||||
collection: collection,
|
||||
environment: runtimeEnv,
|
||||
reporters: ["cli", "json"],
|
||||
reporter: { json: { export: reportExportPath } },
|
||||
reporters: ["cli"],
|
||||
},
|
||||
function (err, summary) {
|
||||
if (summary.run.failures.length > 0) {
|
||||
|
@ -413,7 +412,13 @@ export class PostmanCollectionGenerator {
|
|||
}
|
||||
)
|
||||
.on("done", async (_err, _summary) => {
|
||||
await this.postRun(scenario, reportExportPath, runtimeEnv);
|
||||
const summary = {
|
||||
environment: {
|
||||
values: _summary.environment.values.members,
|
||||
},
|
||||
run: _summary.run,
|
||||
};
|
||||
await this.postRun(scenario, reportExportPath, runtimeEnv, summary);
|
||||
resolve(_summary);
|
||||
});
|
||||
});
|
||||
|
@ -421,7 +426,12 @@ export class PostmanCollectionGenerator {
|
|||
await newmanRun();
|
||||
}
|
||||
|
||||
private async postRun(scenario: Scenario, reportExportPath: string, runtimeEnv: VariableScope) {
|
||||
private async postRun(
|
||||
scenario: Scenario,
|
||||
reportExportPath: string,
|
||||
runtimeEnv: VariableScope,
|
||||
summary: any
|
||||
) {
|
||||
const keys = await this.swaggerAnalyzer.getAllSecretKey();
|
||||
const values: string[] = [];
|
||||
for (const [k, v] of Object.entries(runtimeEnv.syncVariablesTo())) {
|
||||
|
@ -431,17 +441,15 @@ export class PostmanCollectionGenerator {
|
|||
}
|
||||
this.dataMasker.addMaskedValues(values);
|
||||
this.dataMasker.addMaskedKeys(keys);
|
||||
// read content and upload. mask newman report.
|
||||
const rawReport = JSON.parse(await this.fileLoader.load(reportExportPath)) as RawNewmanReport;
|
||||
|
||||
// add mask environment secret value
|
||||
for (const item of rawReport.environment.values) {
|
||||
for (const item of summary.environment.values) {
|
||||
if (this.dataMasker.maybeSecretKey(item.key)) {
|
||||
this.dataMasker.addMaskedValues([item.value]);
|
||||
}
|
||||
}
|
||||
|
||||
const newmanReport = parseNewmanReport(rawReport);
|
||||
const newmanReport = parseNewmanReport(summary);
|
||||
|
||||
const newmanReportValidatorOption: NewmanReportValidatorOption = {
|
||||
apiScenarioFilePath: scenario._scenarioDef._filePath,
|
||||
|
|
Загрузка…
Ссылка в новой задаче