Skip to content

Commit dae108d

Browse files
Merge pull request #73 from julienloizelet/feature/71-end-to-end-test-display-errors
Feature/71 end to end test display errors
2 parents e5aa35c + 148fa57 commit dae108d

File tree

2 files changed

+9
-68
lines changed

2 files changed

+9
-68
lines changed

docs/ddev.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ Finally, you can test by running:
129129
test (all files if empty);
130130

131131
For example:
132-
133-
`./run-tests.sh host "./2-live-mode-remediations.js"`
132+
```
133+
./run-tests.sh host "./2-live-mode-remediations.js"
134+
```
134135

135136
## License
136137

tests/e2e-ddev/utils/helpers.js

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,16 @@ const setToggle = async (optionName, enable) => {
9898
}
9999
};
100100

101+
const fillInput = async (optionName, value) => {
102+
await page.fill(`[name=${optionName}]`, `${value}`);
103+
};
104+
101105
const onAdvancedPageEnableStreamMode = async () => {
102106
await setToggle("crowdsec_stream_mode", true);
103107
await fillInput("crowdsec_stream_mode_refresh_frequency", 1);
104108
};
105109

106-
const onAdvancedPageEnableDebugMode = async () => {
107-
await setToggle("crowdsec_debug_mode", true);
108-
};
109110

110-
const onAdvancedPageDisableDebugMode = async () => {
111-
await setToggle("crowdsec_debug_mode", false);
112-
};
113111

114112
const onAdminAdvancedSettingsPageSetCleanIpCacheDurationTo = async (
115113
seconds,
@@ -209,62 +207,6 @@ const forceCronRun = async () => {
209207
await wait(2000);
210208
};
211209

212-
const fillInput = async (optionName, value) => {
213-
await page.fill(`[name=${optionName}]`, `${value}`);
214-
};
215-
216-
const remediationShouldUpdate = async (
217-
accessibleTextInTitle,
218-
initialRemediation,
219-
newRemediation,
220-
timeoutMs,
221-
intervalMs = 1000,
222-
) =>
223-
new Promise((resolve, reject) => {
224-
let checkRemediationTimeout;
225-
let checkRemediationInterval;
226-
let initialPassed = false;
227-
const stopTimers = () => {
228-
if (checkRemediationInterval) {
229-
clearInterval(checkRemediationInterval);
230-
}
231-
if (checkRemediationTimeout) {
232-
clearTimeout(checkRemediationTimeout);
233-
}
234-
};
235-
236-
checkRemediationInterval = setInterval(async () => {
237-
await page.reload();
238-
await waitForNavigation;
239-
const remediation = await computeCurrentPageRemediation(
240-
accessibleTextInTitle,
241-
);
242-
if (remediation === newRemediation) {
243-
stopTimers();
244-
if (initialPassed) {
245-
resolve();
246-
} else {
247-
reject({
248-
errorType: "INITIAL_REMEDIATION_NEVER_HAPPENED",
249-
type: remediation,
250-
});
251-
}
252-
} else if (remediation === initialRemediation) {
253-
initialPassed = true;
254-
} else {
255-
stopTimers();
256-
reject({
257-
errorType: "WRONG_REMEDIATION_HAPPENED",
258-
type: remediation,
259-
});
260-
}
261-
}, intervalMs);
262-
checkRemediationTimeout = setTimeout(() => {
263-
stopTimers();
264-
reject({ errorType: "NEW_REMEDIATION_NEVER_HAPPENED" });
265-
}, timeoutMs);
266-
});
267-
268210
const storeCookies = async () => {
269211
const cookies = await context.cookies();
270212
const cookieJson = JSON.stringify(cookies);
@@ -290,7 +232,8 @@ const setDefaultConfig = async () => {
290232
await onAdminSaveSettings(false);
291233

292234
await onAdminGoToAdvancedPage();
293-
await onAdvancedPageEnableDebugMode();
235+
await setToggle("crowdsec_debug_mode", true);
236+
await setToggle("crowdsec_display_errors", true);
294237
await page.selectOption("[name=crowdsec_cache_system]", "phpfs");
295238
await setToggle("crowdsec_stream_mode", false);
296239
// We have to save in order that cache duration fields to be visible (not disabled)
@@ -332,11 +275,8 @@ module.exports = {
332275
onCaptchaPageRefreshCaptchaImage,
333276
forceCronRun,
334277
fillInput,
335-
remediationShouldUpdate,
336278
storeCookies,
337279
loadCookies,
338-
onAdvancedPageEnableDebugMode,
339-
onAdvancedPageDisableDebugMode,
340280
deleteExistingStandaloneSettings,
341281
setDefaultConfig,
342282
};

0 commit comments

Comments
 (0)