예제 #1
0
        public List <NodejsTestInfo> FindTests(IEnumerable <string> testFiles,
                                               string nodeExe,
                                               IMessageLogger logger,
                                               string workingDirectory)
        {
            string testInfo           = string.Empty;
            string discoverResultFile = Path.GetTempFileName();

            try {
                string stdout = EvaluateJavaScript(nodeExe, string.Join(";", testFiles), discoverResultFile, logger, workingDirectory);
                if (!String.IsNullOrWhiteSpace(stdout))
                {
                    IEnumerable <String> stdoutLines = stdout.Split(new string[] { Environment.NewLine },
                                                                    StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("NTVS_ERROR:")).Select(s => s.Trim().Remove(0, 11));

                    if (stdoutLines != null && stdoutLines.Count() > 0)
                    {
                        foreach (string s in stdoutLines)
                        {
                            logger.SendMessage(TestMessageLevel.Error, s);
                        }
                        //There was an error during detection, return an empty set
                        return(new List <NodejsTestInfo>());
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    try {
                        testInfo = File.ReadAllText(discoverResultFile);
                        break;
                    } catch (IOException) {
                        //We took an error processing the file.  Wait a few and try again
                        Thread.Sleep(500);
                    }
                }
            } finally {
                try {
                    File.Delete(discoverResultFile);
                } catch (Exception) { //
                    //Unable to delete for some reason
                    //We leave the file behind in this case, its in TEMP so eventually OS will clean up
                }
            }

            List <NodejsTestInfo> testCases       = new List <NodejsTestInfo>();
            List <DiscoveredTest> discoveredTests = (List <DiscoveredTest>)JsonConvert.DeserializeObject(testInfo, typeof(List <DiscoveredTest>));

            if (discoveredTests != null)
            {
                foreach (DiscoveredTest discoveredTest in discoveredTests)
                {
                    var            line   = discoveredTest.Line + 1;
                    var            column = discoveredTest.Column + 1;
                    NodejsTestInfo test   = new NodejsTestInfo(discoveredTest.File, discoveredTest.Test, Name, line, column);
                    testCases.Add(test);
                }
            }
            return(testCases);
        }
예제 #2
0
        public void ConstructFromQualifiedName_ThrowOnInValidInput() {
            //Arrange
            string badDummy = "c:\\dummy.js::dummy::dumm2::test1";

            //Act
            NodejsTestInfo testInfo = new NodejsTestInfo(badDummy);

            //Assert: N/A
        }
예제 #3
0
        public void ConstructFullyQualifiedName_ValidInput() {
            //Arrange
            string testFile = "c:\\dummyWhatever.js";
            string testName = "myMochaTest";
            string testFramework = "mocha";

            //Act
            NodejsTestInfo testInfo = new NodejsTestInfo(testFile, testName, testFramework, 0, 0);
            //Assert
            string expected = testFile + "::" + testName + "::" + testFramework;
            Assert.AreEqual(expected, testInfo.FullyQualifiedName);
            Assert.AreEqual(testName, testInfo.TestName);
            Assert.AreEqual(testFramework, testInfo.TestFramework);
            Assert.AreEqual(testFile, testInfo.ModulePath);
            Assert.AreEqual(testName, testInfo.TestName);
        }
        public List<NodejsTestInfo> FindTests(IEnumerable<string> testFiles,
            string nodeExe,
            IMessageLogger logger, 
            string workingDirectory) {

            string testInfo = string.Empty;
            string discoverResultFile = Path.GetTempFileName();
            try {

                string stdout = EvaluateJavaScript(nodeExe, string.Join(";", testFiles), discoverResultFile, logger, workingDirectory);
                if (!String.IsNullOrWhiteSpace(stdout)) {
                    IEnumerable<String> stdoutLines = stdout.Split(new string[] {Environment.NewLine},
                        StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("NTVS_ERROR:")).Select(s => s.Trim().Remove(0,11));

                    if (stdoutLines != null && stdoutLines.Count() > 0) {
                        foreach (string s in stdoutLines) {
                            logger.SendMessage(TestMessageLevel.Error, s);
                        }
                        //There was an error during detection, return an empty set
                        return new List<NodejsTestInfo>();
                    }
                }

                for (int i = 0; i < 4; i++) {
                    try {
                        testInfo = File.ReadAllText(discoverResultFile);
                        break;
                    } catch (IOException) {
                        //We took an error processing the file.  Wait a few and try again
                        Thread.Sleep(500);
                    }
                }
            } finally {
                try {
                    File.Delete(discoverResultFile);
                } catch (Exception) { //
                    //Unable to delete for some reason
                    //We leave the file behind in this case, its in TEMP so eventually OS will clean up
                }
            }

            List<NodejsTestInfo> testCases = new List<NodejsTestInfo>();
            List<DiscoveredTest> discoveredTests = (List<DiscoveredTest>)JsonConvert.DeserializeObject(testInfo, typeof(List<DiscoveredTest>));
            if (discoveredTests != null) {
                foreach (DiscoveredTest discoveredTest in discoveredTests) {
                    var line = discoveredTest.Line + 1;
                    var column = discoveredTest.Column + 1;
                    NodejsTestInfo test = new NodejsTestInfo(discoveredTest.File, discoveredTest.Test, Name, line, column);
                    testCases.Add(test);
                }
            }
            return testCases;
        }
예제 #5
0
        private void RunTestCase(VisualStudioApp app, IFrameworkHandle frameworkHandle, IRunContext runContext, TestCase test, Dictionary<string, NodejsProjectSettings> sourceToSettings) {
            var testResult = new TestResult(test);
            frameworkHandle.RecordStart(test);
            testResult.StartTime = DateTimeOffset.Now;
            NodejsProjectSettings settings;
            if (!sourceToSettings.TryGetValue(test.Source, out settings)) {
                sourceToSettings[test.Source] = settings = LoadProjectSettings(test.Source);
            }
            if (settings == null) {
                frameworkHandle.SendMessage(
                    TestMessageLevel.Error,
                    "Unable to determine interpreter to use for " + test.Source);
                RecordEnd(
                    frameworkHandle,
                    test,
                    testResult,
                    null,
                    "Unable to determine interpreter to use for " + test.Source,
                    TestOutcome.Failed);
                return;
            }

            NodejsTestInfo testInfo = new NodejsTestInfo(test.FullyQualifiedName);
            List<string> args = new List<string>();
            int port = 0;
            if (runContext.IsBeingDebugged && app != null) {
                app.GetDTE().Debugger.DetachAll();
                args.AddRange(GetDebugArgs(settings, out port));
            }

            var workingDir = Path.GetDirectoryName(CommonUtils.GetAbsoluteFilePath(settings.WorkingDir, testInfo.ModulePath));
            args.AddRange(GetInterpreterArgs(test, workingDir, settings.ProjectRootDir));

            //Debug.Fail("attach debugger");
            if (!File.Exists(settings.NodeExePath)) {
                frameworkHandle.SendMessage(TestMessageLevel.Error, "Interpreter path does not exist: " + settings.NodeExePath);
                return;
            }
            lock (_syncObject) {
                _nodeProcess = ProcessOutput.Run(
                                        settings.NodeExePath,
                                        args,
                                        workingDir,
                                        null,
                                        false,
                                        null,
                                        false);

#if DEBUG
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "cd " + workingDir);
                frameworkHandle.SendMessage(TestMessageLevel.Informational, _nodeProcess.Arguments);
#endif

                _nodeProcess.Wait(TimeSpan.FromMilliseconds(500));
                if (runContext.IsBeingDebugged && app != null) {
                    try {
                        //the '#ping=0' is a special flag to tell VS node debugger not to connect to the port,
                        //because a connection carries the consequence of setting off --debug-brk, and breakpoints will be missed.
                        string qualifierUri = string.Format("tcp://localhost:{0}#ping=0", port);
                        while (!app.AttachToProcess(_nodeProcess, NodejsRemoteDebugPortSupplierUnsecuredId, qualifierUri)) {
                            if (_nodeProcess.Wait(TimeSpan.FromMilliseconds(500))) {
                                break;
                            }
                        }
#if DEBUG
                    } catch (COMException ex) {
                        frameworkHandle.SendMessage(TestMessageLevel.Error, "Error occurred connecting to debuggee.");
                        frameworkHandle.SendMessage(TestMessageLevel.Error, ex.ToString());
                        KillNodeProcess();
                    }
#else
                    } catch (COMException) {
                        frameworkHandle.SendMessage(TestMessageLevel.Error, "Error occurred connecting to debuggee.");
                        KillNodeProcess();
                    }
#endif
                }
            }
