-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
154 lines (140 loc) · 4.01 KB
/
index.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
// show the dev tools by default
require('nw.gui').Window.get().showDevTools(null, function (_win) {
// _win.resizeTo(800, 1000)
})
var Mocha = require('mocha')
var mocha = new Mocha
mocha.reporter('loca')
mocha.bail(true)
mocha.slow(1000)
mocha.timeout(1000*60*60)
// pass the browser context
mocha.suite.emit('pre-require', window, null, mocha)
// iframe onload callback
var page = {
onload: null,
load: function (cb) {
page.onload = cb
}
}
// iframe/shortcuts
var iframe = {jquery: null, window: null, self: null}
var $ = null, win = null
// database client
var client = null
// server process
var server = null
// misc
var spawn = require('child_process').spawn
var async = require('async')
var aw = require('ansi-webkit')
// db
var Client = require('./lib/client')
// mw
var express = require('express')
var admin = require('express-admin')
var config = require('./lib/config')
// ----------------------------------------------------------------------------
jQuery(() => {
jQuery('body')
.append(`<iframe id="iframe" src="http://localhost:${config.admin.port}/login"></iframe>`)
jQuery('#iframe').on('load', function (e) {
iframe = {
jquery: this.contentWindow.$,
window: this.contentWindow,
self: this
}
// shortcuts
$ = iframe.jquery
win = iframe.window
page.onload()
// setTimeout(() => page.onload(), 3000)
})
// wait until the iframe is loaded
page.load(() => {
mocha.run((failures) => {
process.on('exit', () => {
process.exit(failures)
})
})
})
})
// ----------------------------------------------------------------------------
config.db.forEach((db) => {
config.engine.forEach((engine) => {
describe(`${engine} - ${db}`, () => {
before((done) => {
async.series([
// start server
(done) => {
server = express()
.use(admin({
config: require(`${config.dpath}/config/${db}/${engine}/config.json`),
settings: require(`${config.dpath}/config/${db}/${engine}/settings.json`),
custom: require(`${config.dpath}/config/${db}/custom.json`),
users: require(`${config.dpath}/config/${db}/users.json`),
}))
.listen(config.admin.port, () => {
setTimeout(done, 500)
})
},
// reload login page
(done) => {
win.location.reload()
page.load(done)
},
// login
(done) => {
$('[name=username]').val(config.admin.user)
$('[name=password]').val(config.admin.pass)
$('[type=submit]').trigger('click')
page.load(done)
},
// connect to database
(done) => {
var options = {
mysql: {...config.mysql, database: db},
pg: {...config.pg, database: db},
sqlite: {database: `${config.dpath}/fixtures/${db}/${db}.sqlite`}
}
client = Client(engine)
client.connect(options[engine], done)
}
], done)
})
// load test suite
if (/relationships/.test(db)) {
config.test
.filter((path) => path.includes('relationships'))
.forEach((path) => {
jQuery('head').append(`<script src="${path}"></script>`)
})
}
else if (/data-types/.test(db) /*&& /pg/.test(engine)*/) {
config.test
.filter((path) => path.includes('data-types'))
.forEach((path) => {
jQuery('head').append(`<script src="${path}"></script>`)
})
}
after((done) => {
async.series([
// logout
(done) => {
$('[href$="/logout"]')[0].click()
page.load(done)
},
// disconnect from db
(done) => {
client.disconnect()
done()
},
// close server
(done) => {
server.close(done)
}
], done)
})
})
})
})