Skip to content

Commit 92faae9

Browse files
committed
cleanup: remove AsyncLocalStorage check from tests
1 parent cc751cf commit 92faae9

7 files changed

+21
-92
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ unreleased
22
========================
33

44
* Remove `Object.setPrototypeOf` polyfill
5+
* cleanup: remove AsyncLocalStorage check from tests
56

67
5.0.1 / 2024-10-08
78
==========

test/express.json.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
'use strict'
22

33
var assert = require('assert')
4-
var asyncHooks = tryRequire('async_hooks')
4+
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
55
var Buffer = require('node:buffer').Buffer
66
var express = require('..')
77
var request = require('supertest')
88

9-
var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
10-
? describe
11-
: describe.skip
12-
139
describe('express.json()', function () {
1410
it('should parse JSON', function (done) {
1511
request(createApp())
@@ -503,13 +499,13 @@ describe('express.json()', function () {
503499
})
504500
})
505501

506-
describeAsyncHooks('async local storage', function () {
502+
describe('async local storage', function () {
507503
before(function () {
508504
var app = express()
509505
var store = { foo: 'bar' }
510506

511507
app.use(function (req, res, next) {
512-
req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()
508+
req.asyncLocalStorage = new AsyncLocalStorage()
513509
req.asyncLocalStorage.run(store, next)
514510
})
515511

@@ -756,11 +752,3 @@ function shouldContainInBody (str) {
756752
'expected \'' + res.text + '\' to contain \'' + str + '\'')
757753
}
758754
}
759-
760-
function tryRequire (name) {
761-
try {
762-
return require(name)
763-
} catch (e) {
764-
return {}
765-
}
766-
}

test/express.raw.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
'use strict'
22

33
var assert = require('assert')
4-
var asyncHooks = tryRequire('async_hooks')
4+
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
55
var Buffer = require('node:buffer').Buffer
66
var express = require('..')
77
var request = require('supertest')
88

9-
var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
10-
? describe
11-
: describe.skip
12-
139
describe('express.raw()', function () {
1410
before(function () {
1511
this.app = createApp()
@@ -328,13 +324,13 @@ describe('express.raw()', function () {
328324
})
329325
})
330326

331-
describeAsyncHooks('async local storage', function () {
327+
describe('async local storage', function () {
332328
before(function () {
333329
var app = express()
334330
var store = { foo: 'bar' }
335331

336332
app.use(function (req, res, next) {
337-
req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()
333+
req.asyncLocalStorage = new AsyncLocalStorage()
338334
req.asyncLocalStorage.run(store, next)
339335
})
340336

@@ -514,11 +510,3 @@ function createApp (options) {
514510

515511
return app
516512
}
517-
518-
function tryRequire (name) {
519-
try {
520-
return require(name)
521-
} catch (e) {
522-
return {}
523-
}
524-
}

test/express.text.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
'use strict'
22

33
var assert = require('assert')
4-
var asyncHooks = tryRequire('async_hooks')
4+
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
55
var Buffer = require('node:buffer').Buffer
66
var express = require('..')
77
var request = require('supertest')
88

9-
var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
10-
? describe
11-
: describe.skip
12-
139
describe('express.text()', function () {
1410
before(function () {
1511
this.app = createApp()
@@ -361,13 +357,13 @@ describe('express.text()', function () {
361357
})
362358
})
363359

364-
describeAsyncHooks('async local storage', function () {
360+
describe('async local storage', function () {
365361
before(function () {
366362
var app = express()
367363
var store = { foo: 'bar' }
368364

369365
app.use(function (req, res, next) {
370-
req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()
366+
req.asyncLocalStorage = new AsyncLocalStorage()
371367
req.asyncLocalStorage.run(store, next)
372368
})
373369

@@ -568,11 +564,3 @@ function createApp (options) {
568564

569565
return app
570566
}
571-
572-
function tryRequire (name) {
573-
try {
574-
return require(name)
575-
} catch (e) {
576-
return {}
577-
}
578-
}

test/express.urlencoded.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
'use strict'
22

33
var assert = require('assert')
4-
var asyncHooks = tryRequire('async_hooks')
4+
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
55
var Buffer = require('node:buffer').Buffer
66
var express = require('..')
77
var request = require('supertest')
88

9-
var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
10-
? describe
11-
: describe.skip
12-
139
describe('express.urlencoded()', function () {
1410
before(function () {
1511
this.app = createApp()
@@ -606,13 +602,13 @@ describe('express.urlencoded()', function () {
606602
})
607603
})
608604

609-
describeAsyncHooks('async local storage', function () {
605+
describe('async local storage', function () {
610606
before(function () {
611607
var app = express()
612608
var store = { foo: 'bar' }
613609

614610
app.use(function (req, res, next) {
615-
req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()
611+
req.asyncLocalStorage = new AsyncLocalStorage()
616612
req.asyncLocalStorage.run(store, next)
617613
})
618614

@@ -829,11 +825,3 @@ function expectKeyCount (count) {
829825
assert.strictEqual(Object.keys(JSON.parse(res.text)).length, count)
830826
}
831827
}
832-
833-
function tryRequire (name) {
834-
try {
835-
return require(name)
836-
} catch (e) {
837-
return {}
838-
}
839-
}

test/res.download.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var after = require('after');
44
var assert = require('assert')
5-
var asyncHooks = tryRequire('async_hooks')
5+
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
66
var Buffer = require('node:buffer').Buffer
77
var express = require('..');
88
var path = require('path')
@@ -11,10 +11,6 @@ var utils = require('./support/utils')
1111

1212
var FIXTURES_PATH = path.join(__dirname, 'fixtures')
1313

14-
var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
15-
? describe
16-
: describe.skip
17-
1814
describe('res', function(){
1915
describe('.download(path)', function(){
2016
it('should transfer as an attachment', function(done){
@@ -91,14 +87,14 @@ describe('res', function(){
9187
.expect(200, cb);
9288
})
9389

94-
describeAsyncHooks('async local storage', function () {
90+
describe('async local storage', function () {
9591
it('should presist store', function (done) {
9692
var app = express()
9793
var cb = after(2, done)
9894
var store = { foo: 'bar' }
9995

10096
app.use(function (req, res, next) {
101-
req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()
97+
req.asyncLocalStorage = new AsyncLocalStorage()
10298
req.asyncLocalStorage.run(store, next)
10399
})
104100

@@ -125,7 +121,7 @@ describe('res', function(){
125121
var store = { foo: 'bar' }
126122

127123
app.use(function (req, res, next) {
128-
req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()
124+
req.asyncLocalStorage = new AsyncLocalStorage()
129125
req.asyncLocalStorage.run(store, next)
130126
})
131127

@@ -488,11 +484,3 @@ describe('res', function(){
488484
})
489485
})
490486
})
491-
492-
function tryRequire (name) {
493-
try {
494-
return require(name)
495-
} catch (e) {
496-
return {}
497-
}
498-
}

test/res.sendFile.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var after = require('after');
44
var assert = require('assert')
5-
var asyncHooks = tryRequire('async_hooks')
5+
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
66
var Buffer = require('node:buffer').Buffer
77
var express = require('../')
88
, request = require('supertest')
@@ -11,10 +11,6 @@ var path = require('path');
1111
var fixtures = path.join(__dirname, 'fixtures');
1212
var utils = require('./support/utils');
1313

14-
var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
15-
? describe
16-
: describe.skip
17-
1814
describe('res', function(){
1915
describe('.sendFile(path)', function () {
2016
it('should error missing path', function (done) {
@@ -267,14 +263,14 @@ describe('res', function(){
267263
.expect(200, 'got 404 error', done)
268264
})
269265

270-
describeAsyncHooks('async local storage', function () {
266+
describe('async local storage', function () {
271267
it('should presist store', function (done) {
272268
var app = express()
273269
var cb = after(2, done)
274270
var store = { foo: 'bar' }
275271

276272
app.use(function (req, res, next) {
277-
req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()
273+
req.asyncLocalStorage = new AsyncLocalStorage()
278274
req.asyncLocalStorage.run(store, next)
279275
})
280276

@@ -300,7 +296,7 @@ describe('res', function(){
300296
var store = { foo: 'bar' }
301297

302298
app.use(function (req, res, next) {
303-
req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()
299+
req.asyncLocalStorage = new AsyncLocalStorage()
304300
req.asyncLocalStorage.run(store, next)
305301
})
306302

@@ -901,11 +897,3 @@ function createApp(path, options, fn) {
901897

902898
return app;
903899
}
904-
905-
function tryRequire (name) {
906-
try {
907-
return require(name)
908-
} catch (e) {
909-
return {}
910-
}
911-
}

0 commit comments

Comments
 (0)