Skip to content

Commit

Permalink
Make graphlib.core work with amd
Browse files Browse the repository at this point in the history
  • Loading branch information
sprilukin authored and cpettitt committed Feb 21, 2016
1 parent dd14766 commit aa16a58
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions karma.amd.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
{pattern: 'node_modules/chai/chai.js', included: false},
{pattern: 'node_modules/lodash/index.js', included: false},
{pattern: 'build/graphlib*.js', included: false},
{pattern: 'test/bundle.amd-test.js', included: false},
'test/test-main.js'
Expand Down
34 changes: 34 additions & 0 deletions test/bundle.amd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,42 @@ define(function(require) {

var chai = require("chai"),
graphlib = require("graphlib"),
graphlibCore = require("graphlib.core"),
expect = chai.expect;

describe("core bundle", function() {
it("exports graphlib", function() {
expect(graphlibCore).to.be.an("object");
expect(graphlibCore.Graph).to.be.a("function");
expect(graphlibCore.json).to.be.a("object");
expect(graphlibCore.alg).to.be.a("object");
expect(graphlibCore.version).to.be.a("string");
});

it("can do simple graph operations", function() {
var g = new graphlibCore.Graph();
g.setNode("a");
g.setNode("b");
g.setEdge("a", "b");
expect(g.hasNode("a")).to.be.true;
expect(g.hasNode("b")).to.be.true;
expect(g.hasEdge("a", "b")).to.be.true;
});

it("can serialize to json and back", function() {
var g = new graphlibCore.Graph();
g.setNode("a");
g.setNode("b");
g.setEdge("a", "b");

var json = graphlibCore.json.write(g);
var g2 = graphlibCore.json.read(json);
expect(g2.hasNode("a")).to.be.true;
expect(g2.hasNode("b")).to.be.true;
expect(g2.hasEdge("a", "b")).to.be.true;
});
});

describe("bundle", function() {
it("exports graphlib", function() {
expect(graphlib).to.be.an("object");
Expand Down
11 changes: 10 additions & 1 deletion test/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ require.config({

paths:{
chai: 'node_modules/chai/chai',
graphlib: 'build/graphlib'
lodash: 'node_modules/lodash/index',
graphlib: 'build/graphlib',
'graphlib.core': 'build/graphlib.core'
},

shim: {
'graphlib.core': {
deps: ["lodash"],
exports: "graphlib.core" //any even not existing var could be defined here.
}
},

// dynamically load all test files
Expand Down

0 comments on commit aa16a58

Please sign in to comment.