/// <summary> /// Returns an array of QUnitTest objects that encapsulate the QUnit tests within the passed in files to test. /// </summary> /// <param name="maxWaitInMs">The maximum number of milliseconds before the tests should timeout after page load; -1 for infinity, 0 to not support asynchronous tests</param> /// <param name="filesToTest">A list of one or more files to run tests on relative to the root of the test project.</param> /// <returns>An array of QUnitTest objects encapsulating the QUnit tests in the given files</returns> public static IEnumerable<QUnitTest> GetTests(IQUnitParser testRunner, int maxWaitInMs, params string[] filesToTest) { var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset); var tests = default(IEnumerable<QUnitTest>); var exception = default(Exception); // WatiN requires STA to run so rather than making the whole assembly // run with STA, which causes trouble when running with TeamCity we create // an STA thread in which to run the WatiN tests. var t = new Thread(() => { try { tests = filesToTest.SelectMany(testRunner.GetQUnitTestResults).ToArray(); } catch (Exception ex) { exception = ex; } finally { if (testRunner != null) testRunner.Dispose(); waitHandle.Set(); } }); t.SetApartmentState(ApartmentState.STA); t.Start(); waitHandle.WaitOne(); if (exception != null) return new []{ new QUnitTest { InitializationException = exception } }; return tests; }