public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
        {
            this.discoverySink = discoverySink;
            this.messageLogger = logger;
            this.sources       = sources;

            var settingsProvider = discoveryContext.RunSettings.GetSettings(JSTestAdapterConstants.SettingsName) as JavaScriptSettingsProvider;

            this.settings = settingsProvider != null ? settingsProvider.Settings : new JSTestSettings();

            this.settings.Discovery = true;

            try
            {
                this.testRunner.StartExecution(sources, settings, null);
            }
            catch (JSTestException e)
            {
                logger.SendMessage(TestMessageLevel.Error, e.ToString());
                return;
            }

            this.discoveryCompletion.Wait();
            this.testRunner.Dispose();
        }
Esempio n. 2
0
        public TestRuntimeManager(JSTestSettings settings, TestRunEvents testRunEvents)
            : this(JsonDataSerializer.Instance, new ProcessHelper(), new JSProcess())
        {
            this.settings      = settings;
            this.testRunEvents = testRunEvents;

            this.jsProcess.EnableDebugLogs = this.settings.DebugLogs;
        }
        public TestProcessStartInfo GetRuntimeProcessInfo(JSTestSettings settings, IEnumerable <string> sources)
        {
            switch (settings.Runtime)
            {
            case JavaScriptRuntime.NodeJS:
                return(NodeRuntimeProvider.Instance.GetRuntimeProcessInfo(settings.NodePath, settings.NodeModulesPath, this.IsRuntimeDebuggingEnabled, sources));
            }

            return(null);
        }
        public void Load(XmlReader reader)
        {
            ValidateArg.NotNull(reader, "reader");
            var serializer = new XmlSerializer(typeof(JSTestSettings), new XmlRootAttribute(JSTestAdapterConstants.SettingsName));

            if (reader.Read() && reader.Name.Equals(JSTestAdapterConstants.SettingsName))
            {
                this.Settings = serializer.Deserialize(reader) as JSTestSettings;
            }
        }
Esempio n. 5
0
 public void StartExecution(IEnumerable <string> sources, JSTestSettings settings, CancellationToken?cancellationToken)
 {
     this.StartExecution(settings, sources);
     if (settings.Discovery)
     {
         this.runtimeManager.SendStartDiscovery(sources);
     }
     else
     {
         this.runtimeManager.SendStartExecution(sources);
     }
 }
        public void GetRuntimeProcessInfoWillReturnRightProcess()
        {
            var settings = new JSTestSettings();

            settings.Runtime = JavaScriptRuntime.NodeJS;

            var sources = new string[] { "source" };

            var startInfo = factory.GetRuntimeProcessInfo(settings, sources);

            Assert.IsTrue(startInfo.FileName.EndsWith("node") || startInfo.FileName.EndsWith("node.exe"));
        }
Esempio n. 7
0
        public void StartExecution(IEnumerable <TestCase> tests, JSTestSettings settings, CancellationToken?cancellationToken)
        {
            var list = new List <string>();

            foreach (var test in tests)
            {
                if (!string.IsNullOrEmpty(test.Source))
                {
                    list.Add(test.Source);
                }
            }

            this.StartExecution(settings, list);
            this.runtimeManager.SendStartExecution(tests);
        }
Esempio n. 8
0
        private void StartExecution(JSTestSettings settings, IEnumerable <string> sources)
        {
            this.PrintHeader();

            var processInfo = RuntimeProviderFactory.Instance.GetRuntimeProcessInfo(settings, sources);

            this.runtimeManager = new TestRuntimeManager(settings, this.testRunEvents);
            Task <bool>     launchTask = null;
            JSTestException exception  = null;

            try
            {
                var launchStopWatch = Stopwatch.StartNew();
                launchTask = Task.Run(() => this.runtimeManager.LaunchProcessAsync(processInfo, new CancellationToken()));
                int launchTimeoutInMilliseconds = GetProcessLaunchTimeout();

                if (!launchTask.Wait(launchTimeoutInMilliseconds))
                {
                    throw new TimeoutException($"Process launch timeout after {launchTimeoutInMilliseconds} ms");
                }
                else
                {
                    launchStopWatch.Stop();
                    Console.WriteLine($"JSTest: Process Launched with id {this.runtimeManager.GetProcessId()} in {launchStopWatch.ElapsedMilliseconds} ms");
                }
            }
            catch (Exception ex)
            {
                this.testRunEvents.DisableInvoke = true;

                EqtTrace.Error(ex);
                exception = new JSTestException($"JSTest.TestRunner.StartExecution: Could not start javascript runtime : {ex}");
            }
            finally
            {
                if (exception == null && launchTask.Exception != null)
                {
                    EqtTrace.Error(launchTask.Exception);
                    exception = new JSTestException($"JSTest.TestRunner.StartExecution: Could not start javascript runtime. {launchTask.Exception}");
                }
            }

            if (exception != null)
            {
                throw exception;
            }
        }
Esempio n. 9
0
        private void StartRuntimeManager(JSTestSettings settings, IEnumerable <string> sources)
        {
            var processInfo = RuntimeProviderFactory.Instance.GetRuntimeProcessInfo(settings, sources);

            this.runtimeManager = new TestRuntimeManager(settings, this.testRunEvents);

            Task <bool> launchTask = null;

            JSTestException exception = null;

            try
            {
                launchTask = Task.Run(() => this.runtimeManager.LaunchProcessAsync(processInfo, new CancellationToken()));
                if (!launchTask.Wait(RuntimeProviderFactory.Instance.IsRuntimeDebuggingEnabled
                                    ? Constants.InfiniteTimout
                                    : Constants.StandardWaitTimout))
                {
                    throw new TimeoutException("Process launch timeout.");
                }
            }
            catch (Exception ex)
            {
                this.testRunEvents.DisableInvoke = true;

                EqtTrace.Error(ex);
                exception = new JSTestException($"JSTest.TestRunner.StartExecution: Could not start javascript runtime : {ex}");
            }
            finally
            {
                if (exception == null && launchTask.Exception != null)
                {
                    EqtTrace.Error(launchTask.Exception);
                    exception = new JSTestException($"JSTest.TestRunner.StartExecution: Could not start javascript runtime. {launchTask.Exception}");
                }
            }

            if (exception != null)
            {
                throw exception;
            }
        }
 public JavaScriptSettingsProvider()
 {
     this.Settings = new JSTestSettings();
 }