Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Begin working on testing harness for both 0.2 and 0.3. #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/dist
/node_modules
/tests/multidep
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function build(entry, dest, format) {
entry: entry,

external: [
'fs', 'heimdalljs', 'chai'
'fs', 'heimdalljs', 'chai', 'multidep'
],
plugins: [
babel({ exclude: 'node_modules/**' }),
Expand Down
6 changes: 6 additions & 0 deletions tests/multidep.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"path": "tests/multidep",
"versions": {
"heimdalljs": ["0.2.3"]
}
}
15 changes: 13 additions & 2 deletions tests/runtimes/node.js
Original file line number Diff line number Diff line change
@@ -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');
});
Expand Down
114 changes: 93 additions & 21 deletions tests/shared.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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'
]);
});
});
}
22 changes: 20 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand All @@ -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"
Expand Down