-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
resource-loading-resilience.js
116 lines (104 loc) · 3.2 KB
/
resource-loading-resilience.js
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
Cypress.on(`uncaught:exception`, (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
console.log(err)
return false
})
const waitForAPIOptions = {
timeout: 3000,
}
const runTests = () => {
it(`Loads index`, () => {
cy.visit(`/`).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions)
cy.getTestElement(`dom-marker`).contains(`index`)
})
it(`Navigates to second page`, () => {
cy.getTestElement(`page2`).click()
cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions)
.location(`pathname`)
.should(`equal`, `/page-2/`)
cy.getTestElement(`dom-marker`).contains(`page-2`)
})
it(`Navigates to 404 page`, () => {
cy.getTestElement(`404`).click()
cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions)
.location(`pathname`)
.should(`equal`, `/page-3/`)
cy.getTestElement(`dom-marker`).contains(`404`)
})
it(`Loads 404`, () => {
cy.visit(`/page-3/`, {
failOnStatusCode: false,
}).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions)
cy.getTestElement(`dom-marker`).contains(`404`)
})
it(`Can navigate from 404 to index`, () => {
cy.getTestElement(`index`).click()
cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions)
.location(`pathname`)
.should(`equal`, `/`)
cy.getTestElement(`dom-marker`).contains(`index`)
})
}
describe(`Every resources available`, () => {
it(`Restore resources`, () => {
cy.exec(`npm run chunks -- restore`)
})
runTests()
})
describe(`Missing top level resources`, () => {
describe(`Deleted pages manifest`, () => {
it(`Block resources`, () => {
cy.exec(`npm run chunks -- restore`)
cy.exec(`npm run chunks -- block pages-manifest`)
})
runTests()
})
describe(`Deleted app chunk assets`, () => {
it(`Block resources`, () => {
cy.exec(`npm run chunks -- restore`)
cy.exec(`npm run chunks -- block app`)
})
runTests()
})
})
const runSuiteForPage = (label, path) => {
describe(`Missing "${label}" resources`, () => {
describe(`Missing "${label}" page query results`, () => {
it(`Block resources`, () => {
cy.exec(`npm run chunks -- restore`)
cy.exec(`npm run chunks -- block-page ${path} query-result`)
})
runTests()
})
describe(`Missing "${label}" page page-template asset`, () => {
it(`Block resources`, () => {
cy.exec(`npm run chunks -- restore`)
cy.exec(`npm run chunks -- block-page ${path} page-template`)
})
runTests()
})
describe(`Missing "${label}" page extra assets`, () => {
it(`Block resources`, () => {
cy.exec(`npm run chunks -- restore`)
cy.exec(`npm run chunks -- block-page ${path} extra`)
})
runTests()
})
describe(`Missing all "${label}" page assets`, () => {
it(`Block resources`, () => {
cy.exec(`npm run chunks -- restore`)
cy.exec(`npm run chunks -- block-page ${path} all`)
})
runTests()
})
})
}
runSuiteForPage(`Index`, `/`)
runSuiteForPage(`Page-2`, `/page-2/`)
runSuiteForPage(`404`, `/404.html`)
describe(`Cleanup`, () => {
it(`Restore resources`, () => {
cy.exec(`npm run chunks -- restore`)
})
})