Skip to content

Commit

Permalink
test: remove AsyncLocalStorage check
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Phillip9587 committed Oct 22, 2024
1 parent a5055df commit 9eb4bfe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 60 deletions.
18 changes: 3 additions & 15 deletions test/json.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
var Buffer = require('safe-buffer').Buffer
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())
Expand Down Expand Up @@ -512,13 +508,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) {
Expand Down Expand Up @@ -762,11 +758,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/raw.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
var Buffer = require('safe-buffer').Buffer
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()
Expand Down Expand Up @@ -330,13 +326,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) {
Expand Down Expand Up @@ -503,11 +499,3 @@ function createServer (opts) {
})
})
}

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

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
var Buffer = require('safe-buffer').Buffer
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()
Expand Down Expand Up @@ -371,13 +367,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) {
Expand Down Expand Up @@ -566,11 +562,3 @@ function createServer (opts) {
})
})
}

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

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
var Buffer = require('safe-buffer').Buffer
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()
Expand Down Expand Up @@ -756,13 +752,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) {
Expand Down Expand Up @@ -969,11 +965,3 @@ function expectKeyCount (count) {
assert.strictEqual(Object.keys(JSON.parse(res.text)).length, count)
}
}

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

0 comments on commit 9eb4bfe

Please sign in to comment.