forked from DataDog/dd-trace-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for testing multiple versions of supported modules (DataD…
…og#243) * add support for testing multiple versions of supported modules * fix older express 4.x minor versions not instrumented properly
- Loading branch information
Showing
25 changed files
with
2,225 additions
and
2,073 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
coverage | ||
out | ||
test/plugins/versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,4 +103,5 @@ typings/ | |
package-lock.json | ||
yarn.lock | ||
out | ||
test/plugins/versions | ||
!test/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const requireDir = require('require-dir') | ||
const crypto = require('crypto') | ||
const semver = require('semver') | ||
const exec = require('./helpers/exec') | ||
const plugins = requireDir('../src/plugins') | ||
|
||
const workspaces = new Set() | ||
|
||
run() | ||
|
||
function run () { | ||
assertVersions() | ||
assertWorkspace() | ||
install() | ||
} | ||
|
||
function assertVersions () { | ||
Object.keys(plugins).filter(key => key !== 'index').forEach(key => { | ||
[].concat(plugins[key]).forEach(instrumentation => { | ||
[].concat(instrumentation.versions).forEach(version => { | ||
if (version) { | ||
assertModules(instrumentation.name, version) | ||
assertModules(instrumentation.name, semver.coerce(version).version) | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
function assertModules (name, version) { | ||
addFolder(name, version) | ||
assertFolder(name, version) | ||
assertPackage(name, version) | ||
assertIndex(name, version) | ||
} | ||
|
||
function assertFolder (name, version) { | ||
if (!fs.existsSync(folder())) { | ||
fs.mkdirSync(folder()) | ||
} | ||
|
||
if (!fs.existsSync(folder(name, version))) { | ||
fs.mkdirSync(folder(name, version)) | ||
} | ||
} | ||
|
||
function assertPackage (name, version) { | ||
fs.writeFileSync(filename(name, version, 'package.json'), JSON.stringify({ | ||
name: [name, sha1(version)].filter(val => val).join('-'), | ||
version: '1.0.0', | ||
license: 'BSD-3-Clause', | ||
private: true, | ||
dependencies: { | ||
[name]: version | ||
} | ||
}, null, 2) + '\n') | ||
} | ||
|
||
function assertIndex (name, version) { | ||
const index = `'use strict' | ||
module.exports = { | ||
get (id) { return require(id || '${name}') }, | ||
version () { return require('${name}/package.json').version } | ||
} | ||
` | ||
fs.writeFileSync(filename(name, version, 'index.js'), index) | ||
} | ||
|
||
function assertWorkspace () { | ||
fs.writeFileSync(filename(null, null, 'package.json'), JSON.stringify({ | ||
name: 'versions', | ||
version: '1.0.0', | ||
license: 'BSD-3-Clause', | ||
private: true, | ||
workspaces: Array.from(workspaces) | ||
}, null, 2) + '\n') | ||
} | ||
|
||
function install () { | ||
exec('yarn', { cwd: folder() }) | ||
} | ||
|
||
function addFolder (name, version) { | ||
const basename = [name, version].filter(val => val).join('@') | ||
workspaces.add(basename) | ||
} | ||
|
||
function folder (name, version) { | ||
const basename = [name, version].filter(val => val).join('@') | ||
return path.join(__dirname, '..', 'test', 'plugins', 'versions', basename) | ||
} | ||
|
||
function filename (name, version, file) { | ||
return path.join(folder(name, version), file) | ||
} | ||
|
||
function sha1 (str) { | ||
if (!str) return | ||
|
||
const shasum = crypto.createHash('sha1') | ||
shasum.update(str) | ||
return shasum.digest('hex') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const exec = require('./helpers/exec') | ||
const title = require('./helpers/title') | ||
|
||
|
@@ -12,15 +11,10 @@ if (!msg) { | |
throw new Error('Please provide a reason for the change. Example: node scripts/publish_docs.js "fix typo"') | ||
} | ||
|
||
if (fs.existsSync('yarn.lock')) { | ||
exec('yarn') | ||
} else { | ||
exec('npm install') | ||
} | ||
|
||
exec('yarn install') | ||
exec('rm -rf ./out') | ||
exec('git clone -b gh-pages --single-branch [email protected]:DataDog/dd-trace-js.git out') | ||
exec('npm run jsdoc') | ||
exec('yarn jsdoc') | ||
exec('git add -A', { cwd: './out' }) | ||
exec(`git commit -m "${msg}"`, { cwd: './out' }) | ||
exec('git push', { cwd: './out' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.