/
hmr.js
71 lines (58 loc) · 1.94 KB
/
hmr.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
if (Cypress.env("GATSBY_COMMAND") === `develop`) {
before(() => {
cy.exec(`npm run reset`)
})
after(() => {
cy.exec(`npm run reset`)
})
it(`Can hot-reload markdown content`, () => {
cy.visit(`/hmr`, {
onBeforeLoad: win => {
cy.spy(win.console, "log").as(`hmrConsoleLog`)
},
}).waitForRouteChange()
cy.get(`h2`).invoke(`text`).should(`eq`, `Lorem`)
cy.exec(
`npm run update -- --file src/pages/hmr.mdx --exact --replacements "Lorem:Ipsum"`
)
cy.get(`@hmrConsoleLog`).should(`be.calledWithMatch`, `App is up to date`)
cy.wait(1000)
cy.get(`h2`).invoke(`text`).should(`eq`, `Ipsum`)
})
it(`Can hot-reload react content (i.e. change prop in mdx content)`, () => {
cy.visit(`/hmr`, {
onBeforeLoad: win => {
cy.spy(win.console, "log").as(`hmrConsoleLog`)
},
}).waitForRouteChange()
cy.get(`[data-testid="test-prop-edit"]`)
.invoke(`text`)
.should(`eq`, `prop-before`)
cy.exec(
`npm run update -- --file src/pages/hmr.mdx --exact --replacements "prop-before:prop-after"`
)
cy.get(`@hmrConsoleLog`).should(`be.calledWithMatch`, `App is up to date`)
cy.wait(1000)
cy.get(`[data-testid="test-prop-edit"]`)
.invoke(`text`)
.should(`eq`, `prop-after`)
})
it(`Can hot-reload imported js components`, () => {
cy.visit(`/hmr`, {
onBeforeLoad: win => {
cy.spy(win.console, "log").as(`hmrConsoleLog`)
},
}).waitForRouteChange()
cy.get(`[data-testid="test-imported-edit"]`)
.invoke(`text`)
.should(`eq`, `component-before`)
cy.exec(
`npm run update -- --file src/components/hmr-component-edit.js --exact --replacements "component-before:component-after"`
)
cy.get(`@hmrConsoleLog`).should(`be.calledWithMatch`, `App is up to date`)
cy.wait(1000)
cy.get(`[data-testid="test-imported-edit"]`)
.invoke(`text`)
.should(`eq`, `component-after`)
})
}