async function handleRunSuite()

in app.js [58:93]


async function handleRunSuite(request, response, next) {
    const context = new Context(request, response);
    logger.log(`${server.name} processing a suite ${request.method} request.`);
    const runId = ResultsManager.getFreshRunId();
    logger.log("Started suite run with runIn " + runId);
    // Get the suite data from the request.
    try {
        var suiteData = await SuiteData.fromRequest(request);
        logger.log("Successfully got all tests from the request for runId " + runId);
    }
    catch (err){
        response.setHeader("content-type", "application/json");
        response.send(400, {results: [], errorMessage:"Could not get tests data from request", verdict:"error"});
        ResultsManager.deleteSuiteResult(runId);
        logger.log("Could not get tests data from request for runId " + runId);
        logger.log(err);
        return;
    }
    // Send a response with status code 202 and location header based on runId, and start the tests.
    response.setHeader("content-type", "application/json");
    response.setHeader("Location", "http://" + request.headers.host + "/getResults/" + runId);
    response.send(202, "Tests are running.");
    let testSuite = new Suite(context, runId, suiteData);
    try {
        await testSuite.run();
        logger.log("Finished suite run with runId " + runId);
        setTimeout(() => {
            ResultsManager.deleteSuiteResult(runId);
            logger.log("Deleted suite results for runId " + runId);
            }, config.defaults.testSuiteResultsRetentionSeconds*1000); // Delete suite results data after a constant time after tests end.
    }
    catch (err) {
        ResultsManager.updateSuiteResults(runId, [], "Error while running test suite", "error");
        logger.log("Error occurred during suite run with runIn " + runId);
    }
}