Skip to content

Commit 83b4830

Browse files
committed
tests: use feature detetion for named capture groups
1 parent 537e97f commit 83b4830

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

test/route.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ var shouldHitHandle = utils.shouldHitHandle
1414
var shouldNotHaveBody = utils.shouldNotHaveBody
1515
var shouldNotHitHandle = utils.shouldNotHitHandle
1616

17-
// Named capturing groups are available from Node `10.0.0` and up
18-
var describeCaptureGroups = runningOnNodeMajorVersionGreaterOrEqualThan(10) ? describe : describe.skip
17+
var describeNamedCaptureGroups = supportsRegExp('(?<foo>.)') ? describe : describe.skip
1918
var describePromises = global.Promise ? describe : describe.skip
2019

2120
describe('Router', function () {
@@ -1021,7 +1020,7 @@ describe('Router', function () {
10211020
})
10221021
})
10231022

1024-
describeCaptureGroups('using "(?<name>)"', function () {
1023+
describeNamedCaptureGroups('using "(?<name>)"', function () {
10251024
it('should allow defining capturing groups using regexps', function (done) {
10261025
var cb = after(3, done)
10271026
var router = new Router()
@@ -1095,6 +1094,10 @@ function sendParams (req, res) {
10951094
res.end(JSON.stringify(req.params))
10961095
}
10971096

1098-
function runningOnNodeMajorVersionGreaterOrEqualThan (version) {
1099-
return Number(process.versions.node.split('.')[0]) >= Number(version)
1097+
function supportsRegExp (source) {
1098+
try {
1099+
return RegExp(source).source !== ''
1100+
} catch (e) {
1101+
return false
1102+
}
11001103
}

0 commit comments

Comments
 (0)