diff --git a/.gitignore b/.gitignore index c925c21..22e348d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /dist /node_modules +/tests/multidep diff --git a/package.json b/package.json index 89682c3..4b00fc9 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "jsnext:main": "dist/es6/index.js", "scripts": { "build": "node ./scripts/build.js", - "pretest": "npm run build", + "pretest": "npm run build && multidep tests/multidep.json", "test": "mocha dist/cjs/tests/index.js", "test:debug": "npm run build && mocha --no-timeouts debug dist/cjs/tests/index.js", "prepublish": "npm run build" @@ -24,6 +24,7 @@ "chai": "^3.5.0", "heimdalljs": "^0.2.3", "mocha": "^3.2.0", + "multidep": "^2.0.1", "rollup": "^0.37.0", "rollup-plugin-babel": "^2.7.0", "rollup-plugin-commonjs": "^5.0.5", diff --git a/scripts/build.js b/scripts/build.js index d74aabe..6bffd4d 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -12,7 +12,7 @@ function build(entry, dest, format) { entry: entry, external: [ - 'fs', 'heimdalljs', 'chai' + 'fs', 'heimdalljs', 'chai', 'multidep' ], plugins: [ babel({ exclude: 'node_modules/**' }), diff --git a/tests/multidep.json b/tests/multidep.json new file mode 100644 index 0000000..661887a --- /dev/null +++ b/tests/multidep.json @@ -0,0 +1,6 @@ +{ + "path": "tests/multidep", + "versions": { + "heimdalljs": ["0.2.3"] + } +} diff --git a/tests/runtimes/node.js b/tests/runtimes/node.js index 9adf807..10deaa8 100644 --- a/tests/runtimes/node.js +++ b/tests/runtimes/node.js @@ -1,7 +1,18 @@ -// import tests from shared to kick them off -import '../shared'; +import multidep from 'multidep'; +const multidepRequire = multidep('tests/multidep.json'); + +import testGenerator from '../shared'; describe('heimdalljs-graph', function() { + multidepRequire.forEachVersion('heimdalljs', function(version, _heimdall) { + describe(`heimdalljs@${version}`, function() { + // the entry point script _really_ should include a way to + // access Heimdall itself (and not just the default session) + let Heimdall = Object.getPrototypeOf(_heimdall).constructor; + testGenerator(Heimdall, version); + }); + }); + describe('loadFromFile', function() { it('works'); }); diff --git a/tests/shared.js b/tests/shared.js index 1253d08..dfb84dd 100644 --- a/tests/shared.js +++ b/tests/shared.js @@ -1,12 +1,10 @@ import chai from 'chai'; -import Heimdall from 'heimdalljs/heimdall'; -import { loadFromNode } from '../src'; +import { loadFromNode, loadFromJSON } from '../src'; const { expect } = chai; -describe('heimdalljs-graph-shared', function() { +export default function testGenerator(Heimdall, version) { let node; - class StatsSchema { constructor() { this.x = 0; @@ -29,22 +27,42 @@ describe('heimdalljs-graph-shared', function() { \ d */ - - let j = heimdall.start('j'); - let f = heimdall.start('f'); - let a = heimdall.start('a'); - let d = heimdall.start('d'); - d.stop(); - a.stop(); - let h = heimdall.start('h'); - h.stop(); - f.stop(); - let k = heimdall.start('k'); - let z = heimdall.start('z'); - z.stop(); - k.stop(); - - node = heimdall.root._children[0]; + if (version === '0.2.3') { + let j = heimdall.start('j'); + let f = heimdall.start('f'); + let a = heimdall.start('a'); + let d = heimdall.start('d'); + d.stop(); + a.stop(); + let h = heimdall.start('h'); + h.stop(); + f.stop(); + let k = heimdall.start('k'); + let z = heimdall.start('z'); + z.stop(); + k.stop(); + + node = heimdall.root._children[0]; + } else { + let j = heimdall.start('j'); + let f = heimdall.start('f'); + let a = heimdall.start('a'); + let d = heimdall.start('d'); + heimdall.stop(d); + heimdall.stop(a); + let h = heimdall.start('h'); + heimdall.stop(h); + heimdall.stop(f); + let k = heimdall.start('k'); + let z = heimdall.start('z'); + heimdall.stop(z); + heimdall.stop(k); + + // this should not be needed + // we should be able to pass the current + // `heimdall` node directly + node = new Heimdall.Tree(heimdall); + } }); describe('.loadFromNode', function() { @@ -146,4 +164,58 @@ describe('heimdalljs-graph-shared', function() { ]); }); }); -}); + + describe('.loadFromJSON', function() { + it('works with broccoli-viz output from heimdall@0.2', function() { + let data = { + nodes: [ + { + _id: 1, + id: { name: 'j' }, + stats: { own: {}, time: { self: 2734} }, + children: [ 2, 6 ] + }, { + _id: 2, + id: { name: 'f' }, + stats: { own: {}, time: { self: 2257} }, + children: [ 3, 5 ] + }, { + _id: 3, + id: { name: 'a' }, + stats: { own: {}, time: { self: 1842} }, + children: [ 4 ] + }, { + _id: 4, + id: { name: 'd' }, + stats: { own: {}, time: { self: 1738} }, + children: [] + }, { + _id: 5, + id: { name: 'h' }, + stats: { own: {}, time: { self: 1245 } }, + children: [] + }, { + _id: 6, + id: { name: 'k' }, + stats: { own: {}, time: { self: 1596 } }, + children: [ 7 ] + }, { + _id: 7, + id: { name: 'z' }, + stats: { own: {}, time: { self: 1229 } }, + children: [] + } + ] + }; + + let tree = loadFromJSON(data); + let names = []; + for (let node of tree.dfsIterator()) { + names.push(node.label.name); + } + expect(names, 'depth first, pre order').to.eql([ + 'j','f','a','d','h','k','z' + ]); + }); + }); +} diff --git a/yarn.lock b/yarn.lock index fdcf3cd..0ec014d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -527,7 +527,7 @@ fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" -glob@7.0.5: +glob@7.0.5, glob@^7.0.5: version "7.0.5" resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95" dependencies: @@ -715,6 +715,14 @@ ms@0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" +multidep@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/multidep/-/multidep-2.0.1.tgz#a98c498243b5d077ef368ff50039130858904d02" + dependencies: + rimraf "^2.4.3" + rsvp "^3.1.0" + spawn-cmd "0.0.2" + number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" @@ -793,6 +801,12 @@ resolve@^1.1.6, resolve@^1.1.7: version "1.2.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.2.0.tgz#9589c3f2f6149d1417a40becc1663db6ec6bc26c" +rimraf@^2.4.3: + version "2.5.4" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04" + dependencies: + glob "^7.0.5" + rollup-plugin-babel@^2.7.0: version "2.7.1" resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-2.7.1.tgz#16528197b0f938a1536f44683c7a93d573182f57" @@ -839,7 +853,7 @@ rollup@^0.37.0: dependencies: source-map-support "^0.4.0" -rsvp@~3.2.1: +rsvp@^3.1.0, rsvp@~3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.2.1.tgz#07cb4a5df25add9e826ebc67dcc9fd89db27d84a" @@ -857,6 +871,10 @@ source-map@^0.5.0, source-map@^0.5.3: version "0.5.6" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" +spawn-cmd@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/spawn-cmd/-/spawn-cmd-0.0.2.tgz#6d5e251fad0eab00b0f193d245669a7a228ec0de" + strip-ansi@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"