-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
58 lines (53 loc) · 1.75 KB
/
gulpfile.js
File metadata and controls
58 lines (53 loc) · 1.75 KB
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
const gulp = require('gulp');
const istanbul = require('gulp-istanbul');
const mocha = require('gulp-mocha');
const { MongoClient } = require('mongodb');
const config = {
connectionString: 'mongodb://localhost/local-db',
port: 3002,
bodyParserType: 'url',
categories: ['animals', 'cars', 'clothing', 'man', 'school', 'space', 'sport', 'women', 'sex', 'movies', 'music', 'programming', 'work', 'other', 'games']
}
// @ts-ignore
gulp.task('server-start', ['server-stop'], () => {
return Promise.resolve()
.then(() => require('./Forum/app').init(config))
.then((app) => {
const port = process.env.PORT || config.port;
return app.listen(config.port, () =>
console.log(`Magic is running at :${port}`));
})
.then((server) => {
return require('socket.io').listen(server);
})
.then((io) => {
io.on('connection', function(socket) {
// Server side receiving the message then emmiting
// it again for each client to handle
socket.on('chat message', (msgData) => {
io.emit('chat message', msgData);
});
});
})
.catch((err) => {
console.log(err);
});
})
gulp.task('server-stop', () => {
return MongoClient.connect(config.connectionString)
.then((db) => {
db.dropDatabase();
})
})
// @ts-ignore
gulp.task('tests:browser', ['server-start'], () => {
return gulp.src('./Forum/tests/browser/**/*.js')
.pipe(mocha({
// reporter: 'nyan',
timeout: 10000,
}))
.once('end', () => {
// @ts-ignore
gulp.start('server-stop');
})
})