Skip to content

Commit fd5e1be

Browse files
committed
Hack mocha.js to use latests instead of max
1 parent 193d84d commit fd5e1be

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/dd-trace/test/setup/mocha.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const { storage } = require('../../../datadog-core')
1313
const { schemaDefinitions } = require('../../src/service-naming/schemas')
1414
const { getInstrumentation } = require('./helpers/load-inst')
1515

16+
const latestVersions = require('../../../datadog-instrumentations/src/helpers/latests.json').latests
17+
1618
global.withVersions = withVersions
1719
global.withExports = withExports
1820
global.withNamingSchema = withNamingSchema
@@ -142,6 +144,15 @@ function withPeerService (tracer, pluginName, spanGenerationFn, service, service
142144
})
143145
}
144146

147+
// function isVersionInRange(version, latestVersion) {
148+
// if (!latestVersion) return true
149+
// try {
150+
// return semver.lte(version, latestVersion)
151+
// } catch (e) {
152+
// return true // TODO this is a bit of a hack, but I'm not sure what else to do
153+
// }
154+
// }
155+
145156
function withVersions (plugin, modules, range, cb) {
146157
const instrumentations = typeof plugin === 'string' ? getInstrumentation(plugin) : [].concat(plugin)
147158
const names = instrumentations.map(instrumentation => instrumentation.name)
@@ -168,6 +179,8 @@ function withVersions (plugin, modules, range, cb) {
168179
if (!packages.includes(moduleName)) return
169180
}
170181

182+
const latestVersion = latestVersions[moduleName] // TODO is moduleName correct?
183+
171184
const testVersions = new Map()
172185

173186
instrumentations
@@ -185,9 +198,13 @@ function withVersions (plugin, modules, range, cb) {
185198
testVersions.set(min, { range: version, test: min })
186199
}
187200

188-
const max = require(`../../../../versions/${moduleName}@${version}`).version()
189-
190-
testVersions.set(max, { range: version, test: version })
201+
// TODO may run into issues with the latest version being greater than supported Node
202+
if (latestVersion) {
203+
testVersions.set(latestVersion, { range: version, test: latestVersion })
204+
} else {
205+
const max = require(`../../../../versions/${moduleName}@${version}`).version()
206+
testVersions.set(max, { range: version, test: version })
207+
}
191208
})
192209
})
193210

0 commit comments

Comments
 (0)