2022-05-26 11:19:00 +02:00
|
|
|
/*
|
2023-01-11 19:12:38 +01:00
|
|
|
Copyright 2022-2023 The Matrix.org Foundation C.I.C.
|
2022-05-26 11:19:00 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// <reference types="cypress" />
|
|
|
|
|
2023-06-20 17:27:18 +02:00
|
|
|
import "cypress-each";
|
2023-06-22 11:43:49 +02:00
|
|
|
import EventEmitter from "events";
|
2023-06-20 17:27:18 +02:00
|
|
|
|
2022-05-26 11:19:00 +02:00
|
|
|
declare global {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
|
|
namespace Cypress {
|
|
|
|
type ChainableValue<T> = T extends Cypress.Chainable<infer V> ? V : T;
|
|
|
|
|
|
|
|
interface cy {
|
|
|
|
all<T extends Cypress.Chainable[] | []>(
|
2022-12-12 12:24:14 +01:00
|
|
|
commands: T,
|
2022-05-26 11:19:00 +02:00
|
|
|
): Cypress.Chainable<{ [P in keyof T]: ChainableValue<T[P]> }>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description Returns a single Chainable that resolves when all of the Chainables pass.
|
|
|
|
* @param {Cypress.Chainable[]} commands - List of Cypress.Chainable to resolve.
|
|
|
|
* @returns {Cypress.Chainable} Cypress when all Chainables are resolved.
|
|
|
|
*/
|
|
|
|
cy.all = function all(commands): Cypress.Chainable {
|
2023-01-11 19:12:38 +01:00
|
|
|
const resultArray = [];
|
|
|
|
|
|
|
|
// as each command completes, store the result in the corresponding location of resultArray.
|
|
|
|
for (let i = 0; i < commands.length; i++) {
|
|
|
|
commands[i].then((val) => {
|
|
|
|
resultArray[i] = val;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// add an entry to the log which, when clicked, will write the results to the console.
|
|
|
|
Cypress.log({
|
|
|
|
name: "all",
|
|
|
|
consoleProps: () => ({ Results: resultArray }),
|
2022-05-26 11:19:00 +02:00
|
|
|
});
|
2023-01-11 19:12:38 +01:00
|
|
|
|
|
|
|
// return a chainable which wraps the resultArray. Although this doesn't have a direct dependency on the input
|
|
|
|
// commands, cypress won't process it until the commands that precede it on the command queue (which must include
|
|
|
|
// the input commands) have passed.
|
|
|
|
return cy.wrap(resultArray, { log: false });
|
2022-05-26 11:19:00 +02:00
|
|
|
};
|
|
|
|
|
2023-05-24 11:50:05 +02:00
|
|
|
/**
|
|
|
|
* Check if Cypress has been configured to enable rust crypto, and bail out if so.
|
|
|
|
*/
|
|
|
|
export function skipIfRustCrypto() {
|
|
|
|
if (isRustCryptoEnabled()) {
|
|
|
|
cy.log("Skipping due to rust crypto");
|
|
|
|
//@ts-ignore: 'state' is a secret internal command
|
|
|
|
cy.state("runnable").skip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if Cypress has been configured to enable rust crypto (by checking the environment variable)
|
|
|
|
*/
|
|
|
|
export function isRustCryptoEnabled(): boolean {
|
|
|
|
return !!Cypress.env("RUST_CRYPTO");
|
|
|
|
}
|
2023-06-22 11:43:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a Promise which will resolve when the given event emitter emits a given event
|
|
|
|
*/
|
|
|
|
export function emitPromise(e: EventEmitter, k: string | symbol) {
|
|
|
|
return new Promise((r) => e.once(k, r));
|
|
|
|
}
|