Skip to content

Commit 1a0f085

Browse files
committed
Hack mocha.js to use latests instead of max
1 parent 7f0822d commit 1a0f085

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
@@ -12,6 +12,8 @@ const Nomenclature = require('../../src/service-naming')
1212
const { storage } = require('../../../datadog-core')
1313
const { schemaDefinitions } = require('../../src/service-naming/schemas')
1414

15+
const latestVersions = require('../../../datadog-instrumentations/src/helpers/latests.json').latests
16+
1517
global.withVersions = withVersions
1618
global.withExports = withExports
1719
global.withNamingSchema = withNamingSchema
@@ -173,6 +175,15 @@ function withPeerService (tracer, pluginName, spanGenerationFn, service, service
173175
})
174176
}
175177

178+
// function isVersionInRange(version, latestVersion) {
179+
// if (!latestVersion) return true
180+
// try {
181+
// return semver.lte(version, latestVersion)
182+
// } catch (e) {
183+
// return true // TODO this is a bit of a hack, but I'm not sure what else to do
184+
// }
185+
// }
186+
176187
function withVersions (plugin, modules, range, cb) {
177188
const instrumentations = typeof plugin === 'string' ? loadInst(plugin) : [].concat(plugin)
178189
const names = instrumentations.map(instrumentation => instrumentation.name)
@@ -199,6 +210,8 @@ function withVersions (plugin, modules, range, cb) {
199210
if (!packages.includes(moduleName)) return
200211
}
201212

213+
const latestVersion = latestVersions[moduleName] // TODO is moduleName correct?
214+
202215
const testVersions = new Map()
203216

204217
instrumentations
@@ -216,9 +229,13 @@ function withVersions (plugin, modules, range, cb) {
216229
testVersions.set(min, { range: version, test: min })
217230
}
218231

219-
const max = require(`../../../../versions/${moduleName}@${version}`).version()
220-
221-
testVersions.set(max, { range: version, test: version })
232+
// TODO may run into issues with the latest version being greater than supported Node
233+
if (latestVersion) {
234+
testVersions.set(latestVersion, { range: version, test: latestVersion })
235+
} else {
236+
const max = require(`../../../../versions/${moduleName}@${version}`).version()
237+
testVersions.set(max, { range: version, test: version })
238+
}
222239
})
223240
})
224241

0 commit comments

Comments
 (0)