|
1 | | -// TODO need to update to work with page-data.json |
| 1 | +Cypress.on(`uncaught:exception`, (err, runnable) => { |
| 2 | + // returning false here prevents Cypress from |
| 3 | + // failing the test |
| 4 | + console.log(err) |
| 5 | + return false |
| 6 | +}) |
2 | 7 |
|
3 | | -// Cypress.on(`uncaught:exception`, (err, runnable) => { |
4 | | -// // returning false here prevents Cypress from |
5 | | -// // failing the test |
6 | | -// console.log(err) |
7 | | -// return false |
8 | | -// }) |
| 8 | +const waitForAPIOptions = { |
| 9 | + timeout: 3000, |
| 10 | +} |
9 | 11 |
|
10 | | -// const waitForAPIOptions = { |
11 | | -// timeout: 3000, |
12 | | -// } |
| 12 | +const runTests = () => { |
| 13 | + it(`Loads index`, () => { |
| 14 | + cy.visit(`/`).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
| 15 | + cy.getTestElement(`dom-marker`).contains(`index`) |
| 16 | + }) |
13 | 17 |
|
14 | | -// const runTests = () => { |
15 | | -// it(`Loads index`, () => { |
16 | | -// cy.visit(`/`).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
17 | | -// cy.getTestElement(`dom-marker`).contains(`index`) |
18 | | -// }) |
| 18 | + it(`Navigates to second page`, () => { |
| 19 | + cy.getTestElement(`page2`).click() |
| 20 | + cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
| 21 | + .location(`pathname`) |
| 22 | + .should(`equal`, `/page-2/`) |
| 23 | + cy.getTestElement(`dom-marker`).contains(`page-2`) |
| 24 | + }) |
19 | 25 |
|
20 | | -// it(`Navigates to second page`, () => { |
21 | | -// cy.getTestElement(`page2`).click() |
22 | | -// cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
23 | | -// .location(`pathname`) |
24 | | -// .should(`equal`, `/page-2/`) |
25 | | -// cy.getTestElement(`dom-marker`).contains(`page-2`) |
26 | | -// }) |
| 26 | + it(`Navigates to 404 page`, () => { |
| 27 | + cy.getTestElement(`404`).click() |
| 28 | + cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
| 29 | + .location(`pathname`) |
| 30 | + .should(`equal`, `/page-3/`) |
| 31 | + cy.getTestElement(`dom-marker`).contains(`404`) |
| 32 | + }) |
27 | 33 |
|
28 | | -// it(`Navigates to 404 page`, () => { |
29 | | -// cy.getTestElement(`404`).click() |
30 | | -// cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
31 | | -// .location(`pathname`) |
32 | | -// .should(`equal`, `/page-3/`) |
33 | | -// cy.getTestElement(`dom-marker`).contains(`404`) |
34 | | -// }) |
| 34 | + it(`Loads 404`, () => { |
| 35 | + cy.visit(`/page-3/`, { |
| 36 | + failOnStatusCode: false, |
| 37 | + }).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
| 38 | + cy.getTestElement(`dom-marker`).contains(`404`) |
| 39 | + }) |
35 | 40 |
|
36 | | -// it(`Loads 404`, () => { |
37 | | -// cy.visit(`/page-3/`, { |
38 | | -// failOnStatusCode: false, |
39 | | -// }).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
40 | | -// cy.getTestElement(`dom-marker`).contains(`404`) |
41 | | -// }) |
| 41 | + it(`Can navigate from 404 to index`, () => { |
| 42 | + cy.getTestElement(`index`).click() |
| 43 | + cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
| 44 | + .location(`pathname`) |
| 45 | + .should(`equal`, `/`) |
| 46 | + cy.getTestElement(`dom-marker`).contains(`index`) |
| 47 | + }) |
| 48 | +} |
42 | 49 |
|
43 | | -// it(`Can navigate from 404 to index`, () => { |
44 | | -// cy.getTestElement(`index`).click() |
45 | | -// cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) |
46 | | -// .location(`pathname`) |
47 | | -// .should(`equal`, `/`) |
48 | | -// cy.getTestElement(`dom-marker`).contains(`index`) |
49 | | -// }) |
50 | | -// } |
| 50 | +describe(`Every resources available`, () => { |
| 51 | + it(`Restore resources`, () => { |
| 52 | + cy.task(`restoreAllBlockedResources`) |
| 53 | + }) |
| 54 | + runTests() |
| 55 | +}) |
51 | 56 |
|
52 | | -// describe(`Every resources available`, () => { |
53 | | -// it(`Restore resources`, () => { |
54 | | -// cy.exec(`npm run chunks -- restore`) |
55 | | -// }) |
56 | | -// runTests() |
57 | | -// }) |
| 57 | +const runBlockedScenario = (scenario, args) => { |
| 58 | + it(`Block resources`, () => { |
| 59 | + cy.task(`restoreAllBlockedResources`).then(() => { |
| 60 | + cy.task(scenario, args).then(() => { |
| 61 | + runTests() |
| 62 | + }) |
| 63 | + }) |
| 64 | + }) |
| 65 | +} |
58 | 66 |
|
59 | | -// describe(`Missing top level resources`, () => { |
60 | | -// describe(`Deleted pages manifest`, () => { |
61 | | -// it(`Block resources`, () => { |
62 | | -// cy.exec(`npm run chunks -- restore`) |
63 | | -// cy.exec(`npm run chunks -- block pages-manifest`) |
64 | | -// }) |
65 | | -// runTests() |
66 | | -// }) |
| 67 | +describe(`Missing top level resources`, () => { |
| 68 | + describe(`Deleted app chunk assets`, () => { |
| 69 | + runBlockedScenario(`blockAssetsForChunk`, { chunk: `app` }) |
| 70 | + }) |
| 71 | +}) |
67 | 72 |
|
68 | | -// describe(`Deleted app chunk assets`, () => { |
69 | | -// it(`Block resources`, () => { |
70 | | -// cy.exec(`npm run chunks -- restore`) |
71 | | -// cy.exec(`npm run chunks -- block app`) |
72 | | -// }) |
73 | | -// runTests() |
74 | | -// }) |
75 | | -// }) |
| 73 | +const runSuiteForPage = (label, pagePath) => { |
| 74 | + describe(`Missing "${label}" resources`, () => { |
| 75 | + describe(`Missing "${label}" page query results`, () => { |
| 76 | + runBlockedScenario(`blockAssetsForPage`, { |
| 77 | + pagePath, |
| 78 | + filter: `page-data`, |
| 79 | + }) |
| 80 | + }) |
| 81 | + describe(`Missing "${label}" page page-template asset`, () => { |
| 82 | + runBlockedScenario(`blockAssetsForPage`, { |
| 83 | + pagePath, |
| 84 | + filter: `page-template`, |
| 85 | + }) |
| 86 | + }) |
| 87 | + describe(`Missing "${label}" page extra assets`, () => { |
| 88 | + runBlockedScenario(`blockAssetsForPage`, { |
| 89 | + pagePath, |
| 90 | + filter: `extra`, |
| 91 | + }) |
| 92 | + }) |
| 93 | + describe(`Missing all "${label}" page assets`, () => { |
| 94 | + runBlockedScenario(`blockAssetsForPage`, { |
| 95 | + pagePath, |
| 96 | + filter: `all`, |
| 97 | + }) |
| 98 | + }) |
| 99 | + }) |
| 100 | +} |
76 | 101 |
|
77 | | -// const runSuiteForPage = (label, path) => { |
78 | | -// describe(`Missing "${label}" resources`, () => { |
79 | | -// describe(`Missing "${label}" page query results`, () => { |
80 | | -// it(`Block resources`, () => { |
81 | | -// cy.exec(`npm run chunks -- restore`) |
82 | | -// cy.exec(`npm run chunks -- block-page ${path} query-result`) |
83 | | -// }) |
84 | | -// runTests() |
85 | | -// }) |
86 | | -// describe(`Missing "${label}" page page-template asset`, () => { |
87 | | -// it(`Block resources`, () => { |
88 | | -// cy.exec(`npm run chunks -- restore`) |
89 | | -// cy.exec(`npm run chunks -- block-page ${path} page-template`) |
90 | | -// }) |
91 | | -// runTests() |
92 | | -// }) |
93 | | -// describe(`Missing "${label}" page extra assets`, () => { |
94 | | -// it(`Block resources`, () => { |
95 | | -// cy.exec(`npm run chunks -- restore`) |
96 | | -// cy.exec(`npm run chunks -- block-page ${path} extra`) |
97 | | -// }) |
98 | | -// runTests() |
99 | | -// }) |
100 | | -// describe(`Missing all "${label}" page assets`, () => { |
101 | | -// it(`Block resources`, () => { |
102 | | -// cy.exec(`npm run chunks -- restore`) |
103 | | -// cy.exec(`npm run chunks -- block-page ${path} all`) |
104 | | -// }) |
105 | | -// runTests() |
106 | | -// }) |
107 | | -// }) |
108 | | -// } |
| 102 | +runSuiteForPage(`Index`, `/`) |
| 103 | +runSuiteForPage(`Page-2`, `/page-2/`) |
| 104 | +runSuiteForPage(`404`, `/404.html`) |
109 | 105 |
|
110 | | -// runSuiteForPage(`Index`, `/`) |
111 | | -// runSuiteForPage(`Page-2`, `/page-2/`) |
112 | | -// runSuiteForPage(`404`, `/404.html`) |
113 | | - |
114 | | -// describe(`Cleanup`, () => { |
115 | | -// it(`Restore resources`, () => { |
116 | | -// cy.exec(`npm run chunks -- restore`) |
117 | | -// }) |
118 | | -// }) |
| 106 | +describe(`Cleanup`, () => { |
| 107 | + it(`Restore resources`, () => { |
| 108 | + cy.task(`restoreAllBlockedResources`) |
| 109 | + }) |
| 110 | +}) |
0 commit comments