forked from neo4j/neo4j-javascript-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
316 lines (278 loc) · 7.76 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
/**
* Copyright (c) 2002-2020 "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 JasmineReporter = require('jasmine-spec-reporter').SpecReporter
const karma = require('karma')
const log = require('fancy-log')
const JasmineExec = require('jasmine')
/**
* 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('test-nodejs-unit', () => {
return runJasmineTests('#unit*')
})
gulp.task('test-nodejs-stub', () => {
return runJasmineTests('#stub*')
})
gulp.task('test-nodejs-integration', () => {
return runJasmineTests('#integration*')
})
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 () {
// example: gulp set --x 4.0.2
// Get the --x arg from command line
const command = minimist(process.argv.slice(2), { string: 'x' })
const version = command.x
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('./'))
})
gulp.task('start-neo4j', function (done) {
sharedNeo4j.start()
done()
})
gulp.task('stop-neo4j', function (done) {
sharedNeo4j.stop()
done()
})
gulp.task(
'install-driver-into-testkit-backend',
gulp.series('nodejs', function () {
const dir = path.join('build', 'testkit-backend')
fs.emptyDirSync(dir)
const packageJsonContent = JSON.stringify({
private: true,
dependencies: {
'neo4j-driver': __dirname
}
})
return file('package.json', packageJsonContent, { src: true })
.pipe(gulp.dest(dir))
.pipe(install())
})
)
gulp.task(
'testkit-backend',
gulp.series('install-driver-into-testkit-backend', function () {
return gulp
.src('testkit-backend/**/*.js')
.pipe(babel())
.pipe(gulp.dest('build/testkit-backend'))
})
)
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,
moduleResolution: 'node',
types: []
})
)
.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 JasmineReporter({
colors: {
enabled: true
},
spec: {
displayDuration: true,
displayErrorMessages: true,
displayStacktrace: true,
displayFailed: true,
displaySuccessful: true,
displayPending: false
},
summary: {
displayFailed: true,
displayStacktrace: true,
displayErrorMessages: true
}
})
}
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()
}
function runJasmineTests (filterString) {
return new Promise((resolve, reject) => {
const jasmine = new JasmineExec()
jasmine.loadConfigFile('./spec/support/jasmine.json')
jasmine.loadHelpers()
jasmine.loadSpecs()
jasmine.configureDefaultReporter({
print: () => {}
})
jasmine.addReporter(newJasmineConsoleReporter())
jasmine.onComplete(passed => {
if (passed) {
resolve()
} else {
reject(new Error('tests failed'))
}
})
jasmine.execute(null, filterString)
})
}