-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
spec-loader.ts
92 lines (76 loc) · 2.56 KB
/
spec-loader.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
export const shouldHaveTestResults = ({ passCount, failCount, pendingCount }) => {
passCount = passCount || '--'
failCount = failCount || '--'
cy.get('button.restart', { timeout: 30000 }).should('be.visible') // ensure tests are finished running
cy.findByLabelText('Stats', { timeout: 10000 }).within(() => {
cy.get('.passed .num', { timeout: 30000 }).should('have.text', `${passCount}`)
cy.get('.failed .num', { timeout: 30000 }).should('have.text', `${failCount}`)
if (pendingCount) {
cy.get('.pending .num', { timeout: 20000 }).should('have.text', `${pendingCount}`)
}
})
}
export type LoadSpecOptions = {
filePath: string
setup?: () => void
passCount?: number | string
failCount?: number | string
pendingCount?: number | string
hasPreferredIde?: boolean
projectName?: 'runner-e2e-specs' | 'runner-ct-specs' | 'session-and-origin-e2e-specs'
mode?: 'e2e' | 'component'
configFile?: string
scaffold?: boolean
}
export function loadSpec (options: LoadSpecOptions) {
const {
filePath,
setup,
passCount = '--',
failCount = '--',
hasPreferredIde = false,
pendingCount,
mode = 'e2e',
configFile = 'cypress.config.js',
projectName = 'runner-e2e-specs',
scaffold = true,
} = options
if (scaffold) {
cy.scaffoldProject(projectName)
}
cy.openProject(projectName, ['--config-file', configFile])
cy.startAppServer(mode)
cy.withCtx((ctx, options) => {
ctx.update((coreData) => {
if (options.hasPreferredIde) {
// set preferred editor to bypass IDE selection dialog
coreData.localSettings.availableEditors = [
...ctx.coreData.localSettings.availableEditors,
{
id: 'test-editor',
binary: '/usr/bin/test-editor',
name: 'Test editor',
},
]
coreData.localSettings.preferences.preferredEditorBinary = 'test-editor'
}
coreData.localSettings.preferences.isSpecsListOpen = false
})
}, { hasPreferredIde })
cy.visitApp(`specs/runner?file=cypress/e2e/${filePath}`)
if (setup) {
setup()
}
// Wait for specs to complete
shouldHaveTestResults({ passCount, failCount, pendingCount })
}
export function runSpec ({ fileName }: { fileName: string }) {
cy.scaffoldProject('runner-e2e-specs')
cy.openProject('runner-e2e-specs')
cy.startAppServer()
cy.visitApp(`specs/runner?file=cypress/e2e/runner/${fileName}`)
// First ensure the test is loaded
cy.get('.passed > .num').should('contain', '--')
cy.get('.failed > .num').should('contain', '--')
return cy.window()
}