Skip to content

Commit

Permalink
cleanup: remove AsyncLocalStorage check from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip9587 committed Nov 15, 2024
1 parent cc751cf commit 92faae9
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 92 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ unreleased
========================

* Remove `Object.setPrototypeOf` polyfill
* cleanup: remove AsyncLocalStorage check from tests

5.0.1 / 2024-10-08
==========
Expand Down
18 changes: 3 additions & 15 deletions test/express.json.js
Original file line number Diff line number Diff line change
@@ -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())
Expand Down Expand Up @@ -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)
})

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

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}
18 changes: 3 additions & 15 deletions test/express.raw.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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)
})

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

return app
}

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}
18 changes: 3 additions & 15 deletions test/express.text.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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)
})

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

return app
}

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}
18 changes: 3 additions & 15 deletions test/express.urlencoded.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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 {}
}
}
20 changes: 4 additions & 16 deletions test/res.download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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){
Expand Down Expand Up @@ -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)
})

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

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

function tryRequire (name) {
try {
return require(name)
} catch (e) {
return {}
}
}
20 changes: 4 additions & 16 deletions test/res.sendFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
})

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

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

return app;
}

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

0 comments on commit 92faae9

Please sign in to comment.