Skip to content

Commit 988c763

Browse files
Erwin Dondorperwindon
authored andcommitted
brought regression-test back to life
1 parent b21d8e5 commit 988c763

4 files changed

Lines changed: 72 additions & 29 deletions

File tree

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,12 @@ Then browse to [http://localhost:3333/](http://localhost:3333/), you can login w
593593
## Testing
594594
We provide some functional tests and unit tests. They use the docker setup to run the functional tests. You will also need [yarn](https://yarnpkg.com) and [node.js](https://nodejs.org/en/) to run them. When you have docker, yarn and node.js installed, you can run the tests from the root of the repository like this:
595595
```
596-
bash runtests.bash
596+
sh runtests.sh
597597
```
598598

599599
To show the browser window + a debugger while running the functional tests you can run:
600600
```
601-
NIGHTMARE_DEBUG=1 bash runtests.bash
601+
NIGHTMARE_DEBUG=1 sh runtests.sh
602602
```
603603

604604
We use the following testing libraries:

runtests.bash renamed to runtests.sh

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

3-
sudo systemctl stop salt-master salt-api
3+
# show what is going on
4+
set -x
45

5-
sudo apt install -y libxss1 libgconf-2-4 libnss3 libasound2
6+
# get the needed software
7+
sudo apt install -y libxss1 libgconf-2-4 libnss3 libasound2 xvfb psmisc
68

7-
# always cleanup the docker images when something goes wrong
8-
function cleanupdocker {
9-
docker-compose --file docker/docker-compose.yml rm --force --stop
10-
}
11-
trap cleanupdocker EXIT
9+
# prevent conflict with a running salt installation
10+
sudo systemctl stop salt-master salt-api
11+
# or a previous running xvfb
12+
killall Xvfb
1213

1314
set -e
1415

@@ -36,8 +37,17 @@ docker-compose --file docker/docker-compose.yml up -d
3637
npm run wait-for-docker
3738

3839
# run the nightmare.js functional tests
39-
export DEBUG=nightmare:*,electron:*
40-
export NIGHTMARE_DEBUG=1
41-
npm run test:functional
40+
# when debugging is needed:
41+
#export DEBUG=nightmare:*,electron:*
42+
#export NIGHTMARE_DEBUG=1
43+
# suppress Electron Security Warnings:
44+
export ELECTRON_DISABLE_SECURITY_WARNINGS=true
45+
xvfb-run npm run test:functional
46+
47+
# remove the containers
48+
docker-compose --file docker/docker-compose.yml rm --force --stop
49+
50+
# start the usual software again
51+
sudo systemctl start salt-master salt-api
4252

43-
set +e
53+
echo "DONE!"

saltgui/static/scripts/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,25 @@
33
/* istanbul ignore file */
44
import {Router} from "./Router.js";
55
window.addEventListener("load", () => new Router());
6+
7+
/* eslint-disable func-names */
8+
// Make sure the errors are shown during regression testing
9+
window.onerror = function (msg, url, lineNo, columnNo, error) {
10+
console.log("JS Error:" + msg + ",error:" + error + ",url:" + url + "@" + lineNo + ":" + columnNo);
11+
if (error && error.stack) {
12+
console.log("Stack:" + error.stack);
13+
}
14+
return false;
15+
};
16+
17+
// simple polyfill solution
18+
if (!Object.fromEntries) {
19+
Object.fromEntries = function (pairs) {
20+
const obj = {};
21+
for (const pair of pairs) {
22+
obj[pair[0]] = pair[1];
23+
}
24+
return obj;
25+
}
26+
}
27+
/* eslint-enable func-names */

tests/functional/login.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global beforeEach describe it process */
1+
/* global afterEach beforeEach describe it process */
22

33
import Nightmare from "nightmare";
44
import {assert} from "chai";
@@ -26,34 +26,51 @@ describe("Funtional tests", function () {
2626
};
2727

2828
if (process.env.NIGHTMARE_DEBUG === "1") {
29+
console.log("NIGHTMARE_DEBUG=1, setting additional options");
30+
2931
// show the browser and the debug window
3032
options.openDevTools = true;
3133
// to show in a separate window
3234
// options.openDevTools = { mode: "detach" };
33-
options.show = true;
3435
}
3536

3637
browser = new Nightmare(options);
37-
browser.
38+
39+
browser.on('console', (type, message) => {
40+
console.log(`[console][${type}] ` + JSON.stringify(message, null, 2));
41+
});
42+
43+
browser.on('page', (type, message, stack) => {
44+
console.error(`[page-error][${type}] ${JSON.stringify(message)}`);
45+
if (stack) {
46+
console.error('stack:', stack);
47+
}
48+
});
49+
50+
return browser.
3851
goto(url).
3952
wait(1000);
4053
});
4154

55+
/* eslint-disable arrow-body-style */
56+
afterEach(() => {
57+
return browser.end();
58+
});
59+
/* eslint-enable arrow-body-style */
60+
4261
describe("Login and logout", () => {
4362

4463
it("we should be redirected to the login page", (done) => {
4564
browser.
4665
wait(() => document.location.href.includes("login")).
4766
wait(500).
4867
evaluate(() => document.location.href).
49-
end().
5068
then((href) => {
5169
href = href.replace(/[?]reason=.*/, "");
52-
assert.equal(href, url + "login");
53-
return true;
70+
assert.equal(href, url);
5471
}).
5572
then(done).
56-
catch(done);
73+
catch((err) => done(err));
5774
});
5875

5976
it("we cannot login with false credentials", (done) => {
@@ -67,10 +84,8 @@ describe("Funtional tests", function () {
6784
wait("#notice-wrapper div.notice_auth_failed").
6885
wait(1000).
6986
evaluate(() => document.querySelector("#notice-wrapper div").textContent).
70-
end().
7187
then((message) => {
7288
assert.equal(message, "Authentication failed");
73-
return true;
7489
}).
7590
then(done).
7691
catch(done);
@@ -91,10 +106,8 @@ describe("Funtional tests", function () {
91106
}).
92107
wait(1000).
93108
evaluate(() => document.location.href).
94-
end().
95109
then((href) => {
96-
assert.equal(href, url);
97-
return true;
110+
assert.equal(href, url + "#minions");
98111
}).
99112
then(done).
100113
catch(done);
@@ -125,11 +138,9 @@ describe("Funtional tests", function () {
125138
wait(() => document.location.href.includes("login")).
126139
wait(1000).
127140
evaluate(() => document.location.href).
128-
end().
129141
then((href) => {
130142
// and we redirected to the login page
131-
assert.equal(href, url + "login?reason=logout");
132-
return true;
143+
assert.equal(href, url + "?reason=logout#login");
133144
}).
134145
then(done).
135146
catch(done);

0 commit comments

Comments
 (0)