Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Prevent clobbered timer globals from interfering with runner #164

Merged
merged 2 commits into from Aug 19, 2014
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -7,6 +7,11 @@ var Coverage = require('./coverage');
var Leaks = require('./leaks');
var Utils = require('./utils');

// prevent libraries like Sinon from clobbering global time functions
var Date = global.Date;
var setTimeout = global.setTimeout;
var clearTimeout = global.clearTimeout;
var setImmediate = global.setImmediate;

// Declare internals

@@ -18,8 +18,32 @@ var before = lab.before;
var after = lab.after;
var expect = _Lab.expect;

// save references to timer globals

var setTimeout = global.setTimeout;
var clearTimeout = global.clearTimeout;
var setImmediate = global.setImmediate;

describe('Runner', function () {
var poisonPill = function () {

This comment has been minimized.

Copy link
@geek

geek Aug 19, 2014

Member

Please add a newline after each function declaration: https://github.com/hapijs/hapi/blob/master/docs/Style.md

This comment has been minimized.

Copy link
@miloconway

miloconway Aug 19, 2014

Author

@wpreul newline added

throw new Error("Don't use global time-related stuff.");
};
// We can't poison global.Date because the normal implementation of
// global.setTimeout uses it [1] so if the runnable.js keeps a copy of
// global.setTimeout (like it's supposed to), that will blow up.
// [1]: https://github.com/joyent/node/blob/7fc835afe362ebd30a0dbec81d3360bd24525222/lib/timers.js#L74
var setupPoisonPills = function (finished) {
global.setTimeout = poisonPill;
global.clearTimeout = poisonPill;
global.setImmediate = poisonPill;
finished();
};
var teardownPoisonPills = function (finished) {
global.setTimeout = setTimeout;
global.clearTimeout = clearTimeout;
global.setImmediate = setImmediate;
finished();
};

it('sets environment', { parallel: false }, function (done) {

@@ -420,6 +444,10 @@ describe('Runner', function () {
it('ignores second error', function (done) {

var script = Lab.script();
script.before(setupPoisonPills);

script.after(teardownPoisonPills);

script.experiment('test', function () {

script.test('1', function (finished) {
@@ -443,6 +471,10 @@ describe('Runner', function () {
it('override test timeout', function (done) {

var script = Lab.script();
script.before(setupPoisonPills);

script.after(teardownPoisonPills);

script.experiment('test', function () {

script.test('timeout', { timeout: 5 }, function (finished) {
@@ -462,6 +494,10 @@ describe('Runner', function () {
it('disable test timeout', function (done) {

var script = Lab.script();
script.before(setupPoisonPills);

script.after(teardownPoisonPills);

script.experiment('test', { timeout: 5 }, function () {

script.test('timeout', { timeout: 0 }, function (finished) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.