11/*******************************************************************************
2- * Copyright (c) 2019 Red Hat Inc. and others.
2+ * Copyright (c) 2019, 2022 Red Hat Inc. and others.
33 *
44 * This program and the accompanying materials are made
55 * available under the terms of the Eclipse Public License 2.0
1616import static org .junit .jupiter .api .Assertions .assertEquals ;
1717import static org .junit .jupiter .api .Assertions .assertTrue ;
1818
19+ import java .io .BufferedReader ;
20+ import java .io .InputStreamReader ;
1921import java .util .Arrays ;
22+ import java .util .stream .Collectors ;
2023
2124import org .eclipse .core .resources .IFile ;
2225import org .eclipse .core .resources .IFolder ;
2528import org .eclipse .core .resources .IResource ;
2629import org .eclipse .core .runtime .CoreException ;
2730import org .eclipse .core .runtime .NullProgressMonitor ;
31+ import org .eclipse .core .runtime .preferences .InstanceScope ;
2832import org .eclipse .jface .text .IDocument ;
2933import org .eclipse .jface .text .contentassist .ICompletionProposal ;
3034import org .eclipse .lsp4e .operations .completion .LSContentAssistProcessor ;
35+ import org .eclipse .ui .IViewReference ;
36+ import org .eclipse .ui .IWorkbenchPage ;
3137import org .eclipse .ui .PlatformUI ;
3238import org .eclipse .ui .editors .text .TextEditor ;
3339import org .eclipse .ui .ide .IDE ;
40+ import org .eclipse .ui .intro .IIntroPart ;
41+ import org .eclipse .ui .preferences .ScopedPreferenceStore ;
3442import org .eclipse .ui .tests .harness .util .DisplayHelper ;
3543import org .eclipse .wildwebdeveloper .embedder .node .NodeJSManager ;
44+ import org .junit .jupiter .api .AfterAll ;
45+ import org .junit .jupiter .api .BeforeAll ;
46+ import org .junit .jupiter .api .BeforeEach ;
3647import org .junit .jupiter .api .Test ;
37- import org .junit .jupiter .api .extension .ExtendWith ;
3848
39- @ ExtendWith (AllCleanRule .class )
4049public class TestAngular {
50+ static IProject project ;
51+ static IFolder appFolder ;
52+
53+ @ BeforeAll
54+ public static void setUp () throws Exception {
55+ // The following is a copy of new AllCleanRule().afterEach(null);`
56+ // excluding a call to clean the projects - we need to share the project
57+ // between the existing testcases
58+ //
59+ IIntroPart intro = PlatformUI .getWorkbench ().getIntroManager ().getIntro ();
60+ if (intro != null ) {
61+ PlatformUI .getWorkbench ().getIntroManager ().closeIntro (intro );
62+ }
63+ IWorkbenchPage activePage = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage ();
64+ for (IViewReference ref : activePage .getViewReferences ()) {
65+ activePage .hideView (ref );
66+ }
67+ enableLogging ();
68+ // End of note
69+
70+ project = Utils .provisionTestProject ("angular-app" );
71+ ProcessBuilder builder = new ProcessBuilder (NodeJSManager .getNpmLocation ().getAbsolutePath (), "install" ,
72+ "--no-bin-links" , "--ignore-scripts" ).directory (project .getLocation ().toFile ());
73+ Process process = builder .start ();
74+ System .out .println (builder .command ().toString ());
75+ String result = new BufferedReader (new InputStreamReader (process .getErrorStream ())).lines ()
76+ .collect (Collectors .joining ("\n " ));
77+ System .out .println ("Error Stream: >>>\n " + result + "\n <<<" );
78+
79+ result = new BufferedReader (new InputStreamReader (process .getInputStream ())).lines ()
80+ .collect (Collectors .joining ("\n " ));
81+ System .out .println ("Output Stream: >>>\n " + result + "\n <<<" );
4182
42- @ Test
43- public void testAngular () throws Exception {
44- IProject project = Utils .provisionTestProject ("angular-app" );
45- Process process = new ProcessBuilder (NodeJSManager .getNpmLocation ().getAbsolutePath (), "install" ,
46- "--no-bin-links" , "--ignore-scripts" ).directory (project .getLocation ().toFile ()).start ();
4783 assertEquals (0 , process .waitFor (), "npm install didn't complete property" );
84+
4885 project .refreshLocal (IResource .DEPTH_INFINITE , new NullProgressMonitor ());
49- IFolder appFolder = project .getFolder ("src" ).getFolder ("app" );
86+ assertTrue (project .exists ());
87+ appFolder = project .getFolder ("src" ).getFolder ("app" );
88+ assertTrue (appFolder .exists ());
89+ }
90+
91+ @ BeforeEach
92+ public void setUpTestCase () {
93+ enableLogging ();
94+ }
95+
96+ @ AfterAll
97+ public static void tearDown () throws Exception {
98+ new AllCleanRule ().afterEach (null );
99+ }
100+
101+ private static void enableLogging () {
102+ ScopedPreferenceStore prefs = new ScopedPreferenceStore (InstanceScope .INSTANCE , "org.eclipse.lsp4e" );
103+ prefs .putValue ("org.eclipse.wildwebdeveloper.angular.file.logging.enabled" , Boolean .toString (true ));
104+ prefs .putValue ("org.eclipse.wildwebdeveloper.jsts.file.logging.enabled" , Boolean .toString (true ));
105+ prefs .putValue ("org.eclipse.wildwebdeveloper.css.file.logging.enabled" , Boolean .toString (true ));
106+ prefs .putValue ("org.eclipse.wildwebdeveloper.html.file.logging.enabled" , Boolean .toString (true ));
107+ prefs .putValue ("org.eclipse.wildwebdeveloper.json.file.logging.enabled" , Boolean .toString (true ));
108+ prefs .putValue ("org.eclipse.wildwebdeveloper.xml.file.logging.enabled" , Boolean .toString (true ));
109+ prefs .putValue ("org.eclipse.wildwebdeveloper.yaml.file.logging.enabled" , Boolean .toString (true ));
110+ prefs .putValue ("org.eclipse.wildwebdeveloper.eslint.file.logging.enabled" , Boolean .toString (true ));
111+ }
50112
113+ @ Test
114+ public void testAngularTs () throws Exception {
51115 IFile appComponentFile = appFolder .getFile ("app.component.ts" );
52116 TextEditor editor = (TextEditor ) IDE
53117 .openEditor (PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage (), appComponentFile );
@@ -67,13 +131,15 @@ protected boolean condition() {
67131 return false ;
68132 }
69133 }
70- // The timeout is increased to 150 seconds due to the slow compilation of an
71- // angular project.
72- }.waitForCondition (PlatformUI .getWorkbench ().getDisplay (), 150000 ),
134+ }.waitForCondition (editor .getSite ().getShell ().getDisplay (), 30000 ),
73135 "Diagnostic not published in standalone component file" );
74136 editor .close (false );
137+ }
75138
76- editor = (TextEditor ) IDE .openEditor (PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage (),
139+ @ Test
140+ public void testAngularHtml () throws Exception {
141+ TextEditor editor = (TextEditor ) IDE .openEditor (
142+ PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage (),
77143 appFolder .getFile ("app.componentWithHtml.ts" ));
78144 DisplayHelper .sleep (4000 ); // Give time for LS to initialize enough before making edit and sending a
79145 // didChange
@@ -94,10 +160,11 @@ protected boolean condition() {
94160 return Arrays .stream (markers )
95161 .anyMatch (marker -> marker .getAttribute (IMarker .MESSAGE , "" ).contains ("not exist" ));
96162 } catch (CoreException e ) {
163+ e .printStackTrace ();
97164 return false ;
98165 }
99166 }
100- }.waitForCondition (editor .getSite ().getShell ().getDisplay (), 150000 ),
167+ }.waitForCondition (editor .getSite ().getShell ().getDisplay (), 30000 ),
101168 "No error found on erroneous HTML component file" );
102169 // test completion
103170 LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor ();
@@ -106,5 +173,4 @@ protected boolean condition() {
106173 proposals [0 ].apply (document );
107174 assertEquals ("<h1>{{title}}</h1>\n " , document .get (), "Incorrect completion insertion" );
108175 }
109-
110176}
0 commit comments