in lib/apiScenario/apiScenarioLoader.ts [229:311]
public async load(
scenarioFilePath: string,
swaggerFilePaths?: string[],
readmePath?: string
): Promise<ScenarioDefinition> {
const [rawDef, additionalTags] = await this.apiScenarioYamlLoader.load(scenarioFilePath);
if (!swaggerFilePaths || swaggerFilePaths.length === 0) {
swaggerFilePaths = [];
if (!readmePath) {
readmePath = await findReadMe(pathDirName(scenarioFilePath));
}
if (readmePath) {
const inputFile = await getInputFiles(readmePath);
for (const it of inputFile ?? []) {
if (swaggerFilePaths.indexOf(it) < 0) {
swaggerFilePaths.push(this.fileLoader.resolvePath(it));
}
}
}
}
await this.initialize(swaggerFilePaths, additionalTags);
rawDef.scope = rawDef.scope ?? "ResourceGroup";
const isArmScope = rawDef.scope !== "None";
const scenarioDef: ScenarioDefinition = {
name: basename(scenarioFilePath).substring(0, basename(scenarioFilePath).lastIndexOf(".")),
scope: rawDef.scope,
prepareSteps: [],
scenarios: [],
_filePath: this.fileLoader.relativePath(scenarioFilePath),
_swaggerFilePaths: swaggerFilePaths!,
cleanUpSteps: [],
...convertVariables(rawDef.variables),
authentication: this.loadAuthentication(rawDef.authentication),
};
if (isArmScope) {
if (!scenarioDef.authentication) {
scenarioDef.authentication = {
type: "AADToken",
scope: "$(armEndpoint)/.default",
};
}
if (!scenarioDef.variables.armEndpoint) {
scenarioDef.variables.armEndpoint = {
type: "string",
value: DEFAULT_ARM_ENDPOINT,
};
}
const requiredVariables = new Set(scenarioDef.requiredVariables);
if (["ResourceGroup", "Subscription"].indexOf(scenarioDef.scope) >= 0) {
requiredVariables.add("subscriptionId");
if (scenarioDef.scope === "ResourceGroup") {
requiredVariables.add("location");
}
}
scenarioDef.requiredVariables = [...requiredVariables];
}
const ctx: ApiScenarioContext = {
stepTracking: new Map(),
scenarioDef: scenarioDef,
stepIndex: 0,
};
await this.loadPrepareSteps(rawDef, ctx);
await this.loadCleanUpSteps(rawDef, ctx);
ctx.scenarioIndex = 0;
for (const rawScenario of rawDef.scenarios) {
ctx.stepTracking.clear();
const scenario = await this.loadScenario(rawScenario, ctx);
scenarioDef.scenarios.push(scenario);
ctx.scenarioIndex++;
}
// await this.writeTestDefinitionFile("./test.yaml", scenarioDef);
return scenarioDef;
}