/
execute-spec.ts
46 lines (38 loc) · 1.51 KB
/
execute-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { shouldHaveTestResults } from '../runner/support/spec-loader'
export interface ExpectedResults {
passCount?: number
failCount?: number
pendingCount?: number
}
declare global {
namespace Cypress {
interface Chainable {
/**
* Adapter to wait for a spec to finish in a standard way. It
*
* 1. Waits for the stats to reset which signifies that the test page has loaded
* 2. Waits for 'Your tests are loading...' to not be present so that we know the tests themselves have loaded
* 3. Waits (with a timeout of 30s) for the Rerun all tests button to be present. This ensures all tests have completed
*
*/
waitForSpecToFinish(expectedResults?: ExpectedResults, timeout?: number): void
}
}
}
const waitForSpecToFinish = (expectedResults, timeout?: number) => {
// First ensure the test is loaded
cy.get('.passed > .num').should('exist')
cy.get('.failed > .num').should('exist')
// Then ensure the tests are running
cy.contains('Your tests are loading...', { timeout: timeout || 20000 }).should('not.exist')
// Then ensure the tests have finished
cy.get('[aria-label="Rerun all tests"]', { timeout: timeout || 30000 })
if (expectedResults) {
shouldHaveTestResults(expectedResults)
}
}
Cypress.Commands.add('waitForSpecToFinish', waitForSpecToFinish)
// Here we export an empty object to tell the
// typescript type checker that this definitely is a module.
// This way, we are allowed to use the global namespace declaration
export {}