Example #1
0
        public void BraceCompletionsE2E()
        {
            using (var solution = BasicProject.Generate().ToVs()) {
                string folderName = NodejsFolderNode.AppendLabel("SomeFolder", FolderContentType.Node);
                var    server     = solution.OpenItem("Require", folderName, "baz.js");

                // Test '('
                Keyboard.Type("require(");
                server.WaitForText("require()");

                // Test '"'
                Keyboard.Type("\"");
                server.WaitForText("require(\"\")");

                // Test step over
                Keyboard.Type("\")");
                server.WaitForText("require(\"\")");

                // Complete this line and attempt '{'
                Keyboard.Type(";\nfunction a(b) {");
                server.WaitForText("require(\"\");\r\nfunction a(b) {}");

                // Verify both nested completions and '[' as well as '''
                Keyboard.Type("\nvar arr = ['elem\\'ent1', 'element2");
                server.WaitForText("require(\"\");\r\nfunction a(b) {\r\n    var arr = ['elem\\'ent1', 'element2']\r\n}");

                Keyboard.Type("'];");
                server.WaitForText("require(\"\");\r\nfunction a(b) {\r\n    var arr = ['elem\\'ent1', 'element2'];\r\n}");

                // Verify typeover
                Keyboard.Type("\n}");
                server.WaitForText("require(\"\");\r\nfunction a(b) {\r\n    var arr = ['elem\\'ent1', 'element2'];\r\n}");
            }
        }
Example #2
0
        public void BraceCompletionsBasic()
        {
            using (var solution = BasicProject.Generate().ToVs()) {
                string folderName = NodejsFolderNode.AppendLabel("SomeFolder", FolderContentType.Node);
                var    server     = solution.OpenItem("Require", folderName, "baz.js");

                // Test '('
                Keyboard.Type("(");
                server.WaitForText("()");
            }
        }
Example #3
0
        public void BraceCompletionTerminatesOnEscapedQuoteInLiteralAndDoesntStartAgain()
        {
            using (var solution = BasicProject.Generate().ToVs()) {
                string folderName = NodejsFolderNode.AppendLabel("SomeFolder", FolderContentType.Node);
                var    server     = solution.OpenItem("Require", folderName, "baz.js");

                // Verify that when adding an escaped double quote to a literal that we don't try to start
                // a new brace completion on close of the string literal.
                Keyboard.Type("var a = \"some\\\"text");
                server.WaitForText("var a = \"some\\\"text");

                Keyboard.Type("\"");
                server.WaitForText("var a = \"some\\\"text\"");
            }
        }
