From 659a769c2ddc424d5288ed724958e344ea960b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Paku=C5=82a?= Date: Wed, 6 Sep 2023 12:14:27 +0200 Subject: [PATCH] Fix #1316 - Vue.JS tests failures --- .../wildwebdeveloper/tests/AllCleanRule.java | 2 + .../wildwebdeveloper/tests/TestVue.java | 46 ++++++++++++++----- .../testProjects/vue-app/src/App.vue | 2 +- .../vue/VueLanguageServer.java | 3 +- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/AllCleanRule.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/AllCleanRule.java index 86df897a67..9e8e49b0a6 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/AllCleanRule.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/AllCleanRule.java @@ -81,6 +81,8 @@ public static void enableLogging() { prefs.putValue("org.eclipse.wildwebdeveloper.xml.file.logging.enabled", Boolean.toString(true)); prefs.putValue("org.eclipse.wildwebdeveloper.yaml.file.logging.enabled", Boolean.toString(true)); prefs.putValue("org.eclipse.wildwebdeveloper.eslint.file.logging.enabled", Boolean.toString(true)); + prefs.putValue("org.eclipse.wildwebdeveloper.vue.file.logging.enabled", Boolean.toString(true)); + } @Override diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java index c9f2fec318..acf32e23df 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java @@ -30,6 +30,10 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.lsp4e.LSPEclipseUtils; +import org.eclipse.lsp4e.LanguageServerWrapper; +import org.eclipse.lsp4e.LanguageServersRegistry; +import org.eclipse.lsp4e.LanguageServiceAccessor; import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.editors.text.TextEditor; @@ -86,8 +90,9 @@ void testVueApp() throws Exception { IFile appComponentFile = project.getFile("src/App.vue"); TextEditor editor = (TextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile); - DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a - // didChange + LanguageServerWrapper lsWrapper = LanguageServiceAccessor.getLSWrapper(project, + LanguageServersRegistry.getInstance().getDefinition("org.eclipse.wildwebdeveloper.vue")); + assertTrue(new DisplayHelper() { @Override protected boolean condition() { @@ -104,6 +109,14 @@ protected boolean condition() { }.waitForCondition(editor.getSite().getShell().getDisplay(), 30000), "Diagnostic not published in standalone component file"); IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); + assertTrue(new DisplayHelper() { + + @Override + protected boolean condition() { + return lsWrapper.isActive() && lsWrapper.isConnectedTo(LSPEclipseUtils.toUri(document)) + && lsWrapper.canOperate(project) && lsWrapper.canOperate(document); + } + }.waitForCondition(editor.getSite().getShell().getDisplay(), 30000)); LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor(); ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor), document.get().indexOf(" }}")); @@ -113,7 +126,7 @@ protected boolean condition() { assertTrue(proposal.isPresent(), "Proposal not exists"); proposal.get().apply(document); - assertTrue(document.get().contains("{{ appParameter }}"), "Incorrect completion insertion"); + assertTrue(document.get().contains("{{ this.appParameter }}"), "Incorrect completion insertion"); editor.close(false); } @@ -123,16 +136,14 @@ void testVueTemplate() throws Exception { TextEditor editor = (TextEditor) IDE.openEditor( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), componentFolder.getFile("HelloWorld.vue")); - DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a - // didChange + LanguageServerWrapper lsWrapper = LanguageServiceAccessor.getLSWrapper(project, + LanguageServersRegistry.getInstance().getDefinition("org.eclipse.wildwebdeveloper.vue")); IFile appComponentHTML = componentFolder.getFile("HelloWorld.vue"); editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentHTML); - // Give some time for LS to load - DisplayHelper.sleep(2000); - // then make an edit IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); - document.set(document.get() + "\n"); + String tag = ""; + document.set(document.get().replace(tag, tag + "<")); assertTrue(new DisplayHelper() { @Override protected boolean condition() { @@ -148,12 +159,25 @@ protected boolean condition() { } }.waitForCondition(editor.getSite().getShell().getDisplay(), 30000), "No error found on erroneous HTML component file"); - // test completion + + assertTrue(new DisplayHelper() { + + @Override + protected boolean condition() { + return lsWrapper.isActive() && lsWrapper.isConnectedTo(LSPEclipseUtils.toUri(document)) + && lsWrapper.canOperate(project) && lsWrapper.canOperate(document); + } + }.waitForCondition(editor.getSite().getShell().getDisplay(), 30000)); + LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor(); + + int pos = document.get().indexOf(tag) + tag.length(); ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor), - document.get().indexOf("") + " ".length() - 1); + pos + 1); proposals[0].apply(document); assertEquals(new String(componentFolder.getFile("HelloWorldCorrect.vue").getContents().readAllBytes()).trim(), document.get().trim(), "Incorrect completion insertion"); + + editor.close(false); } } diff --git a/org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/src/App.vue b/org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/src/App.vue index e6842dbe86..c48d69e9cf 100644 --- a/org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/src/App.vue +++ b/org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/src/App.vue @@ -1,6 +1,6 @@