/// <summary>
        /// Extracts the test run time data from the passed summary match object and populates it into the test run
        /// </summary>
        /// <param name="match">Passed summary match object</param>
        /// <param name="mochaStateContext"></param>
        protected void ExtractTestRunTime(Match match, MochaParserStateContext mochaStateContext)
        {
            // Handling parse errors is unnecessary
            var timeTaken = long.Parse(match.Groups[RegexCaptureGroups.TestRunTime].Value);

            // Store time taken based on the unit used
            switch (match.Groups[RegexCaptureGroups.TestRunTimeUnit].Value)
            {
            case "ms":
                mochaStateContext.TestRun.TestRunSummary.TotalExecutionTime = TimeSpan.FromMilliseconds(timeTaken);
                break;

            case "s":
                mochaStateContext.TestRun.TestRunSummary.TotalExecutionTime = TimeSpan.FromMilliseconds(timeTaken * 1000);
                break;

            case "m":
                mochaStateContext.TestRun.TestRunSummary.TotalExecutionTime = TimeSpan.FromMilliseconds(timeTaken * 60 * 1000);
                break;

            case "h":
                mochaStateContext.TestRun.TestRunSummary.TotalExecutionTime = TimeSpan.FromMilliseconds(timeTaken * 60 * 60 * 1000);
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// Detailed constructor where specified logger and telemetry data collector are initialized along with test run manager
        /// </summary>
        /// <param name="testRunPublisher"></param>
        /// <param name="diagnosticDataCollector"></param>
        /// <param name="telemetryDataCollector"></param>
        public MochaTestResultParser(ITestRunManager testRunManager, ITraceLogger logger, ITelemetryDataCollector telemetryDataCollector) : base(testRunManager, logger, telemetryDataCollector)
        {
            Logger.Info("MochaTestResultParser : Starting mocha test result parser.");
            Telemetry.AddOrUpdate(MochaTelemetryConstants.Initialize, true, MochaTelemetryConstants.EventArea);

            // Initialize the starting state of the parser
            var testRun = new TestRun($"{Name}/{Version}", "Mocha", 1);

            _stateContext = new MochaParserStateContext(testRun);
            _currentState = MochaParserStates.ExpectingTestResults;
        }
        /// <summary>
        /// Detailed constructor where specified logger and telemetry data collector are initialized along with test run manager
        /// </summary>
        /// <param name="testRunPublisher"></param>
        /// <param name="diagnosticDataCollector"></param>
        /// <param name="telemetryDataCollector"></param>
        public MochaTestResultParser(ITestRunManager testRunManager, ITraceLogger logger, ITelemetryDataCollector telemetryDataCollector) : base(testRunManager, logger, telemetryDataCollector)
        {
            logger.Info("MochaTestResultParser : Starting mocha test result parser.");
            telemetryDataCollector.AddToCumulativeTelemetry(MochaTelemetryConstants.EventArea, MochaTelemetryConstants.Initialize, true);

            // Initialize the starting state of the parser
            var testRun = new TestRun($"{Name}/{Version}", 1);

            this.stateContext = new MochaParserStateContext(testRun);
            this.currentState = MochaParserStates.ExpectingTestResults;

            this.expectingTestResults    = new MochaExpectingTestResults(AttemptPublishAndResetParser, logger, telemetryDataCollector);
            this.expectingTestRunSummary = new MochaExpectingTestRunSummary(AttemptPublishAndResetParser, logger, telemetryDataCollector);
            this.expectingStackTraces    = new MochaExpectingStackTraces(AttemptPublishAndResetParser, logger, telemetryDataCollector);
        }