forked from neo4j/neo4j-javascript-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
239 lines (209 loc) · 6.05 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
/**
* Copyright (c) 2002-2019 "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.
*/
const browserify = require('browserify')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
const gulp = require('gulp')
const uglify = require('gulp-uglify')
const jasmine = require('gulp-jasmine')
const babel = require('gulp-babel')
const watch = require('gulp-watch')
const batch = require('gulp-batch')
const replace = require('gulp-replace')
const fs = require('fs-extra')
const path = require('path')
const minimist = require('minimist')
const install = require('gulp-install')
const file = require('gulp-file')
const semver = require('semver')
const sharedNeo4j = require('./test/internal/shared-neo4j').default
const ts = require('gulp-typescript')
const JasmineConsoleReporter = require('jasmine-console-reporter')
const karma = require('karma')
const log = require('fancy-log')
/**
* Useful to investigate resource leaks in tests. Enable to see active sockets and file handles after the 'test' task.
*/
const enableActiveNodeHandlesLogging = false
/** Build all-in-one files for use in the browser */
gulp.task('browser', async function () {
const browserOutput = 'lib/browser'
// Our app bundler
const appBundler = browserify({
entries: ['src/index.js'],
cache: {},
standalone: 'neo4j',
packageCache: {},
transform: ['babelify', './support/inject-browser-transform']
}).bundle()
// Un-minified browser package
await appBundler
.on('error', log.error)
.pipe(source('neo4j-web.js'))
.pipe(gulp.dest(browserOutput))
await appBundler
.on('error', log.error)
.pipe(source('neo4j-web.min.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(browserOutput))
})
gulp.task('nodejs', function () {
return gulp
.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('lib'))
})
// prepares directory for package.test.js
gulp.task(
'install-driver-into-sandbox',
gulp.series('nodejs', function () {
const testDir = path.join('build', 'sandbox')
fs.emptyDirSync(testDir)
const 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-nodejs',
gulp.series('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('run-browser-test-chrome', function (cb) {
runKarma('chrome', cb)
})
gulp.task('run-browser-test-firefox', function (cb) {
runKarma('firefox', cb)
})
gulp.task('run-browser-test', gulp.series('run-browser-test-firefox'))
gulp.task('watch', function () {
return watch(
'src/**/*.js',
batch(function (events, done) {
gulp.start('all', done)
})
)
})
gulp.task(
'watch-n-test',
gulp.series('test-nodejs', function () {
return gulp.watch(['src/**/*.js', 'test/**/*.js'], ['test-nodejs'])
})
)
/** Set the project version, controls package.json and version.js */
gulp.task('set', function () {
// Get the --version arg from command line
const version = minimist(process.argv.slice(2), { string: 'version' }).version
if (!semver.valid(version)) {
throw new Error(`Invalid version "${version}"`)
}
// Change the version in relevant files
const versionFile = path.join('src', 'version.js')
return gulp
.src([versionFile], { base: './' })
.pipe(replace('0.0.0-dev', version))
.pipe(gulp.dest('./'))
})
const 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 (done) {
return gulp
.src(['test/types/**/*', 'types/**/*'], { base: '.' })
.pipe(
ts({
module: 'es6',
target: 'es6',
noImplicitAny: true,
noImplicitReturns: true,
strictNullChecks: true
})
)
.pipe(gulp.dest('build/test/types'))
.on('error', err => done(err))
.on('end', () => done())
})
gulp.task('all', gulp.series('nodejs', 'browser'))
gulp.task('test-browser', gulp.series('browser', 'run-browser-test'))
gulp.task(
'test',
gulp.series('run-ts-declaration-tests', 'test-nodejs', 'test-browser')
)
gulp.task('default', gulp.series('test'))
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 runKarma (browser, cb) {
new karma.Server(
{
configFile: path.join(__dirname, `/test/browser/karma-${browser}.conf.js`)
},
function (exitCode) {
exitCode ? process.exit(exitCode) : cb()
}
).start()
}