Add data collection mechanism in end to end test suite
parent
6804a26e74
commit
89832eff9e
|
@ -42,6 +42,7 @@ import {SpaceStoreClass} from "../stores/SpaceStore";
|
||||||
import TypingStore from "../stores/TypingStore";
|
import TypingStore from "../stores/TypingStore";
|
||||||
import { EventIndexPeg } from "../indexing/EventIndexPeg";
|
import { EventIndexPeg } from "../indexing/EventIndexPeg";
|
||||||
import {VoiceRecordingStore} from "../stores/VoiceRecordingStore";
|
import {VoiceRecordingStore} from "../stores/VoiceRecordingStore";
|
||||||
|
import PerformanceMonitor, { PerformanceEntryNames } from "../performance";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -79,6 +80,8 @@ declare global {
|
||||||
mxVoiceRecordingStore: VoiceRecordingStore;
|
mxVoiceRecordingStore: VoiceRecordingStore;
|
||||||
mxTypingStore: TypingStore;
|
mxTypingStore: TypingStore;
|
||||||
mxEventIndexPeg: EventIndexPeg;
|
mxEventIndexPeg: EventIndexPeg;
|
||||||
|
mxPerformanceMonitor: PerformanceMonitor;
|
||||||
|
mxPerformanceEntryNames: PerformanceEntryNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Document {
|
interface Document {
|
||||||
|
|
|
@ -1858,7 +1858,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
|
|
||||||
// returns a promise which resolves to the new MatrixClient
|
// returns a promise which resolves to the new MatrixClient
|
||||||
onRegistered(credentials: IMatrixClientCreds) {
|
onRegistered(credentials: IMatrixClientCreds) {
|
||||||
PerformanceMonitor.stop(PerformanceEntryNames.REGISTER);
|
|
||||||
return Lifecycle.setLoggedIn(credentials);
|
return Lifecycle.setLoggedIn(credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1949,6 +1948,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
await Lifecycle.setLoggedIn(credentials);
|
await Lifecycle.setLoggedIn(credentials);
|
||||||
await this.postLoginSetup();
|
await this.postLoginSetup();
|
||||||
PerformanceMonitor.stop(PerformanceEntryNames.LOGIN);
|
PerformanceMonitor.stop(PerformanceEntryNames.LOGIN);
|
||||||
|
PerformanceMonitor.stop(PerformanceEntryNames.REGISTER);
|
||||||
};
|
};
|
||||||
|
|
||||||
// complete security / e2e setup has finished
|
// complete security / e2e setup has finished
|
||||||
|
|
|
@ -28,10 +28,10 @@ interface GetEntriesOptions {
|
||||||
type?: string,
|
type?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformanceCallbackFunction = (entry: PerformanceEntry) => void;
|
type PerformanceCallbackFunction = (entry: PerformanceEntry[]) => void;
|
||||||
|
|
||||||
interface PerformanceDataListener {
|
interface PerformanceDataListener {
|
||||||
entryTypes?: string[],
|
entryNames?: string[],
|
||||||
callback: PerformanceCallbackFunction
|
callback: PerformanceCallbackFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,11 @@ export default class PerformanceMonitor {
|
||||||
// when adding a data callback
|
// when adding a data callback
|
||||||
entries.push(measurement);
|
entries.push(measurement);
|
||||||
|
|
||||||
listeners.forEach(listener => emitPerformanceData(listener, measurement));
|
listeners.forEach(listener => {
|
||||||
|
if (shouldEmit(listener, measurement)) {
|
||||||
|
listener.callback([measurement])
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return measurement;
|
return measurement;
|
||||||
}
|
}
|
||||||
|
@ -116,9 +120,11 @@ export default class PerformanceMonitor {
|
||||||
|
|
||||||
static addPerformanceDataCallback(listener: PerformanceDataListener, buffer = false) {
|
static addPerformanceDataCallback(listener: PerformanceDataListener, buffer = false) {
|
||||||
listeners.push(listener);
|
listeners.push(listener);
|
||||||
|
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
entries.forEach(entry => emitPerformanceData(listener, entry));
|
const toEmit = entries.filter(entry => shouldEmit(listener, entry));
|
||||||
|
if (toEmit.length > 0) {
|
||||||
|
listener.callback(toEmit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,10 +140,8 @@ export default class PerformanceMonitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitPerformanceData(listener, entry): void {
|
function shouldEmit(listener: PerformanceDataListener, entry: PerformanceEntry): boolean {
|
||||||
if (!listener.entryTypes || listener.entryTypes.includes(entry.entryType)) {
|
return !listener.entryNames || listener.entryNames.includes(entry.name);
|
||||||
listener.callback(entry)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,3 +161,6 @@ function supportsPerformanceApi(): boolean {
|
||||||
function buildKey(name: string, id?: string): string {
|
function buildKey(name: string, id?: string): string {
|
||||||
return `${name}${id ? `:${id}` : ''}`;
|
return `${name}${id ? `:${id}` : ''}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.mxPerformanceMonitor = PerformanceMonitor;
|
||||||
|
window.mxPerformanceEntryNames = PerformanceEntryNames;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
node_modules
|
node_modules
|
||||||
*.png
|
*.png
|
||||||
element/env
|
element/env
|
||||||
|
performance-entries.json
|
||||||
|
|
|
@ -208,7 +208,7 @@ module.exports = class ElementSession {
|
||||||
this.log.done();
|
this.log.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
async close() {
|
||||||
return this.browser.close();
|
return this.browser.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ const fs = require("fs");
|
||||||
const program = require('commander');
|
const program = require('commander');
|
||||||
program
|
program
|
||||||
.option('--no-logs', "don't output logs, document html on error", false)
|
.option('--no-logs', "don't output logs, document html on error", false)
|
||||||
.option('--app-url [url]', "url to test", "http://localhost:5000")
|
.option('--app-url [url]', "url to test", "http://localhost:8080")
|
||||||
.option('--windowed', "dont run tests headless", false)
|
.option('--windowed', "dont run tests headless", false)
|
||||||
.option('--slow-mo', "type at a human speed", false)
|
.option('--slow-mo', "type at a human speed", false)
|
||||||
.option('--dev-tools', "open chrome devtools in browser window", false)
|
.option('--dev-tools', "open chrome devtools in browser window", false)
|
||||||
|
@ -79,8 +79,26 @@ async function runTests() {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 5 * 60 * 1000));
|
await new Promise((resolve) => setTimeout(resolve, 5 * 60 * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(sessions.map((session) => session.close()));
|
const performanceEntries = {};
|
||||||
|
|
||||||
|
await Promise.all(sessions.map(async (session) => {
|
||||||
|
// Collecting all performance monitoring data before closing the session
|
||||||
|
const measurements = await session.page.evaluate(() => {
|
||||||
|
let measurements = [];
|
||||||
|
window.mxPerformanceMonitor.addPerformanceDataCallback({
|
||||||
|
entryNames: [
|
||||||
|
window.mxPerformanceEntryNames.REGISTER,
|
||||||
|
],
|
||||||
|
callback: (events) => {
|
||||||
|
measurements = JSON.stringify(events);
|
||||||
|
},
|
||||||
|
}, true);
|
||||||
|
return measurements;
|
||||||
|
});
|
||||||
|
performanceEntries[session.username] = JSON.parse(measurements);
|
||||||
|
return session.close();
|
||||||
|
}));
|
||||||
|
fs.writeFileSync(`performance-entries.json`, JSON.stringify(performanceEntries));
|
||||||
if (failure) {
|
if (failure) {
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue