Skip to content

Commit 6ea900d

Browse files
committed
add full example with visit in before hook
1 parent 2df9344 commit 6ea900d

File tree

11 files changed

+3028
-0
lines changed

11 files changed

+3028
-0
lines changed

examples/before-all-visit/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# example: before-all-visit
2+
3+
Code coverage example where the `cy.visit` happens in `before` hook
4+
5+
Code was instrumented with
6+
7+
```shell
8+
npx nyc instrument --compact false main.js > main-instrumented.js
9+
```
10+
11+
and then removed absolute folder paths, leaving just relative path `main.js` in the produced file.
12+
13+
The code uses custom coverage report command in [package.json](package.json) to call `nyc`
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference types="cypress" />
2+
describe('coverage information', () => {
3+
before(() => {
4+
cy.visit('index.html')
5+
})
6+
7+
it('calls add', () => {
8+
cy.window()
9+
.invoke('add', 2, 3)
10+
.should('equal', 5)
11+
})
12+
13+
it('calls sub', () => {
14+
cy.window()
15+
.invoke('sub', 2, 3)
16+
.should('equal', -1)
17+
})
18+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (on, config) => {
2+
on('task', require('../../../../task'))
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../../../../support'

examples/before-all-visit/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<body>
2+
Page body
3+
<script src="main-instrumented.js"></script>
4+
</body>

examples/before-all-visit/main-instrumented.js

+146
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/before-all-visit/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
window.add = (a, b) => a + b
2+
3+
window.sub = (a, b) => a - b

0 commit comments

Comments
 (0)