Skip to content

Commit

Permalink
Fix #1316 - Vue.JS tests failures
Browse files Browse the repository at this point in the history
  • Loading branch information
zulus committed Sep 11, 2023
1 parent f0f32b0 commit 1f20d13
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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(" }}"));
Expand All @@ -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);
}
Expand All @@ -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 = "<only-start>";
document.set(document.get().replace(tag, tag + "<"));
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
Expand All @@ -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("<only-start>") + " <only-start>".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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<HelloWorld msg="Welcome to Your Vue.js App"/>
{{ appPar }}
{{ this. }}
</template>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public Object getInitializationOptions(URI rootUri) {

try {
URL url = FileLocator.toFileURL(getClass().getResource("/node_modules/typescript/lib"));
System.out.println(new File(url.getPath()).getAbsolutePath());
return Collections.singletonMap("typescript", Collections.singletonMap("tsdk", new File(url.getPath()).getAbsolutePath()));
} catch (IOException e) {
Activator.getDefault().getLog().log(
new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), e.getMessage(), e));
}
return null;
}
Expand Down

0 comments on commit 1f20d13

Please sign in to comment.