From d5d43638279e8f0e96776794d5ce7e9f31e761c2 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 756f7d86..3b5cc653 100644 --- a/test/json.js +++ b/test/json.js @@ -1,16 +1,12 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage 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()) @@ -511,13 +507,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) { @@ -761,11 +757,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 23e537ac..3f9a7284 100644 --- a/test/raw.js +++ b/test/raw.js @@ -1,16 +1,12 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage 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() @@ -329,13 +325,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) { @@ -502,11 +498,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 db9b21ee..021612aa 100644 --- a/test/text.js +++ b/test/text.js @@ -1,16 +1,12 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage 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() @@ -370,13 +366,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) { @@ -565,11 +561,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 9590a00a..dfe0eb9f 100644 --- a/test/urlencoded.js +++ b/test/urlencoded.js @@ -1,16 +1,12 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage 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() @@ -755,13 +751,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) { @@ -968,11 +964,3 @@ function expectKeyCount (count) { assert.strictEqual(Object.keys(JSON.parse(res.text)).length, count) } } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -}