diff --git a/test/json.js b/test/json.js index 6a36ead..5d16cbe 100644 --- a/test/json.js +++ b/test/json.js @@ -1,17 +1,13 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('safe-buffer').Buffer var http = require('http') var request = require('supertest') var bodyParser = require('..') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('bodyParser.json()', function () { it('should parse JSON', function (done) { request(createServer()) @@ -512,13 +508,13 @@ describe('bodyParser.json()', function () { }) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { before(function () { var jsonParser = bodyParser.json() var store = { foo: 'bar' } this.server = createServer(function (req, res, next) { - var asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + var asyncLocalStorage = new AsyncLocalStorage() asyncLocalStorage.run(store, function () { jsonParser(req, res, function (err) { @@ -762,11 +758,3 @@ function shouldContainInBody (str) { 'expected \'' + res.text + '\' to contain \'' + str + '\'') } } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -} diff --git a/test/raw.js b/test/raw.js index 0afcdca..aef565f 100644 --- a/test/raw.js +++ b/test/raw.js @@ -1,17 +1,13 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('safe-buffer').Buffer var http = require('http') var request = require('supertest') var bodyParser = require('..') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('bodyParser.raw()', function () { before(function () { this.server = createServer() @@ -330,13 +326,13 @@ describe('bodyParser.raw()', function () { }) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { before(function () { var rawParser = bodyParser.raw() var store = { foo: 'bar' } this.server = createServer(function (req, res, next) { - var asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + var asyncLocalStorage = new AsyncLocalStorage() asyncLocalStorage.run(store, function () { rawParser(req, res, function (err) { @@ -503,11 +499,3 @@ function createServer (opts) { }) }) } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -} diff --git a/test/text.js b/test/text.js index f581e65..73c5842 100644 --- a/test/text.js +++ b/test/text.js @@ -1,17 +1,13 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('safe-buffer').Buffer var http = require('http') var request = require('supertest') var bodyParser = require('..') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('bodyParser.text()', function () { before(function () { this.server = createServer() @@ -371,13 +367,13 @@ describe('bodyParser.text()', function () { }) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { before(function () { var textParser = bodyParser.text() var store = { foo: 'bar' } this.server = createServer(function (req, res, next) { - var asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + var asyncLocalStorage = new AsyncLocalStorage() asyncLocalStorage.run(store, function () { textParser(req, res, function (err) { @@ -566,11 +562,3 @@ function createServer (opts) { }) }) } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -} diff --git a/test/urlencoded.js b/test/urlencoded.js index 761dfa3..10b6a1f 100644 --- a/test/urlencoded.js +++ b/test/urlencoded.js @@ -1,17 +1,13 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('safe-buffer').Buffer var http = require('http') var request = require('supertest') var bodyParser = require('..') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('bodyParser.urlencoded()', function () { before(function () { this.server = createServer() @@ -756,13 +752,13 @@ describe('bodyParser.urlencoded()', function () { }) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { before(function () { var urlencodedParser = bodyParser.urlencoded() var store = { foo: 'bar' } this.server = createServer(function (req, res, next) { - var asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + var asyncLocalStorage = new AsyncLocalStorage() asyncLocalStorage.run(store, function () { urlencodedParser(req, res, function (err) { @@ -969,11 +965,3 @@ function expectKeyCount (count) { assert.strictEqual(Object.keys(JSON.parse(res.text)).length, count) } } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -}