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