await cliSuppressExceptions()

in lib/commands/run-api-scenario.ts [134:253]


  await cliSuppressExceptions(async () => {
    // suppress warning log in live validator
    log.consoleLogLevel = LiveValidatorLoggingLevels.error;

    if (argv.randomSeed !== undefined) {
      resetPseudoRandomSeed(argv.randomSeed);
    }

    if (argv.logLevel) {
      const transport = logger.transports.find((t) => t instanceof winston.transports.Console);
      if (transport !== undefined) {
        transport.level = argv.logLevel;
      }
    }

    const scenarioFiles = [];
    let readmePath = argv.readme ? pathResolve(argv.readme) : undefined;
    if (argv.apiScenario) {
      const scenarioFilePath = pathResolve(argv.apiScenario);
      scenarioFiles.push(scenarioFilePath);
      if (!readmePath) {
        readmePath = await findReadMe(pathDirName(scenarioFilePath));
      }
    }

    const swaggerFilePaths: string[] = [];
    for (const spec of argv.specs ?? []) {
      const specFile = pathResolve(spec);
      if (specFile && swaggerFilePaths.indexOf(specFile) < 0) {
        swaggerFilePaths.push(specFile);
      }
    }
    if (readmePath) {
      const inputFile = await getInputFiles(readmePath, argv.tag);
      for (const it of inputFile ?? []) {
        if (swaggerFilePaths.indexOf(it) < 0) {
          swaggerFilePaths.push(pathJoin(pathDirName(readmePath), it));
        }
      }

      if (!argv.apiScenario) {
        const tag = argv.tag ?? (await getDefaultTag(readmePath));
        const testResources = await getApiScenarioFiles(
          pathJoin(pathDirName(readmePath), "readme.test.md"),
          tag,
          argv.flag
        );
        for (const it of testResources ?? []) {
          scenarioFiles.push(pathJoin(pathDirName(readmePath), it));
        }
      }
    }

    logger.info("swagger-file:");
    logger.info(swaggerFilePaths);
    logger.info("scenario-file:");
    logger.info(scenarioFiles);

    let env: EnvironmentVariables = {};
    if (argv.envFile !== undefined) {
      env = JSON.parse(fs.readFileSync(argv.envFile).toString());
    }
    if (process.env[apiScenarioEnvKey]) {
      const envFromVariable = JSON.parse(process.env[apiScenarioEnvKey] as string);
      for (const key of Object.keys(envFromVariable)) {
        if (env[key] !== undefined && envFromVariable[key] !== env[key]) {
          logger.warn(
            `Notice: the variable '${key}' in '${argv.e}' is overwritten by the variable in the environment '${apiScenarioEnvKey}'.`
          );
        }
      }
      env = { ...env, ...envFromVariable };
    }

    ["armEndpoint", "location", "subscriptionId", "resourceGroupName"]
      .filter((k) => argv[k] !== undefined)
      .forEach((k) => (env[k] = argv[k]));

    const fileRoot = readmePath
      ? findGitRootDirectory(readmePath) ?? pathDirName(readmePath)
      : process.cwd();
    logger.verbose(`fileRoot: ${fileRoot}`);

    const opt: PostmanCollectionGeneratorOption = {
      fileRoot,
      checkUnderFileRoot: false,
      swaggerFilePaths: swaggerFilePaths,
      generateCollection: true,
      useJsonParser: false,
      runCollection: !argv.dryRun,
      env,
      outputFolder: argv.output,
      markdown: (argv.report ?? []).includes("markdown"),
      junit: (argv.report ?? []).includes("junit"),
      html: (argv.report ?? []).includes("html"),
      eraseXmsExamples: false,
      eraseDescription: false,
      testProxy: argv.testProxy,
      testProxyAssets:
        argv.testProxy && argv.testProxyAssets ? path.resolve(argv.testProxyAssets) : undefined,
      skipValidation: argv.skipValidation,
      savePayload: argv.savePayload,
      generateExample: argv.generateExample,
      verbose: ["verbose", "debug", "silly"].indexOf(argv.logLevel) >= 0,
      devMode: argv.devMode,
    };

    logger.debug("options:");
    logger.debug(opt);

    const generator = inversifyGetInstance(PostmanCollectionGenerator, opt);

    for (const scenarioFile of scenarioFiles) {
      await generator.run(scenarioFile, argv.skipCleanUp);
    }

    await generator.cleanUpAll();

    return 0;
  });