-
Notifications
You must be signed in to change notification settings - Fork 0
/
importing-reloaded.spec.js
104 lines (77 loc) · 1.75 KB
/
importing-reloaded.spec.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
import { test, dev } from './index.js'
/**
* index -> a, b
* a+
* b+ -> a
*
* a+ <==
*
* b+ <==
*
* => b should get last version of a
*/
test('importing updated file', dev({ open: false }), async (t) => {
const reportA = t.spy(() => {})
const reportB = t.spy(() => {})
await t.page.exposeFunction('reportA', reportA)
await t.page.exposeFunction('reportB', reportB)
const reported = Promise.all([reportA, reportB].map((spy) => spy.nextCall()))
await t.fixture.write({
'index.js': `
import './a.js'
import './b.js'
`,
'a.js': `
const value = 'a0'
export default value
reportA(value)
if (import.meta.hot) {
import.meta.hot.accept()
}
`,
'b.js': `
import a from './a.js'
const value = 'b0:' + a
export default value
reportB(value)
if (import.meta.hot) {
import.meta.hot.accept()
}
`,
})
await t.page.goto(t.server.url)
await reported
reportA.wasCalledWith('a0')
reportB.wasCalledWith('b0:a0')
// --- a changes ---
await reportA.nextCallAfter(async () => {
await t.fixture.write({
'a.js': `
const value = 'a1'
export default value
reportA(value)
if (import.meta.hot) {
import.meta.hot.accept()
}
`,
})
})
reportA.wasCalledWith('a1')
reportB.wasNotCalled()
// --- b changes ---
await reportB.nextCallAfter(async () => {
await t.fixture.write({
'b.js': `
import a from './a.js'
const value = 'b1:' + a
export default value
reportB(value)
if (import.meta.hot) {
import.meta.hot.accept()
}
`,
})
})
reportA.wasNotCalled()
reportB.wasCalledWith('b1:a1')
})