From 0b7edf84a772f1d09d5902d9b1bde08ff7190a70 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 24 Mar 2016 01:35:19 -0700 Subject: [PATCH] try to make wrtc test reliable on node v5 --- test/server.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/test/server.js b/test/server.js index 5b79168..b62bfc1 100644 --- a/test/server.js +++ b/test/server.js @@ -1,14 +1,19 @@ var Client = require('../') var common = require('./common') var test = require('tape') -var wrtc +var wrtc = require('electron-webrtc')() + +var wrtcReady = false +wrtc.electronDaemon.once('ready', function () { + wrtcReady = true +}) var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705' var peerId = new Buffer('01234567890123456789') var peerId2 = new Buffer('12345678901234567890') var torrentLength = 50000 -function serverTest (t, serverType, serverFamily, cb) { +function serverTest (t, serverType, serverFamily) { t.plan(30) var hostname = serverFamily === 'inet6' @@ -107,7 +112,8 @@ function serverTest (t, serverType, serverFamily, cb) { t.equal(data.incomplete, 0) client1.destroy() - server.close(cb) + server.close() + if (serverType === 'ws') wrtc.close() }) }) }) @@ -119,12 +125,14 @@ function serverTest (t, serverType, serverFamily, cb) { } test('websocket server', function (t) { - wrtc = require('electron-webrtc')() - wrtc.electronDaemon.once('ready', function () { - serverTest(t, 'ws', 'inet', function () { - wrtc.close() - }) - }) + if (wrtcReady) { + runTest() + } else { + wrtc.electronDaemon.once('ready', runTest) + } + function runTest () { + serverTest(t, 'ws', 'inet') + } }) test('http ipv4 server', function (t) {