forked from brianvoe/vue-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
127 lines (106 loc) · 2.81 KB
/
test.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
var fs = require('fs-extra')
var path = require('path')
var spawn = require('child_process').spawn
var processRoot = process.cwd()
var testFolder = path.join(processRoot, '/test')
function installSample (type) {
return new Promise(function (resolve, reject) {
console.log('installing sample')
var install = spawn('vue-build', ['init', `-s=${type}`], { stdio: 'inherit' })
install.on('close', (code) => {
console.log(`finished installing sample`)
resolve()
})
})
}
function installPackages () {
return new Promise(function (resolve, reject) {
console.log('package installation')
var install = spawn('yarn', ['install'], { stdio: 'inherit' })
install.on('close', (code) => {
if (code !== 0) {
reject(code)
}
console.log(`finished installing packages`)
resolve()
})
})
}
function production () {
return new Promise(function (resolve, reject) {
console.log('building dist')
var prod = spawn('vue-build', ['prod'], { stdio: 'inherit' })
prod.on('close', (code) => {
if (code !== 0) {
reject(code)
}
console.log(`finished building dist`)
resolve()
})
})
}
function test (type) {
return new Promise(function (resolve, reject) {
console.log('testing app')
var prod = spawn('vue-build', [type], { stdio: 'inherit' })
prod.on('close', (code) => {
if (code !== 0) {
reject(code)
}
console.log(`finished testing app`)
resolve()
})
})
}
function simple () {
return new Promise(function (resolve, reject) {
process.chdir(processRoot)
fs.emptyDir(testFolder, function (err) {
if (err) { console.error(err) }
process.chdir(testFolder)
installSample('simple')
.then(installPackages)
.then(production)
.then(resolve)
.catch((err) => { reject(err) })
})
})
}
function full () {
return new Promise(function (resolve, reject) {
process.chdir(processRoot)
fs.emptyDir(testFolder, function (err) {
if (err) { console.error(err) }
process.chdir(testFolder)
installSample('full')
.then(installPackages)
.then(production)
.then(() => test('unit'))
.then(() => test('e2e'))
.then(resolve)
.catch((err) => { reject(err) })
})
})
}
function library () {
return new Promise(function (resolve, reject) {
process.chdir(processRoot)
fs.emptyDir(testFolder, function (err) {
if (err) { console.error(err) }
process.chdir(testFolder)
installSample('library')
.then(installPackages)
.then(production)
.then(() => test('unit'))
.then(resolve)
.catch((err) => { reject(err) })
})
})
}
// Run samples one at a time
simple()
.then(full)
.then(library)
.catch((error) => {
console.log('Tests failed: ', error)
})