Skip to content

Commit

Permalink
cleanup: remove AsyncLocalStorage check from tests (#6147)
Browse files Browse the repository at this point in the history
Co-authored-by: Wes Todd <wes@wesleytodd.com>
  • Loading branch information
Phillip9587 and wesleytodd authored Nov 15, 2024
1 parent 9f8589e commit 4e92ac9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 92 deletions.
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ unreleased
========================

* Remove `Object.setPrototypeOf` polyfill
* cleanup: remove AsyncLocalStorage check from tests
* cleanup: remove unnecessary require for global Buffer


5.0.1 / 2024-10-08
==========

Expand Down
19 changes: 4 additions & 15 deletions test/express.json.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage

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())
Expand Down Expand Up @@ -502,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)
})

Expand Down Expand Up @@ -755,11 +752,3 @@ function shouldContainInBody (str) {
'expected \'' + res.text + '\' to contain \'' + str + '\'')
}
}

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}
19 changes: 4 additions & 15 deletions test/express.raw.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage

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()
Expand Down Expand Up @@ -327,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)
})

Expand Down Expand Up @@ -513,11 +510,3 @@ function createApp (options) {

return app
}

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}
19 changes: 4 additions & 15 deletions test/express.text.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage

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()
Expand Down Expand Up @@ -360,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)
})

Expand Down Expand Up @@ -567,11 +564,3 @@ function createApp (options) {

return app
}

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}
19 changes: 4 additions & 15 deletions test/express.urlencoded.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage

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()
Expand Down Expand Up @@ -605,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)
})

Expand Down Expand Up @@ -828,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 {}
}
}
21 changes: 5 additions & 16 deletions test/res.download.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

var after = require('after');
var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage

var express = require('..');
var path = require('path')
var request = require('supertest');
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){
Expand Down Expand Up @@ -90,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)
})

Expand All @@ -124,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)
})

Expand Down Expand Up @@ -487,11 +484,3 @@ describe('res', function(){
})
})
})

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}
21 changes: 5 additions & 16 deletions test/res.sendFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

var after = require('after');
var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage

var express = require('../')
, request = require('supertest')
var onFinished = require('on-finished');
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) {
Expand Down Expand Up @@ -266,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)
})

Expand All @@ -299,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)
})

Expand Down Expand Up @@ -900,11 +897,3 @@ function createApp(path, options, fn) {

return app;
}

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}

0 comments on commit 4e92ac9

Please sign in to comment.