예제 #6
0
 private IEnumerable<string> GetInterpreterArgs(TestCase test, string workingDir, string projectRootDir) {
     TestFrameworks.NodejsTestInfo testInfo = new TestFrameworks.NodejsTestInfo(test.FullyQualifiedName);
     TestFrameworks.FrameworkDiscover discover = new TestFrameworks.FrameworkDiscover();
     return discover.Get(testInfo.TestFramework).ArgumentsToRunTests(testInfo.TestName, testInfo.ModulePath, workingDir, projectRootDir);
 }
예제 #7
0
 private IEnumerable <string> GetInterpreterArgs(TestCase test, string workingDir, string projectRootDir)
 {
     TestFrameworks.NodejsTestInfo    testInfo = new TestFrameworks.NodejsTestInfo(test.FullyQualifiedName);
     TestFrameworks.FrameworkDiscover discover = new TestFrameworks.FrameworkDiscover();
     return(discover.Get(testInfo.TestFramework).ArgumentsToRunTests(testInfo.TestName, testInfo.ModulePath, workingDir, projectRootDir));
 }
예제 #8
0
        public IEnumerable <NodejsTestInfo> FindTests(IEnumerable <string> testFiles,
                                                      string nodeExe,
                                                      IMessageLogger logger,
                                                      string projectRoot)
        {
            var testInfo           = string.Empty;
            var discoverResultFile = Path.GetTempFileName();

            // Create a temp file with the list of test files.
            var testFilesString   = string.Join(";", testFiles);
            var testFilesListFile = Path.GetTempFileName();

            File.WriteAllText(testFilesListFile, testFilesString, System.Text.Encoding.UTF8);

            try
            {
                var stdout = EvaluateJavaScript(nodeExe, testFilesListFile, discoverResultFile, logger, projectRoot);
                if (!string.IsNullOrWhiteSpace(stdout))
                {
                    var stdoutLines = stdout.Split(new[] { Environment.NewLine },
                                                   StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("NTVS_ERROR:")).Select(s => s.Trim().Remove(0, 11));

                    if (stdoutLines != null && stdoutLines.Count() > 0)
                    {
                        foreach (var s in stdoutLines)
                        {
                            logger.SendMessage(TestMessageLevel.Error, s);
                        }
                        //There was an error during detection, return an empty set
                        return(Enumerable.Empty <NodejsTestInfo>());
                    }
                }

                for (var i = 0; i < 4; i++)
                {
                    try
                    {
                        testInfo = File.ReadAllText(discoverResultFile);
                        break;
                    }
                    catch (IOException)
                    {
                        //We took an error processing the file.  Wait a few and try again
                        Thread.Sleep(500);
                    }
                }
            }
            finally
            {
#if !DEBUG
                try
                {
                    File.Delete(discoverResultFile);
                    File.Delete(testFilesListFile);
                }
                catch (Exception)
                {
                    //Unable to delete for some reason
                    //We leave the file behind in this case, its in TEMP so eventually OS will clean up
                }
#endif
            }

            var testCases       = new List <NodejsTestInfo>();
            var discoveredTests = JsonConvert.DeserializeObject <List <DiscoveredTest> >(testInfo);
            if (discoveredTests != null)
            {
                foreach (var discoveredTest in discoveredTests)
                {
                    var line   = discoveredTest.Line + 1;
                    var column = discoveredTest.Column + 1;
                    var test   = new NodejsTestInfo(discoveredTest.File, discoveredTest.Test, this.Name, line, column, projectRoot);
                    testCases.Add(test);
                }
            }
            return(testCases);
        }