-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
react.cy.ts
118 lines (98 loc) · 3.69 KB
/
react.cy.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/// <reference path="../support/e2e.ts" />
import type { fixtureDirs } from '@tooling/system-tests'
import dedent from 'dedent'
type ProjectDirs = typeof fixtureDirs
const VITE_REACT: ProjectDirs[number][] = ['vite2.8.6-react', 'vite2.9.1-react']
// Add to this list to focus on a particular permutation
const ONLY_PROJECTS: ProjectDirs[number][] = []
for (const project of VITE_REACT) {
if (ONLY_PROJECTS.length && !ONLY_PROJECTS.includes(project)) {
continue
}
describe(`Working with ${project}`, () => {
beforeEach(() => {
cy.scaffoldProject(project)
cy.openProject(project, ['--config-file', 'cypress-vite.config.ts'])
cy.startAppServer('component')
})
it('should mount a passing test', () => {
cy.visitApp()
cy.contains('App.cy.jsx').click()
cy.waitForSpecToFinish()
cy.get('.passed > .num').should('contain', 1)
})
it('MissingReact: should fail, rerun, succeed', () => {
cy.on('uncaught:exception', () => {
// Ignore the uncaught exception in the AUT
return false
})
cy.visitApp()
cy.contains('MissingReact.cy.jsx').click()
cy.waitForSpecToFinish()
cy.get('.failed > .num').should('contain', 1)
cy.withCtx(async (ctx) => {
await ctx.actions.file.writeFileInProject(`src/MissingReact.jsx`,
`import React from 'react';
${await ctx.file.readFileInProject('src/MissingReact.jsx')}`)
})
cy.get('.passed > .num').should('contain', 1)
})
it('MissingReactInSpec: should fail, rerun, succeed', () => {
cy.on('uncaught:exception', () => {
// Ignore the uncaught exception in the AUT
return false
})
cy.visitApp()
cy.contains('MissingReactInSpec.cy.jsx').click()
cy.waitForSpecToFinish()
cy.get('.failed > .num').should('contain', 1)
cy.withCtx(async (ctx) => {
await ctx.actions.file.writeFileInProject(`src/MissingReactInSpec.cy.jsx`,
await ctx.file.readFileInProject('src/App.cy.jsx'))
})
cy.get('.passed > .num').should('contain', 1)
})
it('AppCompilationError: should fail with uncaught exception error', () => {
cy.on('uncaught:exception', () => {
// Ignore the uncaught exception in the AUT
return false
})
cy.visitApp()
cy.contains('AppCompilationError.cy.jsx').click()
cy.waitForSpecToFinish()
cy.get('.failed > .num').should('contain', 1)
cy.contains('An uncaught error was detected outside of a test')
cy.contains('The following error originated from your test code, not from Cypress.')
// Correct the problem
cy.withCtx(async (ctx) => {
await ctx.actions.file.writeFileInProject(
`src/AppCompilationError.cy.jsx`,
await ctx.file.readFileInProject('src/App.cy.jsx'),
)
})
cy.waitForSpecToFinish()
cy.get('.passed > .num').should('contain', 1)
const appCompilationErrorSpec = dedent`
import React from 'react'
import { mount } from 'cypress/react'
import { App } from './App'
it('renders hello world', () => {
mount(<App />)
cy.get('h1').contains('Hello World')
}
})
`
// Cause the problem again
cy.withCtx(async (ctx, o) => {
await ctx.actions.file.writeFileInProject(
`src/AppCompilationError.cy.jsx`,
o.appCompilationErrorSpec,
)
}, { appCompilationErrorSpec })
cy.waitForSpecToFinish()
cy.get('.failed > .num').should('contain', 1)
cy.contains('An uncaught error was detected outside of a test')
cy.contains('The following error originated from your test code, not from Cypress.')
})
})
}