Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit af6ded3

Browse files
authored
Move update tests to Cypress (#8716)
* Move update tests to Cypress * Fix /version intercept to account for cachebuster
1 parent eaace4b commit af6ded3

File tree

4 files changed

+53
-124
lines changed

4 files changed

+53
-124
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/// <reference types="cypress" />
18+
19+
import { SynapseInstance } from "../../plugins/synapsedocker";
20+
21+
describe("Update", () => {
22+
let synapse: SynapseInstance;
23+
24+
beforeEach(() => {
25+
cy.startSynapse("default").then(data => {
26+
synapse = data;
27+
});
28+
});
29+
30+
afterEach(() => {
31+
cy.stopSynapse(synapse);
32+
});
33+
34+
it("should navigate to ?updated=$VERSION if realises it is immediately out of date on load", () => {
35+
const NEW_VERSION = "some-new-version";
36+
37+
cy.intercept("/version*", {
38+
statusCode: 200,
39+
body: NEW_VERSION,
40+
headers: {
41+
"Content-Type": "test/plain",
42+
},
43+
}).as("version");
44+
45+
cy.initTestUser(synapse, "Ursa");
46+
47+
cy.wait("@version");
48+
cy.url().should("contain", "updated=" + NEW_VERSION).then(href => {
49+
const url = new URL(href);
50+
expect(url.searchParams.get("updated")).to.equal(NEW_VERSION);
51+
});
52+
});
53+
});

test/end-to-end-tests/src/scenario.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { RestMultiSession } from "./rest/multi";
2727
import { RestSession } from "./rest/session";
2828
import { stickerScenarios } from './scenarios/sticker';
2929
import { userViewScenarios } from "./scenarios/user-view";
30-
import { updateScenarios } from "./scenarios/update";
3130

3231
export async function scenario(createSession: (s: string) => Promise<ElementSession>,
3332
restCreator: RestSessionCreator): Promise<void> {
@@ -63,10 +62,6 @@ export async function scenario(createSession: (s: string) => Promise<ElementSess
6362
// closing them as we go rather than leaving them all open until the end).
6463
const stickerSession = await createSession("sally");
6564
await stickerScenarios("sally", "ilikestickers", stickerSession, restCreator);
66-
67-
// Create a new window to test app auto-updating
68-
const updateSession = await createSession("update");
69-
await updateScenarios(updateSession);
7065
}
7166

7267
async function createRestUsers(restCreator: RestSessionCreator): Promise<RestMultiSession> {

test/end-to-end-tests/src/scenarios/update.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

test/end-to-end-tests/src/session.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ import { delay, serializeLog } from './util';
2323

2424
const DEFAULT_TIMEOUT = 20000;
2525

26-
interface XHRLogger {
27-
logs: () => string;
28-
}
29-
3026
export class ElementSession {
3127
readonly consoleLog: LogBuffer<puppeteer.ConsoleMessage>;
3228
readonly networkLog: LogBuffer<puppeteer.HTTPRequest>;
@@ -80,10 +76,6 @@ export class ElementSession {
8076
return this.getElementProperty(field, 'innerText');
8177
}
8278

83-
public getOuterHTML(field: puppeteer.ElementHandle): Promise<string> {
84-
return this.getElementProperty(field, 'outerHTML');
85-
}
86-
8779
public isChecked(field: puppeteer.ElementHandle): Promise<string> {
8880
return this.getElementProperty(field, 'checked');
8981
}
@@ -96,29 +88,6 @@ export class ElementSession {
9688
return this.networkLog.buffer;
9789
}
9890

99-
public logXHRRequests(): XHRLogger {
100-
let buffer = "";
101-
this.page.on('requestfinished', async (req) => {
102-
const type = req.resourceType();
103-
const response = await req.response();
104-
//if (type === 'xhr' || type === 'fetch') {
105-
buffer += `${type} ${response.status()} ${req.method()} ${req.url()} \n`;
106-
// if (req.method() === "POST") {
107-
// buffer += " Post data: " + req.postData();
108-
// }
109-
//}
110-
});
111-
return {
112-
logs() {
113-
return buffer;
114-
},
115-
};
116-
}
117-
118-
public async printElements(label: string, elements: puppeteer.ElementHandle[]): Promise<void> {
119-
console.log(label, await Promise.all(elements.map(this.getOuterHTML)));
120-
}
121-
12291
public async replaceInputText(input: puppeteer.ElementHandle, text: string): Promise<void> {
12392
// click 3 times to select all text
12493
await input.click({ clickCount: 3 });
@@ -149,45 +118,6 @@ export class ElementSession {
149118
return await this.page.$$(selector);
150119
}
151120

152-
public waitForReload(): Promise<void> {
153-
const timeout = DEFAULT_TIMEOUT;
154-
return new Promise((resolve, reject) => {
155-
const timeoutHandle = setTimeout(() => {
156-
this.page.off('domcontentloaded', callback);
157-
reject(new Error(`timeout of ${timeout}ms for waitForReload elapsed`));
158-
}, timeout);
159-
160-
const callback = async () => {
161-
clearTimeout(timeoutHandle);
162-
resolve();
163-
};
164-
165-
this.page.once('domcontentloaded', callback);
166-
});
167-
}
168-
169-
public waitForNewPage(): Promise<void> {
170-
const timeout = DEFAULT_TIMEOUT;
171-
return new Promise((resolve, reject) => {
172-
const timeoutHandle = setTimeout(() => {
173-
this.browser.off('targetcreated', callback);
174-
reject(new Error(`timeout of ${timeout}ms for waitForNewPage elapsed`));
175-
}, timeout);
176-
177-
const callback = async (target) => {
178-
if (target.type() !== 'page') {
179-
return;
180-
}
181-
this.browser.off('targetcreated', callback);
182-
clearTimeout(timeoutHandle);
183-
const page = await target.page();
184-
resolve(page);
185-
};
186-
187-
this.browser.on('targetcreated', callback);
188-
});
189-
}
190-
191121
/** wait for a /sync request started after this call that gets a 200 response */
192122
public async waitForNextSuccessfulSync(): Promise<void> {
193123
const syncUrls = [];

0 commit comments

Comments
 (0)