forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnightwatchPlugin.spec.js
134 lines (112 loc) · 4.45 KB
/
nightwatchPlugin.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
jest.setTimeout(process.env.APPVEYOR ? 300000 : 120000)
const fs = require('fs-extra')
const path = require('path')
const create = require('@vue/cli-test-utils/createTestProject')
const createServer = require('@vue/cli-test-utils/createServer')
describe('nightwatch e2e plugin', () => {
let project
beforeAll(async () => {
project = await create('e2e-nightwatch', {
plugins: {
'@vue/cli-plugin-babel': {},
'@vue/cli-plugin-e2e-nightwatch': {},
'@vue/cli-plugin-eslint': {
config: 'airbnb',
lintOn: 'save'
}
}
})
await project.run('vue-cli-service lint')
await fs.copy(path.join(__dirname, './lib/globals-generated.js'),
path.join(project.dir, 'tests/e2e/globals-generated.js'))
const config = {
globals_path: './tests/e2e/globals-generated.js'
}
await project.write('nightwatch.json', JSON.stringify(config))
})
test('should run all tests successfully', async () => {
await project.run(`vue-cli-service test:e2e --headless`)
let results = await project.read('test_results.json')
results = JSON.parse(results)
expect(Object.keys(results.modules)).toEqual([
'test-with-pageobjects',
'test'
])
})
test('should accept the --url cli option', async () => {
let server
try {
await project.run(`vue-cli-service build`)
server = createServer({ root: path.join(project.dir, 'dist') })
await new Promise((resolve, reject) => {
server.listen(8080, err => {
if (err) return reject(err)
resolve()
})
})
await project.run(`vue-cli-service test:e2e --headless --url http://127.0.0.1:8080/`)
let results = await project.read('test_results.json')
results = JSON.parse(results)
expect(Object.keys(results.modules)).toEqual([
'test-with-pageobjects',
'test'
])
} finally {
server && server.close()
}
})
test('should run single test with custom nightwatch.json', async () => {
await project.run(`vue-cli-service test:e2e --headless -t tests/e2e/specs/test.js`)
let results = await project.read('test_results.json')
results = JSON.parse(results)
expect(Object.keys(results.modules)).toEqual([
'test'
])
})
test('should run single test with custom nightwatch.json and selenium server', async () => {
await project.run(`vue-cli-service test:e2e --headless --use-selenium -t tests/e2e/specs/test.js`)
let results = await project.read('test_results.json')
results = JSON.parse(results)
let testSettings = await project.read('test_settings.json')
testSettings = JSON.parse(testSettings)
expect(testSettings).toHaveProperty('selenium')
expect(testSettings.selenium.start_process).toStrictEqual(true)
expect(testSettings.selenium).toHaveProperty('cli_args')
expect(Object.keys(results.modules)).toEqual([
'test'
])
})
test('should run tests in parallel', async () => {
await project.run(`vue-cli-service test:e2e --headless --parallel`)
let results = await project.read('test_results.json')
results = JSON.parse(results)
let testSettings = await project.read('test_settings.json')
testSettings = JSON.parse(testSettings)
expect(testSettings.parallel_mode).toStrictEqual(true)
expect(testSettings.test_workers).toStrictEqual({
enabled: true,
workers: 'auto'
})
expect(Object.keys(results.modules).sort()).toEqual([
'test', 'test-with-pageobjects'
])
})
// This test requires Firefox to be installed
const testFn = process.env.APPVEYOR ? test.skip : test
testFn('should run single test with custom nightwatch.conf.js in firefox', async () => {
// nightwatch.conf.js take priority over nightwatch.json
const copyConfig = fs.copy(path.join(__dirname, './lib/nightwatch.conf.js'),
path.join(project.dir, 'nightwatch.conf.js'))
const copyGlobals = fs.copy(path.join(__dirname, './lib/globals-gecko.js'),
path.join(project.dir, 'tests/e2e/globals-gecko.js'))
await Promise.all([copyConfig, copyGlobals])
await project.run(`vue-cli-service test:e2e --headless --env firefox -t tests/e2e/specs/test.js`)
let results = await project.read('test_results_gecko.json')
results = JSON.parse(results)
expect(Object.keys(results.modules)).toEqual([
'test'
])
expect(results.modules.test).toHaveProperty('reportPrefix')
expect(results.modules.test.reportPrefix).toMatch(/^FIREFOX_.+/)
})
})