forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.spec.js
194 lines (170 loc) · 6.65 KB
/
serve.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
jest.setTimeout(80000)
const path = require('path')
const fs = require('fs-extra')
const { defaultPreset } = require('@vue/cli/lib/options')
const create = require('@vue/cli-test-utils/createTestProject')
const serve = require('@vue/cli-test-utils/serveWithPuppeteer')
const sleep = n => new Promise(resolve => setTimeout(resolve, n))
test('serve', async () => {
const project = await create('e2e-serve', defaultPreset)
await serve(
() => project.run('vue-cli-service serve'),
async ({ page, nextUpdate, helpers }) => {
const msg = `Welcome to Your Vue.js App`
expect(await helpers.getText('h1')).toMatch(msg)
// test hot reload
const file = await project.read(`src/App.vue`)
project.write(`src/App.vue`, file.replace(msg, `Updated`))
await nextUpdate() // wait for child stdout update signal
try {
await page.waitForFunction(selector => {
const el = document.querySelector(selector)
return el && el.textContent.includes('Updated')
}, { timeout: 60000 }, 'h1')
} catch (e) {
if (process.env.APPVEYOR && e.message.match('timeout')) {
// AppVeyor VM is so slow that there's a large chance this test cases will time out,
// we have to tolerate such failures.
console.error(e)
} else {
throw e
}
}
}
)
})
test('serve with router', async () => {
const project = await create('e2e-serve-router', Object.assign({}, defaultPreset, {
plugins: {
'@vue/cli-plugin-router': {}
}
}))
await serve(
() => project.run('vue-cli-service serve'),
async ({ page, helpers }) => {
expect(await helpers.getText('h1')).toMatch(`Welcome to Your Vue.js App`)
expect(await helpers.hasElement('#nav')).toBe(true)
expect(await helpers.hasClass('a[href="#/"]', 'router-link-exact-active')).toBe(true)
expect(await helpers.hasClass('a[href="#/about"]', 'router-link-exact-active')).toBe(false)
await page.click('a[href="#/about"]')
await sleep(1000)
expect(await helpers.getText('h1')).toMatch(`This is an about page`)
expect(await helpers.hasElement('#nav')).toBe(true)
expect(await helpers.hasClass('a[href="#/"]', 'router-link-exact-active')).toBe(false)
expect(await helpers.hasClass('a[href="#/about"]', 'router-link-exact-active')).toBe(true)
}
)
})
test('serve with legacy router option', async () => {
const project = await create('e2e-serve-legacy-router', Object.assign({}, defaultPreset, {
router: true,
routerHistoryMode: true
}))
await serve(
() => project.run('vue-cli-service serve'),
async ({ page, helpers }) => {
expect(await helpers.getText('h1')).toMatch(`Welcome to Your Vue.js App`)
expect(await helpers.hasElement('#nav')).toBe(true)
expect(await helpers.hasClass('a[href="/"]', 'router-link-exact-active')).toBe(true)
expect(await helpers.hasClass('a[href="/about"]', 'router-link-exact-active')).toBe(false)
await page.click('a[href="/about"]')
await sleep(1000)
expect(await helpers.getText('h1')).toMatch(`This is an about page`)
expect(await helpers.hasElement('#nav')).toBe(true)
expect(await helpers.hasClass('a[href="/"]', 'router-link-exact-active')).toBe(false)
expect(await helpers.hasClass('a[href="/about"]', 'router-link-exact-active')).toBe(true)
}
)
})
test('serve with legacy vuex option', async () => {
const project = await create('e2e-serve-legacy-vuex', Object.assign({}, defaultPreset, {
vuex: true
}))
await serve(
() => project.run('vue-cli-service serve'),
async ({ page, helpers }) => {
expect(await helpers.getText('h1')).toMatch(`Welcome to Your Vue.js App`)
}
)
})
test('serve with inline entry', async () => {
const project = await create('e2e-serve-inline-entry', defaultPreset)
await fs.move(
path.resolve(project.dir, 'src/main.js'),
path.resolve(project.dir, 'src/index.js')
)
await serve(
() => project.run('vue-cli-service serve src/index.js'),
async ({ page, nextUpdate, helpers }) => {
const msg = `Welcome to Your Vue.js App`
expect(await helpers.getText('h1')).toMatch(msg)
// test hot reload
const file = await project.read(`src/App.vue`)
project.write(`src/App.vue`, file.replace(msg, `Updated`))
await nextUpdate() // wait for child stdout update signal
try {
await page.waitForFunction(selector => {
const el = document.querySelector(selector)
return el && el.textContent.includes('Updated')
}, { timeout: 60000 }, 'h1')
} catch (e) {
if (process.env.APPVEYOR && e.message.match('timeout')) {
// AppVeyor VM is so slow that there's a large chance this test cases will time out,
// we have to tolerate such failures.
console.error(e)
} else {
throw e
}
}
}
)
})
test('serve with no public dir', async () => {
const project = await create('e2e-serve-no-public', defaultPreset)
await fs.remove(path.resolve(project.dir, 'public'))
await serve(
() => project.run('vue-cli-service serve'),
async ({ page, nextUpdate, helpers }) => {
const msg = `Welcome to Your Vue.js App`
expect(await helpers.getText('h1')).toMatch(msg)
// test hot reload
const file = await project.read(`src/App.vue`)
project.write(`src/App.vue`, file.replace(msg, `Updated`))
await nextUpdate() // wait for child stdout update signal
try {
await page.waitForFunction(selector => {
const el = document.querySelector(selector)
return el && el.textContent.includes('Updated')
}, { timeout: 60000 }, 'h1')
} catch (e) {
if (process.env.APPVEYOR && e.message.match('timeout')) {
// AppVeyor VM is so slow that there's a large chance this test cases will time out,
// we have to tolerate such failures.
console.error(e)
} else {
throw e
}
}
}
)
})
test('dart sass', async () => {
const project = await create('test-dart-sass', exports.defaultPreset = {
useConfigFiles: false,
cssPreprocessor: 'dart-sass',
plugins: {}
})
// should build successfully
await project.run('vue-cli-service build')
})
test('use a single websocket connection for HMR', async () => {
const project = await create('e2e-serve-hmr', defaultPreset)
await serve(
() => project.run('vue-cli-service serve'),
async ({ helpers, requestUrls }) => {
const msg = `Welcome to Your Vue.js App`
expect(await helpers.getText('h1')).toMatch(msg)
expect(requestUrls.filter(url => url.includes('sockjs-node')).length).toBe(1)
}
)
})