|
3 | 3 | * Copyright IBM Corp. 2026 |
4 | 4 | */ |
5 | 5 |
|
6 | | -import * as path from 'path'; |
7 | | -import { logger } from './utils/testLogger'; |
8 | | -import { EditorView, VSBrowser } from 'vscode-extension-tester'; |
9 | | -import { EditorPage } from './pages/EditorPage'; |
10 | 6 | import * as utils from './utils/testUtils'; |
11 | | -import { expect } from 'chai'; |
12 | | -import { CodeAssistPage } from './pages/CodeAssistPage'; |
13 | | -import { ProblemsPage } from './pages/ProblemsPage'; |
14 | | -import { QuickFixPage } from './pages/QuickFixPage'; |
15 | | -import * as editorUtils from './utils/editorUtils'; |
16 | | - |
17 | | -const HOVER_INITIAL_CONTENT = 'WLP_USER_DIR=./custom-user-dir\nLOG_DIR=./logs\n'; |
18 | | - |
19 | | -const HOVER_TEST_CASES = [ |
20 | | - { |
21 | | - element: 'WLP_USER_DIR', |
22 | | - line: 1, |
23 | | - column: 1, |
24 | | - expectedDoc: 'The user or custom configuration directory that is used to store shared and server-specific configuration. See the path_to_liberty/wlp/README.TXT file for details about shared resource locations. A server configuration is at the %WLP_USER_DIR%/servers/serverName location. The default value is the user directory in the installation directory.', |
| 7 | +import { runConfigFileTestSuite } from './shared/configFileTestSuite'; |
| 8 | + |
| 9 | +runConfigFileTestSuite({ |
| 10 | + suiteTitle: 'Server Env', |
| 11 | + getProjectPath: utils.getMvnProjectPath, |
| 12 | + filePathSegments: ['src', 'main', 'liberty', 'config', 'server.env'], |
| 13 | + tabTitle: 'server.env', |
| 14 | + hoverInitialContent: 'WLP_USER_DIR=./custom-user-dir\nLOG_DIR=./logs\n', |
| 15 | + hoverCases: [ |
| 16 | + { |
| 17 | + element: 'WLP_USER_DIR', |
| 18 | + line: 1, |
| 19 | + column: 1, |
| 20 | + expectedDoc: 'The user or custom configuration directory that is used to store shared and server-specific configuration. See the path_to_liberty/wlp/README.TXT file for details about shared resource locations. A server configuration is at the %WLP_USER_DIR%/servers/serverName location. The default value is the user directory in the installation directory.', |
| 21 | + }, |
| 22 | + { |
| 23 | + element: 'LOG_DIR', |
| 24 | + line: 2, |
| 25 | + column: 1, |
| 26 | + expectedDoc: 'The directory that contains the log file. The default value is %WLP_OUTPUT_DIR%/serverName/logs', |
| 27 | + }, |
| 28 | + ], |
| 29 | + completion: { |
| 30 | + trigger: 'WLP_LOG', |
| 31 | + fullItem: 'WLP_LOGGING_MESSAGE_FORMAT', |
| 32 | + value: 'JSON', |
25 | 33 | }, |
26 | | - { |
27 | | - element: 'LOG_DIR', |
28 | | - line: 2, |
29 | | - column: 1, |
30 | | - expectedDoc: 'The directory that contains the log file. The default value is %WLP_OUTPUT_DIR%/serverName/logs', |
| 34 | + diagnostic: { |
| 35 | + lineToken: 'WLP_LOGGING_MESSAGE_FORMAT', |
| 36 | + validValue: 'JSON', |
| 37 | + diagnosticMessage: 'The value `INVALID` is not valid for the variable `WLP_LOGGING_MESSAGE_FORMAT`.', |
| 38 | + quickFixLabel: 'Replace value with JSON', |
31 | 39 | }, |
32 | | -]; |
33 | | - |
34 | | -describe('Server Env functionality tests for Maven Project', () => { |
35 | | - let serverEnv: EditorPage; |
36 | | - let wait: any; |
37 | | - |
38 | | - before(async function() { |
39 | | - this.timeout(60000); |
40 | | - |
41 | | - logger.info('Setting up Maven server.env tests'); |
42 | | - |
43 | | - await VSBrowser.instance.openResources(utils.getMvnProjectPath()); |
44 | | - await VSBrowser.instance.waitForWorkbench(); |
45 | | - |
46 | | - wait = utils.getWaitHelper(); |
47 | | - |
48 | | - logger.info('Opening server.env file for all tests'); |
49 | | - const serverEnvPath = path.resolve( |
50 | | - utils.getMvnProjectPath(), |
51 | | - 'src', 'main', 'liberty', 'config', 'server.env' |
52 | | - ); |
53 | | - logger.info(`Server.env path: ${serverEnvPath}`); |
54 | | - |
55 | | - serverEnv = await new EditorPage().openFile(serverEnvPath, 'server.env'); |
56 | | - logger.info('Server.env file opened and editor obtained'); |
57 | | - }); |
58 | | - |
59 | | - afterEach(async function() { |
60 | | - if (this.currentTest?.state === 'failed') { |
61 | | - await VSBrowser.instance.driver.takeScreenshot(); |
62 | | - logger.error(`Test failed: ${this.currentTest.title}`); |
63 | | - } |
64 | | - }); |
65 | | - |
66 | | - after(async function() { |
67 | | - this.timeout(10000); |
68 | | - try { |
69 | | - if (serverEnv) { |
70 | | - const currentText = await serverEnv.getEditor().getText(); |
71 | | - try { |
72 | | - await serverEnv.getEditor().selectText(currentText); |
73 | | - await wait.sleep(300); |
74 | | - } catch (selectError) { |
75 | | - // selectText may fail but setText still works |
76 | | - } |
77 | | - await editorUtils.clearEditor(serverEnv.getEditor()); |
78 | | - logger.info('Reset server.env to empty after tests'); |
79 | | - } |
80 | | - } catch (error) { |
81 | | - logger.error('Failed to reset server.env', error); |
82 | | - } |
83 | | - try { |
84 | | - await new EditorView().closeAllEditors(); |
85 | | - logger.info('Closed all editors after test suite'); |
86 | | - } catch (error) { |
87 | | - logger.error('Failed to close editors in after hook', error); |
88 | | - } |
89 | | - utils.copyScreenshotsToProjectFolder('maven'); |
90 | | - }); |
91 | | - |
92 | | - it('Liberty Language Server should initialize', async function() { |
93 | | - this.timeout(60000); |
94 | | - logger.testStart('Liberty Language Server should initialize'); |
95 | | - try { |
96 | | - await utils.waitForLanguageServerInit( |
97 | | - 'Language Support for Liberty', |
98 | | - 'Initialized Liberty Language server', |
99 | | - 60 |
100 | | - ); |
101 | | - logger.testComplete('Liberty Language Server initialized successfully'); |
102 | | - } catch (error) { |
103 | | - logger.testFailed('Liberty Language Server should initialize', error); |
104 | | - throw error; |
105 | | - } |
106 | | - }); |
107 | | - |
108 | | - HOVER_TEST_CASES.forEach(testCase => { |
109 | | - it(`Hover over ${testCase.element} shows Liberty Language Server documentation`, async function() { |
110 | | - this.timeout(30000); |
111 | | - logger.testStart(`Hover over ${testCase.element} shows Liberty Language Server documentation`); |
112 | | - await serverEnv.getEditor().setText(HOVER_INITIAL_CONTENT); |
113 | | - await serverEnv.getEditor().save(); |
114 | | - await wait.sleep(1000); |
115 | | - |
116 | | - try { |
117 | | - const hoverText = await editorUtils.hoverOver(serverEnv.getEditor(), testCase.line, testCase.column, testCase.element); |
118 | | - expect(hoverText).to.not.be.empty; |
119 | | - logger.stepSuccess(3, `Hover widget displayed with Liberty Language Server content for ${testCase.element}`); |
120 | | - |
121 | | - logger.step(4, 'Verifying hover contains expected documentation'); |
122 | | - expect(hoverText).to.include(testCase.expectedDoc); |
123 | | - logger.stepSuccess(4, `Hover text contains expected documentation: "${testCase.expectedDoc}"`); |
124 | | - |
125 | | - logger.testComplete(`Hover over ${testCase.element} shows Liberty Language Server documentation`); |
126 | | - } catch (error) { |
127 | | - logger.testFailed(`Hover over ${testCase.element} shows Liberty Language Server documentation`, error); |
128 | | - throw error; |
129 | | - } |
130 | | - }); |
131 | | - }); |
132 | | - |
133 | | - it('server.env WLP_LOG populates correct WLP_LOGGING_MESSAGE_FORMAT type ahead', async function() { |
134 | | - this.timeout(275000); |
135 | | - logger.testStart('server.env WLP_LOG populates correct WLP_LOGGING_MESSAGE_FORMAT type ahead'); |
136 | | - |
137 | | - try { |
138 | | - logger.step(1, 'Positioning cursor'); |
139 | | - await serverEnv.getEditor().setCursor(3, 1); |
140 | | - |
141 | | - logger.step(2, 'Opening content assist'); |
142 | | - const codeAssist = new CodeAssistPage(); |
143 | | - await codeAssist.insertSnippet(serverEnv, 'WLP_LOG', 'WLP_LOGGING_MESSAGE_FORMAT'); |
144 | | - logger.stepSuccess(2, 'Completion inserted'); |
145 | | - const after = await serverEnv.getEditor().getText(); |
146 | | - expect(after).to.include('WLP_LOGGING_MESSAGE_FORMAT'); |
147 | | - await wait.sleep(1000); |
148 | | - |
149 | | - const lineText = await serverEnv.getEditor().getTextAtLine(3); |
150 | | - await serverEnv.getEditor().setTextAtLine(3, lineText.trimEnd() + '=JSON'); |
151 | | - |
152 | | - await serverEnv.getEditor().save(); |
153 | | - await wait.sleep(500); |
154 | | - |
155 | | - logger.testComplete('server.env WLP_LOG populates correct WLP_LOGGING_MESSAGE_FORMAT completion'); |
156 | | - } catch (error) { |
157 | | - logger.testFailed('server.env WLP_LOG populates correct WLP_LOGGING_MESSAGE_FORMAT completion', error); |
158 | | - throw error; |
159 | | - } |
160 | | - }); |
161 | | - |
162 | | - it('Show that INVALID text displays diagnostic and quick fix removes it', async function() { |
163 | | - this.timeout(90000); |
164 | | - logger.testStart('Show that INVALID text displays diagnostic and quick fix removes it'); |
165 | | - try { |
166 | | - await editorUtils.replaceTextWithinLineContaining(serverEnv.getEditor(), 'WLP_LOGGING_MESSAGE_FORMAT', 'JSON', 'INVALID'); |
167 | | - |
168 | | - await serverEnv.getEditor().save(); |
169 | | - await wait.sleep(500); |
170 | | - |
171 | | - const problems = new ProblemsPage(); |
172 | | - const found = await problems.hasDiagnostic('The value `INVALID` is not valid for the variable `WLP_LOGGING_MESSAGE_FORMAT`.'); |
173 | | - expect(found).to.be.true; |
174 | | - logger.testComplete('Diagnostic shows INVALID variable'); |
175 | | - |
176 | | - const buffer = await serverEnv.getEditor().getText(); |
177 | | - logger.info('Buffer before quick fix: ' + JSON.stringify(buffer)); |
178 | | - |
179 | | - await new QuickFixPage().applyFix(serverEnv, 'INVALID', 'Replace value with JSON'); |
180 | | - await wait.sleep(3000); |
181 | | - await serverEnv.getEditor().save(); |
182 | | - await wait.sleep(5000); |
183 | | - |
184 | | - const afterFix = await serverEnv.getEditor().getText(); |
185 | | - expect(afterFix).to.include('JSON'); |
186 | | - expect(await problems.hasDiagnostic('The value `INVALID` is not valid for the variable `WLP_LOGGING_MESSAGE_FORMAT`.')).to.be.false; |
187 | | - } catch (error) { |
188 | | - logger.testFailed('Diagnostic/quick-fix test flow failed', error); |
189 | | - throw error; |
190 | | - } |
191 | | - }); |
192 | 40 | }); |
0 commit comments