diff --git a/.autod.conf.js b/.autod.conf.js new file mode 100644 index 0000000..ed8e6e8 --- /dev/null +++ b/.autod.conf.js @@ -0,0 +1,30 @@ +'use strict'; + +module.exports = { + write: true, + prefix: '^', + test: [ + 'test', + ], + dep: [ + 'nan', + '@xprofiler/node-pre-gyp', + ], + devdep: [ + 'autod', + 'chai', + 'clang-format', + 'eslint', + 'mocha', + ], + exclude: [ + './build', + './scripts', + './test/fixtures', + './demo.js', + './lib/worker_threads.js' + ], + semver: [ + 'mocha@5' + ] +}; diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..a146beb --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +*.debug.js +*.min.js +node_modules/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..fb565b3 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,91 @@ +{ + "rules": { + "indent": [ + 2, + 2 + ], + "quotes": [ + 2, + "single", + { + "avoidEscape": true, + "allowTemplateLiterals": true + } + ], + "linebreak-style": [ + 2, + "unix" + ], + "semi": [ + 2, + "always" + ], + "strict": [ + 2, + "global" + ], + "curly": 2, + "eqeqeq": 2, + "no-eval": 2, + "guard-for-in": 2, + "no-caller": 2, + "no-else-return": 2, + "no-eq-null": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-floating-decimal": 2, + "no-implied-eval": 2, + "no-labels": 2, + "no-with": 2, + "no-loop-func": 1, + "no-native-reassign": 2, + "no-redeclare": [ + 2, + { + "builtinGlobals": true + } + ], + "no-delete-var": 2, + "no-shadow-restricted-names": 2, + "no-undef-init": 2, + "no-use-before-define": 2, + "no-unused-vars": [ + 2, + { + "args": "none" + } + ], + "no-undef": 2, + "callback-return": [ + 2, + [ + "callback", + "cb", + "next" + ] + ], + "global-require": 0, + "no-console": 0, + "require-yield": 0, + "no-constant-condition": 1, + "max-len": [ + "error", + { + "code": 120 + } + ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true + }, + "parserOptions": { + "ecmaVersion": 2018, + "sourceType": "script", + "ecmaFeatures": { + "jsx": true + } + }, + "extends": "eslint:recommended" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 564426c..1de8012 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ tmp *.heapprofile demo.js *.log +config.gypi +release \ No newline at end of file diff --git a/binding.gyp b/binding.gyp index 1bd21b4..7766b95 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,4 +1,12 @@ { + 'includes': [ + 'config.gypi' + ], + + 'variables': { + 'action_after_build': 'false' + }, + 'targets': [ { 'target_name': 'profiler', @@ -17,8 +25,8 @@ 'src/environment_data.cc' ], 'include_dirs' : [ - "src", - " 0) { + binding.cpu.setGenerateType(type); + } else { + console.error(`type should in [${types.join(', ')}], got ${type}.`); } + }, - process.nextTick(function () { - if (toStream) { - if (error) { - dataReceiver.emit('error', error); - } + startProfiling: function (name, recsamples) { + if (activeProfiles.length === 0 && typeof process._startProfilerIdleNotifier === 'function') { + process._startProfilerIdleNotifier(); + } - dataReceiver.end(result); - } else { - dataReceiver(error, result); - } - }); + if (typeof name === 'boolean') { + recsamples = name; + name = ''; + } - return toStream ? dataReceiver : undefined; -}; + recsamples = recsamples === undefined ? true : Boolean(recsamples); + name = name && '' + name || ''; -let startTime, endTime; -let activeProfiles = []; + if (activeProfiles.indexOf(name) < 0) { activeProfiles.push(name); } -let profiler = { - /*HEAP PROFILER API*/ + startTime = Date.now(); + binding.cpu.startProfiling(name, recsamples); + }, + + stopProfiling: function (name) { + let index = activeProfiles.indexOf(name); + if (name && index < 0) { return; } - get snapshots() { return binding.heap.snapshots; }, - - takeSnapshot: function (name, control) { - if (typeof name == 'function') { - control = name; - name = ''; - } + let profile = binding.cpu.stopProfiling(name); + endTime = Date.now(); + profile.__proto__ = CpuProfile.prototype; + if (!profile.startTime) { profile.startTime = startTime; } + if (!profile.endTime) { profile.endTime = endTime; } - if (typeof control !== 'function') { - control = function noop() { }; - } + if (name) { activeProfiles.splice(index, 1); } + else { activeProfiles.length = activeProfiles.length - 1; } + + if (activeProfiles.length === 0 && typeof process._stopProfilerIdleNotifier === 'function') { + process._stopProfilerIdleNotifier(); + } - name = '' + name; - - let snapshot = binding.heap.takeSnapshot(name, control); - snapshot.__proto__ = Snapshot.prototype; - snapshot.title = name; - return snapshot; - }, + return profile; + }, - deleteAllSnapshots: function () { - Object.keys(binding.heap.snapshots).forEach(function (key) { - binding.heap.snapshots[key].delete(); - }); - }, - - startTrackingHeapObjects: function () { - binding.heap.startTrackingHeapObjects(); - }, - - stopTrackingHeapObjects: function () { - binding.heap.stopTrackingHeapObjects(); - }, - - getHeapStats: function (iterator, callback) { - if (typeof iterator !== 'function') - iterator = function noop() { }; - - if (typeof callback !== 'function') - callback = function noop() { }; - - return binding.heap.getHeapStats(iterator, callback) - }, - - getObjectByHeapObjectId: function (id) { - id = parseInt(id, 10); - if (isNaN(id)) return; - - return binding.heap.getObjectByHeapObjectId(id); - }, - - getHeapObjectId: function (value) { - if (!arguments.length) return; - return binding.heap.getHeapObjectId(value); - }, - - /*CPU PROFILER API*/ - - get profiles() { return binding.cpu.profiles; }, - - setGenerateType: function (type) { - const types = [0, 1]; - if (types.indexOf(type) > 0) { - binding.cpu.setGenerateType(type); - } else { - console.error(`type should in [${types.join(', ')}], got ${type}.`); - } - }, - - startProfiling: function (name, recsamples) { - if (activeProfiles.length == 0 && typeof process._startProfilerIdleNotifier == "function") - process._startProfilerIdleNotifier(); - - if (typeof name == 'boolean') { - recsamples = name; - name = ''; - } - - recsamples = recsamples === undefined ? true : Boolean(recsamples); - name = name && '' + name || ''; - - if (activeProfiles.indexOf(name) < 0) - activeProfiles.push(name) - - startTime = Date.now(); - binding.cpu.startProfiling(name, recsamples); - }, - - stopProfiling: function (name) { - let index = activeProfiles.indexOf(name); - if (name && index < 0) - return; - - let profile = binding.cpu.stopProfiling(name); - endTime = Date.now(); - profile.__proto__ = CpuProfile.prototype; - if (!profile.startTime) profile.startTime = startTime; - if (!profile.endTime) profile.endTime = endTime; - - if (name) - activeProfiles.splice(index, 1); - else - activeProfiles.length = activeProfiles.length - 1; - - if (activeProfiles.length == 0 && typeof process._stopProfilerIdleNotifier == "function") - process._stopProfilerIdleNotifier(); - - return profile; - }, - - setSamplingInterval: function (num) { - if (activeProfiles.length) { - throw new Error('setSamplingInterval must be called when there are no profiles being recorded.'); - } - - num = parseInt(num, 10) || 1000; - binding.cpu.setSamplingInterval(num); - }, - - deleteAllProfiles: function () { - Object.keys(binding.cpu.profiles).forEach(function (key) { - binding.cpu.profiles[key].delete(); - }); - }, - - /*SAMPLING HEAP PROFILER API*/ - - startSamplingHeapProfiling: function (interval, depth) { - if (process.versions.modules < 48) - throw new Error('Sampling heap profiler needs node version >= node-v6.0.0!'); - if (arguments.length === 2) - binding.samplingHeap.startSamplingHeapProfiling(interval, depth); - else - binding.samplingHeap.startSamplingHeapProfiling(); - }, - - stopSamplingHeapProfiling: function () { - if (process.versions.modules < 48) - throw new Error('Sampling heap profiler needs node version >= node-v6.0.0!'); - let profile = binding.samplingHeap.stopSamplingHeapProfiling(); - profile.__proto__ = SamplingHeapProfile.prototype; - return profile; + setSamplingInterval: function (num) { + if (activeProfiles.length) { + throw new Error('setSamplingInterval must be called when there are no profiles being recorded.'); } + + num = parseInt(num, 10) || 1000; + binding.cpu.setSamplingInterval(num); + }, + + deleteAllProfiles: function () { + Object.keys(binding.cpu.profiles).forEach(function (key) { + binding.cpu.profiles[key].delete(); + }); + }, + + /*SAMPLING HEAP PROFILER API*/ + + startSamplingHeapProfiling: function (interval, depth) { + if (process.versions.modules < 48) { throw new Error('Sampling heap profiler needs node version >= node-v6.0.0!'); } + if (arguments.length === 2) { binding.samplingHeap.startSamplingHeapProfiling(interval, depth); } + else { binding.samplingHeap.startSamplingHeapProfiling(); } + }, + + stopSamplingHeapProfiling: function () { + if (process.versions.modules < 48) { throw new Error('Sampling heap profiler needs node version >= node-v6.0.0!'); } + let profile = binding.samplingHeap.stopSamplingHeapProfiling(); + profile.__proto__ = SamplingHeapProfile.prototype; + return profile; + } }; module.exports = profiler; diff --git a/lib/binding.js b/lib/binding.js new file mode 100644 index 0000000..6683373 --- /dev/null +++ b/lib/binding.js @@ -0,0 +1,17 @@ +'use strict'; + +const nodeVersion = process.versions.node; +const tags = nodeVersion.split('.'); + +let binding; + +if (tags[0] < 12) { + binding = require('../build/Release/profiler.node'); +} else { + const path = require('path'); + const binary = require('@xprofiler/node-pre-gyp'); + const bindingPath = binary.find(path.resolve(path.join(__dirname, '../package.json'))); + binding = require(bindingPath); +} + +module.exports = binding; \ No newline at end of file diff --git a/package.json b/package.json index e009f35..f2026e0 100644 --- a/package.json +++ b/package.json @@ -3,14 +3,30 @@ "version": "1.6.1", "description": "node bindings for the v8 profiler", "main": "dispatch.js", + "binary": { + "module_name": "profiler", + "module_path": "./build/binding/{configuration}/{node_abi}-{platform}-{arch}/", + "remote_path": "./v{version}/", + "package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz", + "host": "https://github.com/hyj1991/v8-profiler-next/releases/download" + }, "scripts": { + "install": "node scripts/install.js", + "build": "node scripts/rebuild.js", + "dep": "npm run build && npm run test", + "pack-common": "node scripts/common.js", + "pack-7u": "node scripts/7u.js", + "pack-8u": "node scripts/8u.js", + "copy": "node scripts/copy.js", + "pack": "node scripts/clean.js && node-pre-gyp package && node-pre-gyp testpackage && npm run copy", "test-old": "mocha test/*.test.js --exclude test/worker.test.js --timeout 10000", "test-new": "mocha test/*.test.js --timeout 10000", "test": "node scripts/test.js", "test-single": "mocha --timeout 10000", - "build": "node-gyp rebuild", "format": "clang-format -i --glob=\"src/**/*[.h|.cc]\"", - "stability": "node scripts/stability.js" + "lint": "npm run format && eslint . --fix", + "stability": "node scripts/stability.js", + "autod": "autod" }, "repository": { "type": "git", @@ -36,11 +52,13 @@ "README.md" ], "dependencies": { + "@xprofiler/node-pre-gyp": "^1.0.9", "nan": "^2.15.0" }, "devDependencies": { - "chai": "^4.2.0", + "chai": "^4.3.6", "clang-format": "^1.8.0", + "eslint": "^8.16.0", "mocha": "^5.2.0" } -} \ No newline at end of file +} diff --git a/scripts/7u.js b/scripts/7u.js new file mode 100644 index 0000000..267a77a --- /dev/null +++ b/scripts/7u.js @@ -0,0 +1,16 @@ +'use strict'; + +const build = require('./build'); + +const nodeVersions = [ + 'node-v12.22.12', + 'node-v13.14.0', + 'node-v14.19.2', + 'node-v15.14.0', + 'node-v16.15.0', + 'node-v17.9.0', +]; + +build(nodeVersions); + +module.exports = nodeVersions; \ No newline at end of file diff --git a/scripts/8u.js b/scripts/8u.js new file mode 100644 index 0000000..327a4bb --- /dev/null +++ b/scripts/8u.js @@ -0,0 +1,11 @@ +'use strict'; + +const build = require('./build'); + +const nodeVersions = [ + 'node-v18.1.0', +]; + +build(nodeVersions); + +module.exports = nodeVersions; \ No newline at end of file diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 0000000..f43b135 --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,68 @@ +'use strict'; + +const os = require('os'); +const fs = require('fs'); +const cp = require('child_process'); +const path = require('path'); + +const isWindows = os.platform() === 'win32'; + +function debug(message) { + console.log(`\n\x1b[32;1m${message}\x1b[0m\n`); +} + +// function error(message) { +// console.log(`\n\x1b[31m${message}\x1b[0m\n`); +// } + +function execCmd(cmd) { + debug(cmd); + cp.execSync(cmd, { + env: process.env, + cwd: path.join(__dirname, '../'), + stdio: 'inherit', + shell: isWindows ? undefined : '/bin/bash', + }); +} + +function cleanReleaseDir() { + const release = path.join(__dirname, '../release'); + if (!fs.existsSync(release)) { + fs.mkdirSync(release); + } + const files = fs.readdirSync(release); + for (const file of files) { + const filePath = path.join(release, file); + if (!fs.existsSync(filePath)) { + continue; + } + fs.unlinkSync(filePath); + } +} + +exports = module.exports = versions => { + cleanReleaseDir(); + + for (const version of versions) { + debug(`>>>>>>>> start build with ${version}`); + const tnvmPath = path.join(os.homedir(), '.tnvm/tnvm.sh'); + let npmBin = 'npm'; + let change = `source ${tnvmPath} && tnvm use ${version}`; + const nvmNodeVersion = /^node-v(.*)$/.exec(version)[1]; + if (isWindows) { + npmBin = path.join(os.tmpdir(), '../../', `Roaming\\nvm\\v${nvmNodeVersion}\\npm.cmd`); + change = `nvm use ${nvmNodeVersion}`; + } + + const install = 'npm install'; + const build = `${npmBin} run dep`; + const pack = 'npx node-pre-gyp package && npx node-pre-gyp testpackage'; + const copy = `${npmBin} run copy`; + execCmd(`${change} && ${build} && ${install} && ${pack} && ${copy}`); + debug(`<<<<<<<< build with ${version} done.`); + } + + debug('all build tasks done.'); +}; + +exports.execCmd = execCmd; \ No newline at end of file diff --git a/scripts/clean.js b/scripts/clean.js new file mode 100644 index 0000000..2e45828 --- /dev/null +++ b/scripts/clean.js @@ -0,0 +1,17 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); + +const release = path.join(__dirname, '../release'); +if (!fs.existsSync(release)) { + fs.mkdirSync(release); +} +const files = fs.readdirSync(release); +for (const file of files) { + const filePath = path.join(release, file); + if (!fs.existsSync(filePath)) { + continue; + } + fs.unlinkSync(filePath); +} diff --git a/scripts/common.js b/scripts/common.js new file mode 100644 index 0000000..0e5429f --- /dev/null +++ b/scripts/common.js @@ -0,0 +1,15 @@ +'use strict'; + +const build = require('./build'); + +const nodeVersions = [ + 'node-v12.22.12', + 'node-v13.14.0', + 'node-v14.19.2', + 'node-v15.14.0', + 'node-v16.15.0', + 'node-v17.9.0', + 'node-v18.1.0', +]; + +build(nodeVersions); \ No newline at end of file diff --git a/scripts/copy.js b/scripts/copy.js new file mode 100644 index 0000000..7a4919f --- /dev/null +++ b/scripts/copy.js @@ -0,0 +1,23 @@ +'use strict'; + +const path = require('path'); +const fs = require('fs'); +const versioning = require('@xprofiler/node-pre-gyp/lib/util/versioning.js'); +const packagePath = versioning.evaluate(require('../package.json')).staged_tarball; + +function copy() { + const release = path.join(__dirname, '../release'); + if (!fs.existsSync(release)) { + fs.mkdirSync(release); + } + + if (!fs.existsSync(packagePath)) { + return; + } + + const filename = path.basename(packagePath); + const target = path.join(release, filename); + fs.copyFileSync(packagePath, target); +} + +copy(); diff --git a/scripts/gyp.js b/scripts/gyp.js new file mode 100644 index 0000000..48ab695 --- /dev/null +++ b/scripts/gyp.js @@ -0,0 +1,31 @@ +'use strict'; + +const path = require('path'); +const fs = require('fs'); +const execCmd = require('./build').execCmd; +const nodeVersion = process.versions.node; + +function writeConfig(config) { + const options = JSON.stringify(config, null, 2); + fs.writeFileSync(path.join(__dirname, '../config.gypi'), options, 'utf-8'); + console.log('Writing config.gypi:'); + console.log(options); +} + +module.exports = function (oldCmd, newCmd) { + const tags = nodeVersion.split('.'); + const options = { + variables: { + action_after_build: 'false' + } + }; + + if (tags[0] < 12) { + writeConfig(options); + execCmd(oldCmd); + } else { + options.variables.action_after_build = 'true'; + writeConfig(options); + execCmd(newCmd); + } +}; diff --git a/scripts/install.js b/scripts/install.js new file mode 100644 index 0000000..9520a31 --- /dev/null +++ b/scripts/install.js @@ -0,0 +1,5 @@ +'use strict'; + +const execCmd = require('./gyp'); + +execCmd('node-gyp rebuild', 'node-pre-gyp install --fallback-to-build'); diff --git a/scripts/rebuild.js b/scripts/rebuild.js new file mode 100644 index 0000000..885842e --- /dev/null +++ b/scripts/rebuild.js @@ -0,0 +1,5 @@ +'use strict'; + +const execCmd = require('./gyp'); + +execCmd('node-gyp rebuild', 'node-pre-gyp rebuild'); diff --git a/scripts/stability.js b/scripts/stability.js index 8d1c01d..f0db913 100644 --- a/scripts/stability.js +++ b/scripts/stability.js @@ -1,18 +1,10 @@ 'use strict'; -const cp = require('child_process'); -const path = require('path'); - -function exec(cmd) { - cp.execSync(cmd, { - cwd: path.join(__dirname, '../'), - stdio: 'inherit', env: process.env, - shell: '/bin/bash' - }); -} +const execCmd = require('./build').execCmd; +const versions = require('./7u'); function runOneVersion(version) { - exec(`source ~/.tnvm/tnvm.sh && tnvm use ${version} && npm run build && npm run test`); + execCmd(`source ~/.tnvm/tnvm.sh && tnvm use ${version} && npm run build && npm run test`); } function main(versions, infinity = false) { @@ -23,14 +15,4 @@ function main(versions, infinity = false) { } while (infinity); } -// test for 7u -const nodeVersions = [ - 'node-v12.22.12', - 'node-v13.14.0', - 'node-v14.19.2', - 'node-v15.14.0', - 'node-v16.15.0', - 'node-v17.9.0', -]; - -main(nodeVersions, true); +main(versions, true); diff --git a/test/binding.test.js b/test/binding.test.js index 4c0412d..7662160 100644 --- a/test/binding.test.js +++ b/test/binding.test.js @@ -1,11 +1,9 @@ 'use strict'; +const binding = require('../lib/binding'); const expect = require('chai').expect; -const path = require('path'); -const binding = require(path.join(__dirname, '../build/Release/profiler.node')); const NODE_V_010 = /^v0\.10\.\d+$/.test(process.version); -const NODE_V_3 = /^v3\./.test(process.version); describe('binding', function () { describe('Profiler container', function () { @@ -19,10 +17,16 @@ describe('binding', function () { }); describe('CPU', function () { - after(deleteAllProfiles); - const cpu = binding.cpu; + function deleteAllProfiles() { + cpu.profiles.slice().forEach(function (profile) { + profile.delete(); + }); + } + + after(deleteAllProfiles); + describe('Profiler', function () { it('has expected structure', function () { @@ -108,19 +112,19 @@ describe('binding', function () { }); }); }); + }); - function deleteAllProfiles() { - cpu.profiles.slice().forEach(function (profile) { - profile.delete(); + describe('HEAP', function () { + const heap = binding.heap; + + function deleteAllSnapshots() { + Object.keys(binding.heap.snapshots).forEach(function (key) { + binding.heap.snapshots[key].delete(); }); } - }); - describe('HEAP', function () { after(deleteAllSnapshots); - const heap = binding.heap; - describe('Profiler', function () { it('has expected structure', function () { const properties = [ @@ -150,11 +154,5 @@ describe('binding', function () { }); }); }); - - function deleteAllSnapshots() { - Object.keys(binding.heap.snapshots).forEach(function (key) { - binding.heap.snapshots[key].delete(); - }); - } }); }); diff --git a/test/fixtures/worker.js b/test/fixtures/worker.js index 592f472..8bc65bd 100644 --- a/test/fixtures/worker.js +++ b/test/fixtures/worker.js @@ -28,6 +28,8 @@ async function main() { return; } + const globalThis = global; + const workerThreads = require('worker_threads'); if (workerThreads.isMainThread) { const w = new workerThreads.Worker(__filename, { diff --git a/test/v8-profiler.test.js b/test/v8-profiler.test.js index 72cd3d3..2a1f41d 100644 --- a/test/v8-profiler.test.js +++ b/test/v8-profiler.test.js @@ -9,6 +9,12 @@ const NODE_V_5 = /^v5\./.test(process.version); describe('v8-profiler', function () { describe('CPU', function () { + function deleteAllProfiles() { + Object.keys(profiler.profiles).forEach(function (key) { + profiler.profiles[key].delete(); + }); + } + after(deleteAllProfiles); describe('Profiler', function () { @@ -37,7 +43,7 @@ describe('v8-profiler', function () { }); it('should record samples, if started with recsamples argument', function () { - if (NODE_V_010) return; + if (NODE_V_010) { return; } profiler.startProfiling(true); const profile = profiler.stopProfiling(); @@ -67,7 +73,7 @@ describe('v8-profiler', function () { expect(profile.timeDeltas.length > 0).to.equal(true); expect(!profile.timestamps).to.equal(true); }); - }) + }); describe('Profile', function () { it('should export itself with callback', function () { @@ -93,15 +99,15 @@ describe('v8-profiler', function () { }); }); }); + }); - function deleteAllProfiles() { - Object.keys(profiler.profiles).forEach(function (key) { - profiler.profiles[key].delete(); + describe('HEAP', function () { + function deleteAllSnapshots() { + Object.keys(profiler.snapshots).forEach(function (key) { + profiler.snapshots[key].delete(); }); } - }); - describe('HEAP', function () { after(deleteAllSnapshots); describe('Profiler', function () { @@ -139,17 +145,17 @@ describe('v8-profiler', function () { it('should return id for object in getHeapObjectId', function () { const obj = {}; - const snapshot = profiler.takeSnapshot(); + profiler.takeSnapshot(); expect(profiler.getHeapObjectId(obj)).to.be.gt(0); }); it('should return id for undefined param in getHeapObjectId', function () { - const snapshot = profiler.takeSnapshot(); + profiler.takeSnapshot(); expect(profiler.getHeapObjectId(undefined)).to.be.gt(0); }); it('should return undefined for wrong params in getHeapObjectId', function () { - const snapshot = profiler.takeSnapshot(); + profiler.takeSnapshot(); expect(profiler.getHeapObjectId()).to.be.equal(undefined); }); }); @@ -163,7 +169,7 @@ describe('v8-profiler', function () { const oldSnapshotsLength = Object.keys(profiler.snapshots).length; snapshot.delete(); - expect(Object.keys(profiler.snapshots).length == oldSnapshotsLength - 1).to.equal(true); + expect(Object.keys(profiler.snapshots).length === oldSnapshotsLength - 1).to.equal(true); expect(profiler.snapshots[uid]).to.be.equal(undefined); }); @@ -197,7 +203,7 @@ describe('v8-profiler', function () { snapshot.export(function (err, result) { expect(!err); - expect(typeof result == 'string'); + expect(typeof result === 'string'); done(); }); }); @@ -232,12 +238,6 @@ describe('v8-profiler', function () { }); }); }); - - function deleteAllSnapshots() { - Object.keys(profiler.snapshots).forEach(function (key) { - profiler.snapshots[key].delete(); - }); - } }); describe('SAMPLING HEAP', function () { @@ -262,7 +262,7 @@ describe('v8-profiler', function () { }); it('has expected structure', function () { - if (NODE_V_4 || NODE_V_5) return; + if (NODE_V_4 || NODE_V_5) { return; } profiler.startSamplingHeapProfiling(); const profile = profiler.stopSamplingHeapProfiling(); const samplingHeapProperties = ['head'];