Exemplo n.º 1
0
        public void OnMessage(ILongPollingConnection connection, string message, JToken data)
        {
            switch (message)
            {
            case "focusPlace":
            {
                var position = new Dictionary <string, object> {
                    { "fn", PathUtils.Join(_mainServer.ProjectDir, data.Value <string>("fn")) }, { "pos", data.Value <JArray>("pos") }
                };
                _mainServer.SendToAll(message, position);
                break;
            }

            /*case "runAction":
             *  {
             *      actions.actionList.invokeAction(data.id);
             *      break;
             *  }*/
            case "setLiveReload":
            {
                _mainServer.Project.LiveReloadEnabled = data.Value <bool>("value");
                // TODO: force recompile
                _mainServer.SendToAll("setLiveReload", data);
                break;
            }

            default:
            {
                Console.WriteLine("Main Message " + message + " " + data);
                break;
            }
            }
        }
Exemplo n.º 2
0
 public void OnConnect(ILongPollingConnection connection)
 {
     _mainServer.Clients.TryAdd(this, this);
     _connection = connection;
     _connection.Send("testUpdated", _mainServer.TestServerStateGetter());
     // _connection.Send("actionsRefresh", actions.actionList.getList());
     _connection.Send("setLiveReload", new Dictionary <string, object> {
         { "value", _mainServer.Project.LiveReloadEnabled }
     });
 }
Exemplo n.º 3
0
 public void OnClose(ILongPollingConnection connection)
 {
     _mainServer.Clients.TryRemove(this, out var _);
 }
Exemplo n.º 4
0
        public void OnMessage(ILongPollingConnection connection, string message, JToken data)
        {
            try
            {
                switch (message)
                {
                case "newClient":
                {
                    if (_verbose)
                    {
                        Console.WriteLine("New Test Client: " + data.Value <string>("userAgent"));
                    }
                    var client = UAParser.Parser.GetDefault().Parse(data.Value <string>("userAgent"));
                    lock (_lock)
                    {
                        _userAgent = client.ToString();
                        if (_url != null)
                        {
                            DoStart();
                        }
                        else
                        {
                            _connection.Send("wait", null);
                        }
                    }
                    _testServer.NotifySomeChange();
                    break;
                }

                case "wholeStart":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        _curResults.TotalTests = (int)data;
                        _suiteId    = 0;
                        _suiteStack = new Stack <SuiteOrTest>();
                        _suiteStack.Push(_curResults);
                    }
                    _testServer.NotifyTestingStarted();
                    _testServer.NotifySomeChange();
                    break;
                }

                case "wholeDone":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        _curResults.Duration = (double)data;
                        _curResults.Running  = false;
                        _oldResults          = _curResults;
                        _curResults          = null;
                        _suiteStack          = null;
                    }
                    _testServer.NotifyFinishedResults(_oldResults);
                    _testServer.NotifySomeChange();
                    break;
                }

                case "suiteStart":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var suite = new SuiteOrTest
                        {
                            Id       = ++_suiteId,
                            ParentId = _suiteStack.Peek().Id,
                            Name     = (string)data,
                            Nested   = new List <SuiteOrTest>(),
                            Duration = 0,
                            Failure  = false,
                            IsSuite  = true,
                            Failures = new List <MessageAndStack>(),
                            Skipped  = false,
                            Logs     = new List <MessageAndStack>()
                        };
                        _suiteStack.Peek().Nested.Add(suite);
                        _suiteStack.Push(suite);
                    }
                    _testServer.NotifySomeChange();
                    break;
                }

                case "suiteDone":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var suite = _suiteStack.Pop();
                        suite.Duration = data.Value <double>("duration");
                        suite.Failures.AddRange(ConvertFailures(data.Value <JArray>("failures")));
                        if (suite.Failures.Count > 0)
                        {
                            suite.Failure = true;
                            foreach (var s in _suiteStack)
                            {
                                s.Failure = true;
                            }
                        }
                    }
                    _testServer.NotifySomeChange();
                    break;
                }

                case "testStart":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var test = new SuiteOrTest
                        {
                            Id       = ++_suiteId,
                            ParentId = _suiteStack.Peek().Id,
                            Name     = data.Value <string>("name"),
                            Stack    = ConvertMessageAndStack("", data.Value <string>("stack")).Stack.Where(f => f.FileName != "testbundle.js").ToList(),
                            Nested   = null,
                            Duration = 0,
                            Failure  = false,
                            IsSuite  = false,
                            Failures = new List <MessageAndStack>(),
                            Skipped  = false,
                            Logs     = new List <MessageAndStack>()
                        };
                        _suiteStack.Peek().Nested.Add(test);
                        _suiteStack.Push(test);
                    }
                    _testServer.NotifySomeChange();
                    break;
                }

                case "testDone":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var test = _suiteStack.Pop();
                        test.Duration = data.Value <double>("duration");
                        test.Failures.AddRange(ConvertFailures(data.Value <JArray>("failures")));
                        _curResults.TestsFinished++;
                        var status = data.Value <string>("status");
                        if (status == "passed")
                        {
                        }
                        else if (status == "skipped" || status == "pending" || status == "disabled")
                        {
                            _curResults.TestsSkipped++;
                            test.Skipped = true;
                        }
                        else
                        {
                            _curResults.TestsFailed++;
                            test.Failure = true;
                            foreach (var s in _suiteStack)
                            {
                                s.Failure = true;
                            }
                        }
                    }
                    _testServer.NotifySomeChange();
                    break;
                }

                case "consoleLog":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var test = _suiteStack.Peek();
                        test.Logs.Add(ConvertMessageAndStack(data.Value <string>("message"), data.Value <string>("stack")));
                    }
                    _testServer.NotifySomeChange();
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in TestServerConnectionHandler message: " + message);
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 5
0
 public void OnClose(ILongPollingConnection connection)
 {
     _testServer.Clients.TryRemove(this, out var _);
     _testServer.NotifySomeChange();
 }
