Skip to content

Commit 2d78b43

Browse files
author
zhenlineo
committed
Added support to auto start neo4j for tests on windows
1 parent 5da2482 commit 2d78b43

File tree

4 files changed

+80
-19
lines changed

4 files changed

+80
-19
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ See files under `examples/` on how to use.
8484
This runs the test suite against a fresh download of Neo4j.
8585
Or `npm test` if you already have a running version of a compatible Neo4j server.
8686

87+
### Testing on windows
88+
Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable `Path`.
89+
To run the same test suite, run `.\runTest.ps1` instead in powershell with admin right.
90+
The admin right is required to start/stop Neo4j properly as a system service.
91+
While there is no need to grab admin right if you are running tests against an existing Neo4j server using `npm test`.
92+
8793
## A note on numbers and the Integer type
8894
For this driver to fully map to the Neo4j type system handling of 64-bits Integers is needed.
8995
Javascript can saftely represent numbers between `-(2`<sup>`53`</sup>` - 1)` and `(2`<sup>`53`</sup>` - 1)`.

gulpfile.js

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ var uglify = require('gulp-uglify');
2727
var concat = require('gulp-concat');
2828
var gutil = require('gulp-util');
2929
var download = require("gulp-download");
30-
var gunzip = require('gulp-gunzip');
31-
var untar = require('gulp-untar2');
3230
var shell = require('gulp-shell');
3331
var jasmine = require('gulp-jasmine');
3432
var jasmineBrowser = require('gulp-jasmine-browser');
@@ -39,6 +37,9 @@ var watch = require('gulp-watch');
3937
var batch = require('gulp-batch');
4038
var fs = require("fs");
4139
var runSequence = require('run-sequence');
40+
var path = require('path');
41+
var childProcess = require("child_process");
42+
var decompress = require('gulp-decompress');
4243

4344
gulp.task('default', ["test"]);
4445

@@ -131,15 +132,6 @@ gulp.task('test', function(cb){
131132
runSequence('test-nodejs', 'test-browser', cb);
132133
});
133134

134-
gulp.task('start-neo4j', ['download-neo4j'], shell.task([
135-
'chmod +x build/neo4j-enterprise*/bin/neo4j',
136-
'build/neo4j-enterprise*/bin/neo4j start',
137-
]));
138-
139-
gulp.task('stop-neo4j', shell.task([
140-
'build/neo4j-enterprise*/bin/neo4j stop',
141-
]));
142-
143135
gulp.task('test-nodejs', ['nodejs'], function () {
144136
return gulp.src('test/**/*.test.js')
145137
.pipe(jasmine({
@@ -167,12 +159,62 @@ gulp.task('watch', function () {
167159
}));
168160
});
169161

162+
var neo4jLinuxUrl = 'http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-M01-NIGHTLY-unix.tar.gz';
163+
var neo4jWinUrl = 'http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-M01-NIGHTLY-windows.zip';
164+
var neo4jHome = './build/neo4j-enterprise-3.0.0-M01';
165+
var isWin = /^win/.test(process.platform);
166+
170167
gulp.task('download-neo4j', function() {
171-
if( !fs.existsSync('./build/neo4j-enterprise-3.0.0-alpha') ) {
168+
if( !fs.existsSync(neo4jHome) ) {
172169
// Need to download
173-
return download("http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-M01-NIGHTLY-unix.tar.gz")
174-
.pipe(gunzip())
175-
.pipe(untar())
176-
.pipe(gulp.dest('./build'));
170+
if(isWin) {
171+
return download(neo4jWinUrl)
172+
.pipe(decompress({strip: 1}))
173+
.pipe(gulp.dest(neo4jHome));
174+
}
175+
else {
176+
return download(neo4jLinuxUrl)
177+
.pipe(decompress({strip: 1}))
178+
.pipe(gulp.dest(neo4jHome));
179+
}
180+
}
181+
});
182+
183+
var runPowershell = function( cmd ) {
184+
var spawn = childProcess.spawn, child;
185+
child = spawn("powershell.exe",[
186+
'Import-Module ' + neo4jHome + '/bin/Neo4j-Management.psd1;' + cmd]);
187+
child.stdout.on("data",function(data){
188+
console.log("Powershell Data: " + data);
189+
});
190+
child.stderr.on("data",function(data){
191+
console.log("Powershell Errors: " + data);
192+
});
193+
child.on("exit",function(){
194+
console.log("Powershell Script finished");
195+
});
196+
child.stdin.end(); //end input
197+
}
198+
199+
gulp.task('start-neo4j', ['download-neo4j'], function() {
200+
if(isWin) {
201+
runPowershell('Install-Neo4jServer -Neo4jServer ' + neo4jHome + ' -Name neo4j-js;' +
202+
'Start-Neo4jServer -Neo4jServer ' + neo4jHome + ' -ServiceName neo4j-js');
203+
} else {
204+
shell.task([
205+
'chmod +x' + neo4jHome + 'bin/neo4j',
206+
neo4jHome + '/bin/neo4j start',
207+
]);
208+
}
209+
});
210+
211+
gulp.task('stop-neo4j', function() {
212+
if(isWin) {
213+
runPowershell('Stop-Neo4jServer -Neo4jServer ' + neo4jHome + ' -ServiceName neo4j-js;' +
214+
'Uninstall-Neo4jServer -Neo4jServer ' + neo4jHome + ' -ServiceName neo4j-js');
215+
} else {
216+
shell.task([
217+
neo4jHome + '/bin/neo4j stop',
218+
])
177219
}
178220
});

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@
2929
"gulp-concat": "^2.6.0",
3030
"gulp-cucumber": "^0.0.12",
3131
"gulp-download": "^0.0.1",
32-
"gulp-gunzip": "^0.0.3",
3332
"gulp-if": "^1.2.5",
3433
"gulp-jasmine": "^2.1.0",
3534
"gulp-jasmine-browser": "^0.2.3",
3635
"gulp-shell": "^0.4.3",
3736
"gulp-uglify": "^1.4.2",
38-
"gulp-untar2": "^0.1.0",
3937
"gulp-util": "^3.0.6",
4038
"gulp-watch": "^4.3.5",
4139
"jasmine-reporters": "^2.0.7",
4240
"phantomjs2-ext": "^0.1.0",
4341
"run-sequence": "^1.1.4",
4442
"through2": "~2.0.0",
4543
"vinyl-buffer": "^1.0.0",
46-
"vinyl-source-stream": "^1.1.0"
44+
"vinyl-source-stream": "^1.1.0",
45+
"gulp-decompress": "^1.2.0"
4746
}
4847
}

runTests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Try
2+
{
3+
npm install
4+
npm run start-neo4j
5+
npm test
6+
}
7+
Catch [system.exception]
8+
{
9+
"Error found while running tests"
10+
}
11+
Finally
12+
{
13+
npm run stop-neo4j
14+
}

0 commit comments

Comments
 (0)