public static void RunTests(TestRunnerMode mode, Action <IEnumerator> mainThreadDispatcher, Action onEnd) { Debug.Log("start test, mode:" + mode); var testRunner = new MiyamasuTestRunner(mainThreadDispatcher, onEnd); testRunner.RunTests(); }
public static void RunTests(TestRunnerMode mode, Action <Func <IEnumerator>[]> mainThreadDispatcher) { Debug.Log("start test, mode:" + mode); // new MiyamasuTestRunner(acts => mainThreadDispatcher(acts)); }
private TestFileSummary InvokeTestRunner(string headlessBrowserPath, TestOptions options, TestContext testContext, TestRunnerMode testRunnerMode, ITestMethodRunnerCallback callback) { string runnerPath = fileProbe.FindFilePath(testContext.TestRunner); string fileUrl = BuildHarnessUrl(testContext.TestHarnessPath, testContext.IsRemoteHarness); string runnerArgs = BuildRunnerArgs(options, testContext, fileUrl, runnerPath, testRunnerMode); Func<ProcessStream, TestFileSummary> streamProcessor = processStream => testCaseStreamReaderFactory.Create().Read(processStream, options, testContext, callback, m_debugEnabled); var processResult = process.RunExecutableAndProcessOutput(headlessBrowserPath, runnerArgs, streamProcessor); HandleTestProcessExitCode(processResult.ExitCode, testContext.InputTestFile, processResult.Model.Errors, callback); return processResult.Model; }
private TestCaseSummary ProcessTestPaths(IEnumerable<string> testPaths, TestOptions options, TestRunnerMode testRunnerMode, ITestMethodRunnerCallback callback) { stopWatch.Start(); string headlessBrowserPath = fileProbe.FindFilePath(HeadlessBrowserName); if (testPaths == null) throw new ArgumentNullException("testPaths"); if (headlessBrowserPath == null) throw new FileNotFoundException("Unable to find headless browser: " + HeadlessBrowserName); if (fileProbe.FindFilePath(TestRunnerJsName) == null) throw new FileNotFoundException("Unable to find test runner base js file: " + TestRunnerJsName); var overallSummary = new TestCaseSummary(); // Concurrent collection used to gather the parallel results from var testFileSummaries = new ConcurrentQueue<TestFileSummary>(); var resultCount = 0; var cancellationSource = new CancellationTokenSource(); var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = options.MaxDegreeOfParallelism, CancellationToken = cancellationSource.Token }; Parallel.ForEach(fileProbe.FindScriptFiles(testPaths, options.TestingMode), parallelOptions, testFile => { try { if (cancellationSource.IsCancellationRequested) return; TestContext testContext; resultCount++; if (testContextBuilder.TryBuildContext(testFile, options, out testContext)) { if (options.OpenInBrowser) { ChutzpahTracer.TraceInformation("Launching test harness '{0}' for file '{1}' in a browser", testContext.TestHarnessPath, testContext.InputTestFile); process.LaunchFileInBrowser(testContext.TestHarnessPath); } else { ChutzpahTracer.TraceInformation("Invoking test runner on test harness '{0}' for file '{1}'", testContext.TestHarnessPath, testContext.InputTestFile); var testSummary = InvokeTestRunner(headlessBrowserPath, options, testContext, testRunnerMode, callback); testFileSummaries.Enqueue(testSummary); } if (!m_debugEnabled && !options.OpenInBrowser) { ChutzpahTracer.TraceInformation("Cleaning up test context artifacts"); // Don't clean up context if in debug mode testContextBuilder.CleanupContext(testContext); } } // Limit the number of files we can scan to attempt to build a context for // This is important in the case of folder scanning where many JS files may not be // test files. if (resultCount >= options.FileSearchLimit) { cancellationSource.Cancel(); } } catch (Exception e) { callback.ExceptionThrown(e, testFile.FullPath); } }); // Gather TestFileSummaries into TaseCaseSummary foreach (var fileSummary in testFileSummaries) { overallSummary.Append(fileSummary); } stopWatch.Stop(); overallSummary.SetTotalRunTime((int)stopWatch.Elapsed.TotalMilliseconds); compilerCache.Save(); return overallSummary; }
private static string BuildRunnerArgs(TestOptions options, TestContext context, string fileUrl, string runnerPath, TestRunnerMode testRunnerMode) { string runnerArgs; var testModeStr = testRunnerMode.ToString().ToLowerInvariant(); var timeout = context.TestFileSettings.TestFileTimeout ?? options.TestFileTimeoutMilliseconds; if (timeout.HasValue && timeout > 0) { runnerArgs = string.Format("--proxy-type=none \"{0}\" {1} {2} {3}", runnerPath, fileUrl, testModeStr, timeout); } else { runnerArgs = string.Format("--proxy-type=none \"{0}\" {1} {2}", runnerPath, fileUrl, testModeStr); } return runnerArgs; }