-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
80 lines (58 loc) · 2.21 KB
/
gulpfile.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
import gulp from 'gulp';
import mochaPhantomJS from 'gulp-mocha-phantomjs';
import fs from 'fs';
import browserify from 'browserify';
import babelify from 'babelify';
import buffer from 'vinyl-buffer';
import source from 'vinyl-source-stream';
import sourcemaps from 'gulp-sourcemaps';
import util from 'gulp-util';
import glob from 'glob';
import localhost from 'localhost';
const port = 8080;
const server = localhost('./');
const scripts_to_watch = ['**/*.js', '!node_modules/**/*', '!test/components/**/*', '!test/bundle.js', '!test/specs/index.js'];
gulp.task('localhost', done => {
server.listen(port, done);
util.log('Listening on port', util.colors.cyan(port));
});
gulp.task('index_tests', () => {
const root = 'test/specs/';
// for the given files in the test directory, create an index
return glob('test/specs/**/*.spec.js', (err, files) => {
files = files.filter(path => path !== '!test/specs/index.js');
// Write line to the index file
const index = files.map(name => `import('${name.replace(root, './')}');`);
index.push('');
fs.writeFileSync('test/specs/index.js', index.join('\n'));
});
});
gulp.task('watch', gulp.series('localhost', () => gulp.watch(scripts_to_watch, {interval: 500}, ['test'])));
gulp.task('close', () => server.close());
gulp.task('bundle', gulp.series('index_tests', () =>
// Package up the specs directory into a single file called config.js
browserify('./test/setup_bundle.js', {debug: true, paths: './'})
.transform(babelify)
.bundle()
.on('error', util.log.bind(util, 'Browserify Error'))
.pipe(source('./bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./test/'))
));
gulp.task('test', gulp.series('bundle', testSpecs('test/bundle.html')));
gulp.task('watch_bundle', () => gulp.watch(scripts_to_watch, {interval: 500}, ['bundle']));
gulp.task('default', gulp.series('localhost', 'test', done => {
util.log(`Closing localhost:${port}`);
server.close(done);
}));
function testSpecs(pathname) {
return function stream() {
const path = `http://localhost:${port}/${pathname}`;
const stream = mochaPhantomJS();
stream.write({path, reporter: 'spec'});
stream.end();
return stream;
};
}