Skip to content

Commit 5acc151

Browse files
authored
Merge pull request #15 from matrix-org/michaelk/return_data_from_cypress
Return information from a get_timeline method.
2 parents 71c24b4 + acf0b3b commit 5acc151

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Trafficlight adapter for element-web
44
This code provides a cypress-based adapter for running trafficlight clients against element web.
55

66
See matrix-org/trafficlight for more information on how to run using this.
7+

cypress/e2e/trafficlight/actions/timeline.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,18 @@ export function verifyLastMessageIsTrusted(): string {
4646
.find(".mx_EventTile_e2eIcon").should("not.exist");
4747
return "verified";
4848
}
49+
50+
export function getTimeline(): JSONValue {
51+
const rsp = [];
52+
Cypress.$('.mx_EventTile').each(
53+
function(index, obj) {
54+
tile = {};
55+
tile['user'] = Cypress.$(obj).find('.mx_BaseAvatar_image').attr('title');
56+
const e2eicon = Cypress.$(obj).find('.mx_EventTile_e2eIcon').attr('class');
57+
tile['e2e_issues'] = e2eicon;
58+
tile['message'] = Cypress.$(obj).find('.mx_EventTile_content').text();
59+
rsp.push(tile);
60+
},
61+
);
62+
return { "response": "got_timeline", "timeline": rsp };
63+
}

cypress/e2e/trafficlight/trafficlight.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
openRoom,
4040
} from "./actions/room";
4141
import {
42+
getTimeline,
4243
sendMessage,
4344
verifyLastMessageIsTrusted,
4445
verifyLastMessageIsUTD,
@@ -104,7 +105,13 @@ function recurse() {
104105
const respondUrl = `${Cypress.env('TRAFFICLIGHT_URL') }/client/${ Cypress.env('TRAFFICLIGHT_UUID') }/respond`;
105106

106107
function sendResponse(responseStatus) {
107-
cy.request('POST', respondUrl, { response: responseStatus }).then((response) => {
108+
let data;
109+
if (typeof responseStatus == "string") {
110+
data = { response: responseStatus };
111+
} else {
112+
data = responseStatus;
113+
}
114+
cy.request('POST', respondUrl, data).then((response) => {
108115
expect(response.status).to.eq(200);
109116
});
110117
}
@@ -130,7 +137,7 @@ function recurse() {
130137
});
131138
}
132139

133-
function runAction(action: string, data: JSONValue): string | undefined {
140+
function runAction(action: string, data: JSONValue): string | JSONValue | undefined {
134141
switch (action) {
135142
// Auth
136143
case 'register':
@@ -246,6 +253,9 @@ function runAction(action: string, data: JSONValue): string | undefined {
246253
}
247254
return advanceClock(milliseconds);
248255
}
256+
case "get_timeline": {
257+
return getTimeline();
258+
}
249259
case "clear_idb_storage":
250260
return clearIDBStorage();
251261
case "reload":

src/trafficlight.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async function uploadFile(trafficlightUrl: string, uuid: string, filename: strin
8686
return promise;
8787
}
8888

89-
async function runCypress(trafficlightUrl: string, uuid: string): Promise<boolean> {
89+
async function runCypress(trafficlightUrl: string, uuid: string, openMode: boolean): Promise<boolean> {
9090
const cypressOptions = {
9191
headed: true,
9292
// @ts-ignore-next-line
@@ -101,7 +101,7 @@ async function runCypress(trafficlightUrl: string, uuid: string): Promise<boolea
101101
},
102102
config: {
103103
retries: { // Override cypress.json - we want to run exactly once.
104-
'openMode': 0,
104+
'openMode': openMode ? 1 : 0,
105105
'runMode': 0,
106106
},
107107
e2e: {
@@ -132,17 +132,25 @@ async function runCypress(trafficlightUrl: string, uuid: string): Promise<boolea
132132
}
133133
}
134134

135-
async function runRepeatedly(trafficlightUrl: string) {
135+
async function runRepeatedly(trafficlightUrl: string, openMode: boolean) {
136136
// need to find an exit condition here
137137
let shouldContinue = true;
138138
while (shouldContinue) {
139139
const uuid = crypto.randomUUID();
140140
await registerClient(trafficlightUrl, uuid);
141-
shouldContinue = await runCypress(trafficlightUrl, uuid);
141+
shouldContinue = await runCypress(trafficlightUrl, uuid, openMode);
142142
}
143143
}
144144

145145
const trafficlightUrl = process.env.TRAFFICLIGHT_URL || 'http://127.0.0.1:5000';
146-
runRepeatedly(trafficlightUrl).then((result) => {
146+
147+
let openMode = false;
148+
for (let i = 0; i < process.argv.length; i++) {
149+
if (process.argv[i] == "open") {
150+
openMode = true;
151+
}
152+
}
153+
154+
runRepeatedly(trafficlightUrl, openMode).then((result) => {
147155
console.log(`Finished looping forever(?), got ${result}`);
148156
});

0 commit comments

Comments
 (0)