From 6d22e0095cb260290004d105d4dc6407b0a980b5 Mon Sep 17 00:00:00 2001 From: Phillip9587 Date: Tue, 5 Nov 2024 12:21:40 +0100 Subject: [PATCH] cleanup: 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/express.json.js | 18 +++--------------- test/express.raw.js | 18 +++--------------- test/express.text.js | 18 +++--------------- test/express.urlencoded.js | 18 +++--------------- test/res.download.js | 20 ++++---------------- test/res.sendFile.js | 20 ++++---------------- 6 files changed, 20 insertions(+), 92 deletions(-) diff --git a/test/express.json.js b/test/express.json.js index c92d8234bb..c87f491e27 100644 --- a/test/express.json.js +++ b/test/express.json.js @@ -1,15 +1,11 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('node:buffer').Buffer var express = require('..') var request = require('supertest') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('express.json()', function () { it('should parse JSON', function (done) { request(createApp()) @@ -503,13 +499,13 @@ describe('express.json()', function () { }) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { before(function () { var app = express() var store = { foo: 'bar' } app.use(function (req, res, next) { - req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + req.asyncLocalStorage = new AsyncLocalStorage() req.asyncLocalStorage.run(store, next) }) @@ -756,11 +752,3 @@ function shouldContainInBody (str) { 'expected \'' + res.text + '\' to contain \'' + str + '\'') } } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -} diff --git a/test/express.raw.js b/test/express.raw.js index cd526e3913..2a4893ba26 100644 --- a/test/express.raw.js +++ b/test/express.raw.js @@ -1,15 +1,11 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('node:buffer').Buffer var express = require('..') var request = require('supertest') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('express.raw()', function () { before(function () { this.app = createApp() @@ -328,13 +324,13 @@ describe('express.raw()', function () { }) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { before(function () { var app = express() var store = { foo: 'bar' } app.use(function (req, res, next) { - req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + req.asyncLocalStorage = new AsyncLocalStorage() req.asyncLocalStorage.run(store, next) }) @@ -514,11 +510,3 @@ function createApp (options) { return app } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -} diff --git a/test/express.text.js b/test/express.text.js index e5fd9e415a..27a647a8d8 100644 --- a/test/express.text.js +++ b/test/express.text.js @@ -1,15 +1,11 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('node:buffer').Buffer var express = require('..') var request = require('supertest') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('express.text()', function () { before(function () { this.app = createApp() @@ -361,13 +357,13 @@ describe('express.text()', function () { }) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { before(function () { var app = express() var store = { foo: 'bar' } app.use(function (req, res, next) { - req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + req.asyncLocalStorage = new AsyncLocalStorage() req.asyncLocalStorage.run(store, next) }) @@ -568,11 +564,3 @@ function createApp (options) { return app } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -} diff --git a/test/express.urlencoded.js b/test/express.urlencoded.js index 2bf72b79b9..0d2d2eb3bb 100644 --- a/test/express.urlencoded.js +++ b/test/express.urlencoded.js @@ -1,15 +1,11 @@ 'use strict' var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('node:buffer').Buffer var express = require('..') var request = require('supertest') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('express.urlencoded()', function () { before(function () { this.app = createApp() @@ -606,13 +602,13 @@ describe('express.urlencoded()', function () { }) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { before(function () { var app = express() var store = { foo: 'bar' } app.use(function (req, res, next) { - req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + req.asyncLocalStorage = new AsyncLocalStorage() req.asyncLocalStorage.run(store, next) }) @@ -829,11 +825,3 @@ function expectKeyCount (count) { assert.strictEqual(Object.keys(JSON.parse(res.text)).length, count) } } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -} diff --git a/test/res.download.js b/test/res.download.js index 3ccd0c7744..8edcdb6a1f 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -2,7 +2,7 @@ var after = require('after'); var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('node:buffer').Buffer var express = require('..'); var path = require('path') @@ -11,10 +11,6 @@ var utils = require('./support/utils') var FIXTURES_PATH = path.join(__dirname, 'fixtures') -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('res', function(){ describe('.download(path)', function(){ it('should transfer as an attachment', function(done){ @@ -91,14 +87,14 @@ describe('res', function(){ .expect(200, cb); }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { it('should presist store', function (done) { var app = express() var cb = after(2, done) var store = { foo: 'bar' } app.use(function (req, res, next) { - req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + req.asyncLocalStorage = new AsyncLocalStorage() req.asyncLocalStorage.run(store, next) }) @@ -125,7 +121,7 @@ describe('res', function(){ var store = { foo: 'bar' } app.use(function (req, res, next) { - req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + req.asyncLocalStorage = new AsyncLocalStorage() req.asyncLocalStorage.run(store, next) }) @@ -488,11 +484,3 @@ describe('res', function(){ }) }) }) - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -} diff --git a/test/res.sendFile.js b/test/res.sendFile.js index d0b4b1b50c..48d1b16907 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -2,7 +2,7 @@ var after = require('after'); var assert = require('assert') -var asyncHooks = tryRequire('async_hooks') +var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage var Buffer = require('node:buffer').Buffer var express = require('../') , request = require('supertest') @@ -11,10 +11,6 @@ var path = require('path'); var fixtures = path.join(__dirname, 'fixtures'); var utils = require('./support/utils'); -var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function' - ? describe - : describe.skip - describe('res', function(){ describe('.sendFile(path)', function () { it('should error missing path', function (done) { @@ -267,14 +263,14 @@ describe('res', function(){ .expect(200, 'got 404 error', done) }) - describeAsyncHooks('async local storage', function () { + describe('async local storage', function () { it('should presist store', function (done) { var app = express() var cb = after(2, done) var store = { foo: 'bar' } app.use(function (req, res, next) { - req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + req.asyncLocalStorage = new AsyncLocalStorage() req.asyncLocalStorage.run(store, next) }) @@ -300,7 +296,7 @@ describe('res', function(){ var store = { foo: 'bar' } app.use(function (req, res, next) { - req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage() + req.asyncLocalStorage = new AsyncLocalStorage() req.asyncLocalStorage.run(store, next) }) @@ -901,11 +897,3 @@ function createApp(path, options, fn) { return app; } - -function tryRequire (name) { - try { - return require(name) - } catch (e) { - return {} - } -}