Example #4
0
        public void BraceCompletionDoesNotOccurInCommentsOrLiterals()
        {
            using (var solution = BasicProject.Generate().ToVs()) {
                string folderName = NodejsFolderNode.AppendLabel("SomeFolder", FolderContentType.Node);
                var    server     = solution.OpenItem("Require", folderName, "baz.js");

                // Verify that a comment gets no completions brace causes nothing if it has no start.
                Keyboard.Type("// '");
                server.WaitForText("// '");

                // Verify that inside strings no extra completions happen
                Keyboard.Type("\nconsole.log(\"'");
                server.WaitForText("// '\r\nconsole.log(\"'\")");

                Keyboard.Type("\", '{");
                server.WaitForText("// '\r\nconsole.log(\"'\", '{')");
            }
        }
        public void TestClientServerIntelliSenseModes()
        {
            string
                solutionLabel                       = "Solution 'ClientServerCode' (1 project)",
                projectLabel                        = "ClientServerCode",
                nodeDirectoryLabel                  = NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node),
                nodeSubDirectoryLabel               = NodejsFolderNode.AppendLabel("NodeSubDirectory", FolderContentType.Node),
                browserDirectoryLabel               = NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Browser),
                emptyBrowserSubDirectoryLabel       = "BrowserSubDirectory",
                browserSubDirectoryLabel            = NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Browser),
                mixedDirectoryLabel                 = NodejsFolderNode.AppendLabel("MixedDirectory", FolderContentType.Mixed),
                mixedDirectoryBrowserDirectoryLabel = NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Browser),
                mixedDirectoryNodeDirectoryLabel    = NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node),
                browserCodeLabel                    = "browserCode.js",
                mixedDirectoryRenamedLabel          = NodejsFolderNode.AppendLabel("MixedDirectoryRenamed", FolderContentType.Mixed);

            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\ClientServerCode\ClientServerCode.sln");

                using (new NodejsOptionHolder(NodejsPackage.Instance.GeneralOptionsPage, "ShowBrowserAndNodeLabels", true)) {
                    // Wait until project is loaded
                    var solutionExplorer = app.OpenSolutionExplorer();

                    solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        "app.js");

                    var nodejsProject = app.GetProject("ClientServerCode").GetNodejsProject();

                    var projectNode = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel);

                    var browserDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserDirectory,
                        "Browser directories should be labeled as such. Could not find " + browserDirectoryLabel);

                    var browserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        emptyBrowserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserSubDirectory,
                        "Project initialization: could not find " + emptyBrowserSubDirectoryLabel);

                    var nodeDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        nodeDirectoryLabel
                        );
                    Assert.IsNotNull(
                        nodeDirectory,
                        "Node directories should be labeled as such. Could not find " + nodeDirectoryLabel);

                    var nodeSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        nodeDirectoryLabel,
                        nodeSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        nodeSubDirectory,
                        "Project initialization: could not find " + nodeSubDirectoryLabel);

                    projectNode.Select();
                    using (var newItem = NewItemDialog.FromDte(app)) {
                        newItem.FileName = "newItem.js";
                        newItem.OK();
                    }

                    Assert.AreEqual(
                        "Compile",
                        nodejsProject.GetItemType("newItem.js"),
                        "Top level files should be set to item type 'Compile'");

                    Keyboard.Type("process.");
                    Keyboard.Type(Keyboard.CtrlSpace.ToString());

                    using (var session = app.GetDocument(Path.Combine(nodejsProject.ProjectHome, @"newItem.js")).WaitForSession <ICompletionSession>()) {
                        var completions = session.Session.CompletionSets.First().Completions.Select(x => x.InsertionText);
                        Assert.IsTrue(
                            completions.Contains("env"),
                            "New documents of the node type should open with default VS editor"
                            );
                    }

                    browserSubDirectory.Select();
                    using (var newBrowserItem = NewItemDialog.FromDte(app)) {
                        newBrowserItem.FileName = "newBrowserItem.js";
                        newBrowserItem.OK();
                    }

                    Keyboard.Type("document.");
                    System.Threading.Thread.Sleep(2000);
                    Keyboard.Type(Keyboard.CtrlSpace.ToString());

                    using (var session = app.GetDocument(Path.Combine(nodejsProject.ProjectHome, @"BrowserDirectory\browserSubDirectory\newBrowserItem.js")).WaitForSession <ICompletionSession>()) {
                        var completions = session.Session.CompletionSets.First().Completions.Select(x => x.InsertionText);
                        Assert.IsTrue(
                            completions.Contains("body"),
                            "New documents of the browser type should open with default VS editor"
                            );
                    }

                    browserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserSubDirectory,
                        "Folder label was not updated to " + browserSubDirectoryLabel);

                    var newBrowserItemFile = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel,
                        "newBrowserItem.js"
                        );
                    Assert.AreEqual(
                        "Content",
                        nodejsProject.GetItemType(@"BrowserDirectory\BrowserSubDirectory\newBrowserItem.js"),
                        "Adding a javascript file to a 'browser' directory should set the item type as Content.");

                    var mixedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryLabel
                        );
                    Assert.IsNotNull(
                        mixedDirectory,
                        "Folder with mixed browser/node content should be specified as such. Could not find: " + mixedDirectoryLabel);

                    nodeDirectory.Select();
                    using (var newTypeScriptItem = NewItemDialog.FromDte(app)) {
                        newTypeScriptItem.FileName = "newTypeScriptItem.ts";
                        newTypeScriptItem.OK();
                    }

                    Assert.AreEqual(
                        "TypeScriptCompile",
                        nodejsProject.GetItemType(@"NodeDirectory\newTypeScriptItem.ts"),
                        "Non-javascript files should retain their content type.");

                    var newBrowserItemNode = nodejsProject.FindNodeByFullPath(
                        Path.Combine(nodejsProject.ProjectHome, @"BrowserDirectory\BrowserSubDirectory\newBrowserItem.js")
                        );

                    newBrowserItemNode.ExcludeFromProject();
                    var excludedBrowserItem = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        emptyBrowserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        emptyBrowserSubDirectoryLabel,
                        "Label should be removed when there are no included javascript files the directory. Could not find " + emptyBrowserSubDirectoryLabel);

                    (newBrowserItemNode as NodejsFileNode).IncludeInProject(false);
                    var includedBrowserItem = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        includedBrowserItem,
                        "Label should be added when a javascript file is included in the directory. Could not find " + browserSubDirectoryLabel);

                    var mixedDirectoryNode = app.GetProject("ClientServerCode").GetNodejsProject().FindNodeByFullPath(
                        Path.Combine(nodejsProject.ProjectHome, @"MixedDirectory\"));

                    System.Threading.Thread.Sleep(2000);
                    mixedDirectory.Select();
                    Keyboard.PressAndRelease(Key.F2);
                    Keyboard.Type("MixedDirectoryRenamed");
                    Keyboard.PressAndRelease(Key.Enter);

                    mixedDirectoryNode.ExpandItem(EXPANDFLAGS.EXPF_ExpandFolderRecursively);
                    var renamedMixedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryBrowserDirectoryLabel,
                        browserCodeLabel
                        );

                    Assert.IsNotNull(
                        renamedMixedDirectory,
                        "Renaming mixed directory failed: could not find " + browserCodeLabel);

                    newBrowserItemNode.ItemNode.ItemTypeName = "Compile";

                    var nodeBrowserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Mixed),
                        NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Node)
                        );
                    Assert.IsNotNull(
                        nodeBrowserSubDirectory,
                        "Changing the item type should change the directory label. Could not find " +
                        NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Node)
                        );

                    var nodeDirectoryNode = app.GetProject("ClientServerCode").GetNodejsProject().FindNodeByFullPath(
                        Path.Combine(app.GetProject("ClientServerCode").GetNodejsProject().ProjectHome,
                                     @"NodeDirectory\"));
                    (nodeDirectoryNode as NodejsFolderNode).SetItemTypeRecursively(VSLangProj.prjBuildAction.prjBuildActionContent);

                    Assert.AreEqual(
                        "Content",
                        nodejsProject.GetItemType(@"NodeDirectory\NodeSubDirectory\nodeCode.js"),
                        "nodeCode.js file should be marked as content after recursively setting directory contents as Content."
                        );
                    Assert.AreEqual(
                        "TypeScriptCompile",
                        nodejsProject.GetItemType(@"NodeDirectory\newTypeScriptItem.ts"),
                        "Only javascript file item types should change when marking item types recursively."
                        );

                    var fromPoint = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryNodeDirectoryLabel
                        ).GetClickablePoint();

                    var toPoint = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryBrowserDirectoryLabel
                        ).GetClickablePoint();

                    Mouse.MoveTo(fromPoint);
                    Mouse.Down(MouseButton.Left);

                    Mouse.MoveTo(toPoint);
                    Mouse.Up(MouseButton.Left);

                    var draggedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Mixed),
                        NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node)
                        );
                    Assert.IsNotNull(
                        draggedDirectory,
                        "Labels not properly updated after dragging and dropping directory."
                        );
                }
            }
        }