Exemplo n.º 6
0
 public void OnConnect(ILongPollingConnection connection)
 {
     _testServer.Clients.TryAdd(this, this);
     _url        = _testServer.Url;
     _connection = connection;
 }
Exemplo n.º 7
0
        public void OnMessage(ILongPollingConnection connection, string message, JToken data)
        {
            try
            {
                switch (message)
                {
                case "newClient":
                {
                    if (_verbose)
                    {
                        _logger.Info($"New Test Client: {data.Value<string>("userAgent")}");
                    }
                    var client = UAParser.Parser.GetDefault().Parse(data.Value <string>("userAgent"));
                    lock (_lock)
                    {
                        _userAgent = client.ToString();
                        if (_url != null)
                        {
                            DoStart();
                        }
                        else
                        {
                            _connection.Send("wait", null);
                        }
                    }

                    _testServer.NotifySomeChange();
                    break;
                }

                case "wholeStart":
                {
                    if (_verbose)
                    {
                        _logger.Info($"wholeStart tests:{(int)data}");
                    }
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        _curResults.TotalTests = (int)data;
                        _suiteId = 0;
                        if (_suiteStack == null)
                        {
                            _suiteStack = new Stack <SuiteOrTest>();
                            _suiteStack.Push(_curResults);
                        }
                    }

                    _testServer.NotifyTestingStarted();
                    _testServer.NotifySomeChange();
                    break;
                }

                case "wholeDone":
                {
                    if (_verbose)
                    {
                        _logger.Info($"wholeDone duration:{((double)data):f2}");
                    }
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        _curResults.Duration = (double)data;
                        _curResults.Running  = false;
                        _oldResults          = _curResults;
                        _curResults          = null;
                        _suiteStack          = null;
                    }

                    _testServer.NotifyFinishedResults(_oldResults);
                    _testServer.NotifySomeChange();
                    break;
                }

                case "suiteStart":
                {
                    if (_verbose)
                    {
                        _logger.Info($"suiteStart {(string)data}");
                    }
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var suite = new SuiteOrTest
                        {
                            Id       = ++_suiteId,
                            ParentId = _suiteStack.Peek().Id,
                            Name     = (string)data,
                            Nested   = new List <SuiteOrTest>(),
                            Duration = 0,
                            Failure  = false,
                            IsSuite  = true,
                            Failures = new List <MessageAndStack>(),
                            Skipped  = false,
                            Logs     = new List <MessageAndStack>()
                        };
                        _suiteStack.Peek().Nested.Add(suite);
                        _suiteStack.Push(suite);
                    }

                    _testServer.NotifySomeChange();
                    break;
                }

                case "suiteDone":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var suite = _suiteStack.Pop();
                        suite.Duration = data.Value <double>("duration");
                        if (_verbose)
                        {
                            _logger.Info($"suiteDone {suite.Name} {suite.Duration:f2}");
                        }
                        suite.Failures.AddRange(ConvertFailures(data.Value <JArray>("failures")));
                        if (suite.Failures.Count > 0)
                        {
                            _curResults.SuitesFailed += suite.Failures.Count;
                            suite.Failure             = true;
                            _logger.Error(
                                $"suite {suite.Name} in between test failures\n{string.Join('\n', suite.Failures.Select(f => f.Message + "\n  " + string.Join("\n  ", f.Stack)))}");
                            foreach (var s in _suiteStack)
                            {
                                s.Failure = true;
                            }
                        }
                    }

                    _testServer.NotifySomeChange();
                    break;
                }

                case "testStart":
                {
                    if (_verbose)
                    {
                        _logger.Info("testStart " + data.Value <string>("name"));
                    }
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var test = new SuiteOrTest
                        {
                            Id       = ++_suiteId,
                            ParentId = _suiteStack.Peek().Id,
                            Name     = data.Value <string>("name"),
                            Stack    = ConvertMessageAndStack("", data.Value <string>("stack")).Stack
                                       .Where(f => f.FileName != "bundle.js").ToList(),
                            Nested   = null,
                            Duration = 0,
                            Failure  = false,
                            IsSuite  = false,
                            Failures = new List <MessageAndStack>(),
                            Skipped  = false,
                            Logs     = new List <MessageAndStack>()
                        };
                        _suiteStack.Peek().Nested.Add(test);
                        _suiteStack.Push(test);
                    }

                    _testServer.NotifySomeChange();
                    break;
                }

                case "testDone":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var test = _suiteStack.Pop();
                        test.Duration = data.Value <double>("duration");
                        test.Failures.AddRange(ConvertFailures(data.Value <JArray>("failures")));
                        _curResults.TestsFinished++;
                        var status = data.Value <string>("status");
                        if (_verbose)
                        {
                            _logger.Info("testDone " + test.Name + " " + status);
                        }
                        if (status == "passed")
                        {
                        }
                        else if (status == "skipped" || status == "pending" || status == "disabled" || status == "excluded")
                        {
                            _curResults.TestsSkipped++;
                            test.Skipped = true;
                        }
                        else
                        {
                            _curResults.TestsFailed++;
                            test.Failure = true;
                            foreach (var s in _suiteStack)
                            {
                                s.Failure = true;
                            }
                        }
                    }

                    _testServer.NotifySomeChange();
                    break;
                }

                case "consoleLog":
                {
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        if (_suiteStack == null)
                        {
                            break;
                        }
                        var test = _suiteStack.Peek();
                        test.Logs.Add(ConvertMessageAndStack(data.Value <string>("message"),
                                                             data.Value <string>("stack")));
                    }

                    _testServer.NotifySomeChange();
                    break;
                }

                case "onerror":
                {
                    if (_verbose)
                    {
                        _logger.Error("onerror " + data);
                    }
                    lock (_lock)
                    {
                        if (_curResults == null)
                        {
                            break;
                        }
                        _suiteId    = 0;
                        _suiteStack = new Stack <SuiteOrTest>();
                        _suiteStack.Push(_curResults);
                        _curResults.Failures.Add(ConvertMessageAndStack(data.Value <string>("message"), data.Value <string>("stack")));
                        _logger.Error("Test onerror " + _curResults.Failures[^ 1].Message);