Skip to content

Commit

Permalink
fixes for latest tap version
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Apr 6, 2016
1 parent 5d8e77d commit 149d7ab
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 178 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"restler": "3.2.2",
"rimraf": "^2.3.2",
"superagent": "^1.4.0",
"tap": "^0.7.1",
"tap": "^5.7.0",
"zombie": "^4.2.1"
},
"scripts": {
Expand Down
40 changes: 14 additions & 26 deletions tests/test_back.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function testNock (t) {
}, function(res) {

t.equal(res.statusCode, 200);
res.on('end', function() {
res.once('end', function() {
t.ok(dataCalled);
scope.done();
t.end();
Expand Down Expand Up @@ -55,6 +55,11 @@ function nockBackWithFixture (t, scopesLoaded) {
});
}

function setOriginalModeOnEnd(t, nockBack) {
t.once('end', function() {
nockBack.setMode(originalMode);
});
}



Expand Down Expand Up @@ -87,21 +92,15 @@ tap.test('nockBack wild tests', function (nw) {
testNock(t);
});


nw.test('nock back doesn\'t do anything', function (t) {
nockBackWithFixture(t, false);
});

})
.on('end', function () {

nockBack.setMode(originalMode);
setOriginalModeOnEnd(nw, nockBack);

nw.end();
});




tap.test('nockBack dryrun tests', function (nw) {

// Manually disable net connectivity to confirm that dryrun enables it.
Expand Down Expand Up @@ -179,7 +178,7 @@ tap.test('nockBack dryrun tests', function (nw) {

});

req.on('error', function(err) {
req.once('error', function(err) {
if (err.code !== 'ECONNREFUSED') {
throw err;
}
Expand All @@ -189,16 +188,12 @@ tap.test('nockBack dryrun tests', function (nw) {
req.end();
});
});
})
.on('end', function () {

nockBack.setMode(originalMode);
setOriginalModeOnEnd(nw, nockBack);

nw.end();
});




tap.test('nockBack record tests', function (nw) {
nockBack.setMode('record');

Expand Down Expand Up @@ -318,16 +313,10 @@ tap.test('nockBack record tests', function (nw) {
});

nw.end();
})
.on('end', function () {

nockBack.setMode(originalMode);

setOriginalModeOnEnd(nw, nockBack);
});




tap.test('nockBack lockdown tests', function (nw) {
nockBack.fixtures = __dirname + '/fixtures';
nockBack.setMode('lockdown');
Expand Down Expand Up @@ -358,9 +347,8 @@ tap.test('nockBack lockdown tests', function (nw) {

req.end();
});
})
.on('end', function () {

nockBack.setMode(originalMode);
setOriginalModeOnEnd(nw, nockBack);

nw.end();
});
15 changes: 10 additions & 5 deletions tests/test_back_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ var fs = require('fs');
var originalMode;
var fixture;

function rimrafOnEnd(t) {
t.once('end', function() {
rimraf.sync(fixture);
});
}

test('setup', function(t) {
originalMode = nockBack.currentMode;

Expand Down Expand Up @@ -41,8 +47,8 @@ test('recording', function(t) {
res.resume();
});
});
}).once('end', function() {
rimraf.sync(fixture);

rimrafOnEnd(t);
});

test('passes custom options to recorder', function(t) {
Expand All @@ -60,9 +66,8 @@ test('passes custom options to recorder', function(t) {
// See https://nodejs.org/api/stream.html#stream_class_stream_readable
res.resume();
});
})
}).once('end', function() {
rimraf.sync(fixture);
});
rimrafOnEnd(t);
});

test('teardown', function(t) {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('emits request and replied events', function(t) {
});

test('emits no match when no match and no mock', function(t) {
nock.emitter.on('no match', function(req) {
nock.emitter.once('no match', function(req) {
t.end();
});

Expand Down

0 comments on commit 149d7ab

Please sign in to comment.