Skip to content

Commit 609f855

Browse files
committed
Implemented the server start callback in the whole tests
1 parent ca72e94 commit 609f855

39 files changed

+77
-146
lines changed

lib/server/WebDAVServer.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ var WebDAVServer = (function () {
168168
if (callback)
169169
throw new Error('Illegal arguments');
170170
}
171-
if (_callback) {
172-
var _callback_1 = _callback;
173-
_callback = function () {
174-
if (_callback_1)
175-
_callback_1(_this.server);
176-
};
177-
}
178171
if (!this.server) {
179172
this.server = http.createServer(function (req, res) {
180173
var method = _this.methods[_this.normalizeMethodName(req.method)];
@@ -218,7 +211,10 @@ var WebDAVServer = (function () {
218211
});
219212
});
220213
}
221-
this.server.listen(_port, this.options.hostname, _callback);
214+
this.server.listen(_port, this.options.hostname, function () {
215+
if (_callback)
216+
_callback(_this.server);
217+
});
222218
};
223219
WebDAVServer.prototype.stop = function (callback) {
224220
if (this.server) {

src/server/WebDAVServer.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,6 @@ export class WebDAVServer
253253
if(callback)
254254
throw new Error('Illegal arguments');
255255
}
256-
if(_callback)
257-
{
258-
const _callback_ = _callback;
259-
_callback = () => {
260-
if(_callback_)
261-
_callback_(this.server);
262-
}
263-
}
264256

265257
if(!this.server)
266258
{
@@ -318,7 +310,10 @@ export class WebDAVServer
318310
})
319311
}
320312

321-
this.server.listen(_port, this.options.hostname, _callback);
313+
this.server.listen(_port, this.options.hostname, () => {
314+
if(_callback)
315+
_callback(this.server);
316+
});
322317
}
323318

324319
stop(callback : () => void)

test/root.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
2-
var path = require('path'),
2+
var webdav = require('../lib/index.js'),
3+
path = require('path'),
34
fs = require('fs')
45

56
module.exports = (callback, options) => {
@@ -27,6 +28,9 @@ module.exports = (callback, options) => {
2728
{
2829
try
2930
{
31+
if(fn.constructor !== Function)
32+
throw fn;
33+
3034
let callback = (valid, details) => {
3135
callback = (valid, details) => { }
3236

@@ -58,7 +62,11 @@ module.exports = (callback, options) => {
5862
}
5963
}
6064
setTimeout(() => callback(false, 'Timeout'), options.timeout);
61-
fn(callback)
65+
66+
const server = new webdav.WebDAVServer();
67+
server.start(options.port + this.index, () => {
68+
fn(callback, server);
69+
})
6270
}
6371
catch(ex)
6472
{
@@ -82,14 +90,14 @@ module.exports = (callback, options) => {
8290
f = path.join(root, f);
8391
try
8492
{
85-
require(f)(isValid, options, index);
93+
require(f)(isValid.bind({ index }), options, index);
8694
}
8795
catch(ex)
8896
{
8997
if(options.showExceptions)
9098
console.error(ex);
9199

92-
isValid(f, isValid => isValid(false, ex));
100+
isValid(f, ex);
93101
}
94102
})
95103
})

test/tests/addResourceTree.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
var webdav = require('../../lib/index.js'),
33
Client = require('webdav-fs');
44

5-
module.exports = (test, options, index) => test('addResourceTree method', isValid =>
5+
module.exports = (test, options, index) => test('addResourceTree method', (isValid, server) =>
66
{
7-
var server = new webdav.WebDAVServer();
8-
server.start(options.port + index);
97
isValid = isValid.multiple(2, server);
108
const _ = (e, cb) => {
119
if(e)

test/tests/authentication.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
var webdav = require('../../lib/index.js'),
33
Client = require('webdav-fs');
44

5-
module.exports = (test, options, index) => test('authentication', isValid =>
5+
module.exports = (test, options, index) => test('authentication', (isValid, server) =>
66
{
7-
var server = new webdav.WebDAVServer();
8-
server.start(options.port + index);
97
isValid = isValid.multiple(2, server);
108
const _ = (e, cb) => {
119
if(e)

test/tests/copyPhysicalFile.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ var webdav = require('../../lib/index.js'),
55
path = require('path'),
66
fs = require('fs');
77

8-
module.exports = (test, options, index) => test('copy a physical file', isValid =>
8+
module.exports = (test, options, index) => test('copy a physical file', (isValid, server) =>
99
{
10-
var server = new webdav.WebDAVServer();
11-
server.start(options.port + index);
1210
isValid = isValid.multiple(2, server);
1311
const _ = (e, cb) => {
1412
if(e)

test/tests/copyPhysicalFolder.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ var webdav = require('../../lib/index.js'),
55
path = require('path'),
66
fs = require('fs');
77

8-
module.exports = (test, options, index) => test('copy a physical folder', isValid =>
8+
module.exports = (test, options, index) => test('copy a physical folder', (isValid, server) =>
99
{
10-
var server = new webdav.WebDAVServer();
11-
server.start(options.port + index);
1210
isValid = isValid.multiple(2, server);
1311
const _ = (e, cb) => {
1412
if(e)

test/tests/copyProp.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ var webdav = require('../../lib/index.js'),
33
request = require('request'),
44
xmljs = require('xml-js');
55

6-
module.exports = (test, options, index) => test('copy a virtual resource with properties', isValid =>
6+
module.exports = (test, options, index) => test('copy a virtual resource with properties', (isValid, server) =>
77
{
8-
var server = new webdav.WebDAVServer();
9-
server.start(options.port + index);
108
isValid = isValid.multiple(1, server);
119
const _ = (e, cb) => {
1210
if(e)

test/tests/copyVirtualFile.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ var webdav = require('../../lib/index.js'),
33
request = require('request'),
44
Client = require('webdav-fs');
55

6-
module.exports = (test, options, index) => test('copy a virtual file', isValid =>
6+
module.exports = (test, options, index) => test('copy a virtual file', (isValid, server) =>
77
{
8-
var server = new webdav.WebDAVServer();
9-
server.start(options.port + index);
108
isValid = isValid.multiple(1, server);
119
const _ = (e, cb) => {
1210
if(e)

test/tests/copyVirtualFolder.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ var webdav = require('../../lib/index.js'),
33
request = require('request'),
44
Client = require('webdav-fs');
55

6-
module.exports = (test, options, index) => test('copy a virtual folder', isValid =>
6+
module.exports = (test, options, index) => test('copy a virtual folder', (isValid, server) =>
77
{
8-
var server = new webdav.WebDAVServer();
9-
server.start(options.port + index);
108
isValid = isValid.multiple(1, server);
119
const _ = (e, cb) => {
1210
if(e)

0 commit comments

Comments
 (0)