Skip to content

Commit

Permalink
test: remove AsyncLocalStorage check (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip9587 authored Nov 7, 2024
1 parent 51e90e7 commit 80fbb76
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,16 +1,12 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
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 @@ -511,13 +507,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 @@ -761,11 +757,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,16 +1,12 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
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 @@ -329,13 +325,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 @@ -502,11 +498,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,16 +1,12 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
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 @@ -370,13 +366,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 @@ -565,11 +561,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,16 +1,12 @@
'use strict'

var assert = require('assert')
var asyncHooks = tryRequire('async_hooks')
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage
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 @@ -755,13 +751,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 @@ -968,11 +964,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 80fbb76

Please sign in to comment.