forked from eclipse-wildwebdeveloper/wildwebdeveloper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vue Support - eclipse-wildwebdeveloper#83
- Loading branch information
Showing
26 changed files
with
2,126 additions
and
1 deletion.
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Dawid Pakuła and others. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Dawid Pakuła <[email protected]> - initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.wildwebdeveloper.tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IFolder; | ||
import org.eclipse.core.resources.IMarker; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.jface.text.IDocument; | ||
import org.eclipse.jface.text.contentassist.ICompletionProposal; | ||
import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.editors.text.TextEditor; | ||
import org.eclipse.ui.ide.IDE; | ||
import org.eclipse.ui.tests.harness.util.DisplayHelper; | ||
import org.eclipse.wildwebdeveloper.embedder.node.NodeJSManager; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestVue { | ||
static IProject project; | ||
static IFolder componentFolder; | ||
|
||
@BeforeAll | ||
public static void setUp() throws Exception { | ||
AllCleanRule.closeIntro(); | ||
AllCleanRule.enableLogging(); | ||
|
||
project = Utils.provisionTestProject("vue-app"); | ||
ProcessBuilder builder = new ProcessBuilder(NodeJSManager.getNpmLocation().getAbsolutePath(), "install", | ||
"--no-bin-links", "--ignore-scripts").directory(project.getLocation().toFile()); | ||
Process process = builder.start(); | ||
System.out.println(builder.command().toString()); | ||
String result = new BufferedReader(new InputStreamReader(process.getErrorStream())).lines() | ||
.collect(Collectors.joining("\n")); | ||
System.out.println("Error Stream: >>>\n" + result + "\n<<<"); | ||
|
||
result = new BufferedReader(new InputStreamReader(process.getInputStream())).lines() | ||
.collect(Collectors.joining("\n")); | ||
System.out.println("Output Stream: >>>\n" + result + "\n<<<"); | ||
|
||
assertEquals(0, process.waitFor(), "npm install didn't complete property"); | ||
|
||
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); | ||
assertTrue(project.exists()); | ||
componentFolder = project.getFolder("src").getFolder("components"); | ||
assertTrue(componentFolder.exists()); | ||
} | ||
|
||
@BeforeEach | ||
public void setUpTestCase() { | ||
AllCleanRule.enableLogging(); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDown() throws Exception { | ||
new AllCleanRule().afterEach(null); | ||
} | ||
|
||
@Test | ||
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 | ||
assertTrue(new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
try { | ||
return Arrays | ||
.stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true, | ||
IResource.DEPTH_ZERO)) | ||
.anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("never read")); | ||
} catch (CoreException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
} | ||
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000), | ||
"Diagnostic not published in standalone component file"); | ||
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); | ||
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor(); | ||
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor), | ||
document.get().indexOf(" }}")); | ||
Optional<ICompletionProposal> proposal = Arrays.stream(proposals) | ||
.filter(item -> item.getDisplayString().equals("appParameter")).findFirst(); | ||
|
||
assertTrue(proposal.isPresent(), "Proposal not exists"); | ||
proposal.get().apply(document); | ||
|
||
assertTrue(document.get().contains("{{ appParameter }}"), "Incorrect completion insertion"); | ||
|
||
editor.close(false); | ||
} | ||
|
||
@Test | ||
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 | ||
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"); | ||
assertTrue(new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
IMarker[] markers; | ||
try { | ||
markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO); | ||
return Arrays.stream(markers).anyMatch( | ||
marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("Element is missing end tag.")); | ||
} catch (CoreException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
} | ||
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000), | ||
"No error found on erroneous HTML component file"); | ||
// test completion | ||
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor(); | ||
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor), | ||
document.get().indexOf("<only-start>") + " <only-start>".length() - 1); | ||
proposals[0].apply(document); | ||
assertEquals(new String(componentFolder.getFile("HelloWorldCorrect.vue").getContents().readAllBytes()).trim(), | ||
document.get().trim(), "Incorrect completion insertion"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.DS_Store | ||
node_modules | ||
/dist | ||
|
||
|
||
# local env files | ||
.env.local | ||
.env.*.local | ||
|
||
# Log files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
5 changes: 5 additions & 0 deletions
5
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/babel.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
presets: [ | ||
'@vue/cli-plugin-babel/preset' | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/jsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "esnext", | ||
"baseUrl": "./", | ||
"moduleResolution": "node", | ||
"paths": { | ||
"@/*": [ | ||
"src/*" | ||
] | ||
}, | ||
"lib": [ | ||
"esnext", | ||
"dom", | ||
"dom.iterable", | ||
"scripthost" | ||
] | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "vue-app", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"serve": "vue-cli-service serve", | ||
"build": "vue-cli-service build", | ||
"lint": "vue-cli-service lint" | ||
}, | ||
"dependencies": { | ||
"core-js": "^3.8.3", | ||
"vue": "^3.2.13" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.16", | ||
"@babel/eslint-parser": "^7.12.16", | ||
"@vue/cli-plugin-babel": "~5.0.0", | ||
"@vue/cli-plugin-eslint": "~5.0.0", | ||
"@vue/cli-service": "~5.0.0", | ||
"eslint": "^7.32.0", | ||
"eslint-plugin-vue": "^8.0.3" | ||
}, | ||
"eslintConfig": { | ||
"root": true, | ||
"env": { | ||
"node": true | ||
}, | ||
"extends": [ | ||
"plugin:vue/vue3-essential", | ||
"eslint:recommended" | ||
], | ||
"parserOptions": { | ||
"parser": "@babel/eslint-parser" | ||
}, | ||
"rules": {} | ||
}, | ||
"browserslist": [ | ||
"> 1%", | ||
"last 2 versions", | ||
"not dead", | ||
"not ie 11" | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/public/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang=""> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
</head> | ||
<body> | ||
<noscript> | ||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> | ||
</noscript> | ||
<div id="app"></div> | ||
<!-- built files will be auto injected --> | ||
</body> | ||
</html> |
36 changes: 36 additions & 0 deletions
36
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/src/App.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<HelloWorld msg="Welcome to Your Vue.js App"/> | ||
{{ appPar }} | ||
</template> | ||
|
||
<script> | ||
import HelloWorld from './components/HelloWorld.vue' | ||
export default { | ||
name: 'App', | ||
components: { | ||
HelloWorld | ||
}, | ||
data() { | ||
return { | ||
appParameter : null | ||
} | ||
}, | ||
methods: { | ||
testMethod(arg) { | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style> | ||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
} | ||
</style> |
29 changes: 29 additions & 0 deletions
29
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/src/components/HelloWorld.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<template> | ||
<div> | ||
<only-start> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
name: 'HelloWorld', | ||
props: { | ||
msg: String | ||
} | ||
} | ||
</script> | ||
<style scoped> | ||
h3 { | ||
margin: 40px 0 0; | ||
} | ||
ul { | ||
list-style-type: none; | ||
padding: 0; | ||
} | ||
li { | ||
display: inline-block; | ||
margin: 0 10px; | ||
} | ||
a { | ||
color: #42b983; | ||
} | ||
</style> |
29 changes: 29 additions & 0 deletions
29
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/src/components/HelloWorldCorrect.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<template> | ||
<div> | ||
<only-start></only-start> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
name: 'HelloWorld', | ||
props: { | ||
msg: String | ||
} | ||
} | ||
</script> | ||
<style scoped> | ||
h3 { | ||
margin: 40px 0 0; | ||
} | ||
ul { | ||
list-style-type: none; | ||
padding: 0; | ||
} | ||
li { | ||
display: inline-block; | ||
margin: 0 10px; | ||
} | ||
a { | ||
color: #42b983; | ||
} | ||
</style> |
4 changes: 4 additions & 0 deletions
4
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/src/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
|
||
createApp(App).mount('#app') |
4 changes: 4 additions & 0 deletions
4
org.eclipse.wildwebdeveloper.tests/testProjects/vue-app/vue.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const { defineConfig } = require('@vue/cli-service') | ||
module.exports = defineConfig({ | ||
transpileDependencies: true | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a copy from https://github.com/vuejs/language-tools/tree/master/packages/vscode-vue/syntaxes/ |
Oops, something went wrong.