From 9eb4bfee74a380c59103a46ea02bdb4cc1e96c7b Mon Sep 17 00:00:00 2001 From: Phillip9587 Date: Tue, 22 Oct 2024 20:44:27 +0200 Subject: [PATCH] test: remove AsyncLocalStorage check with the minimum supported node version set to v18 we can remove the AsyncLocalStorage support check as it was added in v13.10.0 and v12.17.0 --- test/json.js | 18 +++--------------- test/raw.js | 18 +++--------------- test/text.js | 18 +++--------------- test/urlencoded.js | 18 +++--------------- 4 files changed, 12 insertions(+), 60 deletions(-) diff --git a/test/json.js b/test/json.js index 6a36eada..5d16cbe6 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 0afcdcab..aef565fc 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 f581e651..73c5842e 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 761dfa31..10b6a1f0 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 {} - } -}