forked from neo4j/neo4j-javascript-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
336 lines (292 loc) · 9.39 KB
/
gulpfile.babel.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/**
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gulp = require('gulp');
var through = require('through2');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var download = require("gulp-download");
var jasmine = require('gulp-jasmine');
var babelify = require('babelify');
var babel = require('gulp-babel');
var watch = require('gulp-watch');
var batch = require('gulp-batch');
var replace = require('gulp-replace');
var decompress = require('gulp-decompress');
var fs = require("fs-extra");
var runSequence = require('run-sequence');
var path = require('path');
var minimist = require('minimist');
var cucumber = require('gulp-cucumber');
var install = require("gulp-install");
var file = require('gulp-file');
var semver = require('semver');
var sharedNeo4j = require('./test/internal/shared-neo4j').default;
var ts = require('gulp-typescript');
var JasmineConsoleReporter = require('jasmine-console-reporter');
var karmaServer = require('karma').Server;
var transformTools = require('browserify-transform-tools');
/**
* Useful to investigate resource leaks in tests. Enable to see active sockets and file handles after the 'test' task.
*/
var enableActiveNodeHandlesLogging = false;
gulp.task('default', ["test"]);
gulp.task('browser', function(cb){
runSequence('build-browser-test', 'build-browser', cb);
});
/** Build all-in-one files for use in the browser */
gulp.task('build-browser', function () {
var browserOutput = 'lib/browser';
// Our app bundler
var appBundler = browserify({
entries: ['src/index.js'],
cache: {},
standalone: 'neo4j',
packageCache: {}
}).transform(babelifyTransform())
.transform(browserifyTransformNodeToBrowserRequire())
.bundle();
// Un-minified browser package
appBundler
.on('error', gutil.log)
.pipe(source('neo4j-web.js'))
.pipe(gulp.dest(browserOutput));
return appBundler
.on('error', gutil.log)
.pipe(source('neo4j-web.min.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(browserOutput));
});
gulp.task('build-browser-test', function(){
var browserOutput = 'build/browser/';
var testFiles = [];
return gulp.src(['./test/**/*.test.js', '!./test/**/node/*.js'])
.pipe( through.obj( function( file, enc, cb ) {
if(file.path.indexOf('examples.test.js') < 0) {
testFiles.push( file.path );
}
cb();
}, function(cb) {
// At end-of-stream, push the list of files to the next step
this.push( testFiles );
cb();
}))
.pipe( through.obj( function( testFiles, enc, cb) {
browserify({
entries: testFiles,
cache: {},
debug: true
}).transform(babelifyTransform())
.transform(browserifyTransformNodeToBrowserRequire())
.bundle(function () {
cb();
})
.on('error', gutil.log)
.pipe(source('neo4j-web.test.js'))
.pipe(gulp.dest(browserOutput));
},
function(cb) {
cb()
}
));
});
var buildNode = function(options) {
return gulp.src(options.src)
.pipe(babel(babelConfig()))
.pipe(gulp.dest(options.dest))
};
gulp.task('nodejs', function(){
return buildNode({
src: 'src/**/*.js',
dest: 'lib'
});
});
gulp.task('all', function(cb){
runSequence('nodejs', 'browser', cb);
});
// prepares directory for package.test.js
gulp.task('install-driver-into-sandbox', ['nodejs'], function(){
var testDir = path.join('build', 'sandbox');
fs.emptyDirSync(testDir);
var packageJsonContent = JSON.stringify({
'private': true,
'dependencies': {
'neo4j-driver': __dirname
}
});
return file('package.json', packageJsonContent, {src:true})
.pipe(gulp.dest(testDir))
.pipe(install());
});
gulp.task('test', function (cb) {
runSequence('run-ts-declaration-tests', 'test-nodejs', 'test-browser', 'run-tck', function (err) {
if (err) {
var exitCode = 2;
console.log('[FAIL] test task failed - exiting with code ' + exitCode);
return process.exit(exitCode);
}
return cb();
});
});
gulp.task('test-nodejs', ['install-driver-into-sandbox'], function () {
return gulp.src(['./test/**/*.test.js', '!./test/**/browser/*.js'])
.pipe(jasmine({
includeStackTrace: true,
reporter: newJasmineConsoleReporter()
})).on('end', logActiveNodeHandles);
});
gulp.task('test-browser', function (cb) {
runSequence('all', 'run-browser-test', cb)
});
gulp.task('run-browser-test', function(cb){
runSequence('run-browser-test-firefox', cb);
});
gulp.task('run-browser-test-chrome', function(cb){
new karmaServer({
configFile: __dirname + '/test/browser/karma-chrome.conf.js',
}, cb).start();
});
gulp.task('run-browser-test-firefox', function(cb){
new karmaServer({
configFile: __dirname + '/test/browser/karma-firefox.conf.js',
}, cb).start();
});
gulp.task('run-browser-test-edge', function(cb){
new karmaServer({
configFile: __dirname + '/test/browser/karma-edge.conf.js',
}, cb).start();
});
gulp.task('run-browser-test-ie', function (cb) {
new karmaServer({
configFile: __dirname + '/test/browser/karma-ie.conf.js',
}, cb).start();
});
gulp.task('watch', function () {
return watch('src/**/*.js', batch(function (events, done) {
gulp.start('all', done);
}));
});
gulp.task('watch-n-test', ['test-nodejs'], function () {
return gulp.watch(['src/**/*.js', "test/**/*.js"], ['test-nodejs'] );
});
var featureFiles = 'https://s3-eu-west-1.amazonaws.com/remoting.neotechnology.com/driver-compliance/tck.tar.gz';
var featureHome = './build/tck';
gulp.task('download-tck', function() {
return download(featureFiles)
.pipe(decompress({strip: 1}))
.pipe(gulp.dest(featureHome));
});
gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
return gulp.src(featureHome + "/*").pipe(cucumber({
'steps': 'test/v1/tck/steps/*.js',
'format': 'progress',
'tags' : ['~@fixed_session_pool', '~@db', '~@equality', '~@streaming_and_cursor_navigation']
})).on('end', logActiveNodeHandles);
});
/** Set the project version, controls package.json and version.js */
gulp.task('set', function() {
// Get the --version arg from command line
var version = minimist(process.argv.slice(2), { string: 'version' }).version;
if (!semver.valid(version)) {
throw 'Invalid version "' + version + '"';
}
// Change the version in relevant files
var versionFile = path.join('src', 'version.js');
return gulp.src([versionFile], {base: "./"})
.pipe(replace('0.0.0-dev', version))
.pipe(gulp.dest('./'));
});
var neo4jHome = path.resolve('./build/neo4j');
gulp.task('start-neo4j', function (done) {
sharedNeo4j.start(neo4jHome, process.env.NEOCTRL_ARGS);
done();
});
gulp.task('stop-neo4j', function (done) {
sharedNeo4j.stop(neo4jHome);
done();
});
gulp.task('run-stress-tests', function () {
return gulp.src('test/**/stress.test.js')
.pipe(jasmine({
includeStackTrace: true,
reporter: newJasmineConsoleReporter()
})).on('end', logActiveNodeHandles);
});
gulp.task('run-ts-declaration-tests', function () {
var failed = false;
return gulp.src(['test/types/**/*', 'types/**/*'], {base: '.'})
.pipe(ts({
module: 'es6',
target: 'es6',
noImplicitAny: true,
noImplicitReturns: true,
strictNullChecks: true,
}))
.on('error', function () {
failed = true;
})
.on('finish', function () {
if (failed) {
console.log('[ERROR] TypeScript declarations contain errors. Exiting...');
process.exit(1);
}
})
.pipe(gulp.dest('build/test/types'));
});
function logActiveNodeHandles() {
if (enableActiveNodeHandlesLogging) {
console.log('-- Active NodeJS handles START\n', process._getActiveHandles(), '\n-- Active NodeJS handles END');
}
}
function newJasmineConsoleReporter() {
return new JasmineConsoleReporter({
colors: 1,
cleanStack: 1,
verbosity: 4,
listStyle: 'indent',
activity: false
});
}
function babelifyTransform() {
return babelify.configure(babelConfig());
}
function babelConfig() {
return {
presets: ['env'], plugins: ['transform-runtime']
};
}
function browserifyTransformNodeToBrowserRequire() {
var nodeRequire = '/node';
var browserRequire = '/browser';
return transformTools.makeRequireTransform('bodeToBrowserRequireTransform',
{evaluateArguments: true},
function (args, opts, cb) {
var requireArg = args[0];
var endsWithNodeRequire = requireArg.slice(-nodeRequire.length) === nodeRequire;
if (endsWithNodeRequire) {
var newRequireArg = requireArg.replace(nodeRequire, browserRequire);
return cb(null, 'require(\'' + newRequireArg + '\')');
} else {
return cb();
}
});
}