Skip to content

Commit 0baf025

Browse files
committed
Implement Promises support
1 parent 833a32b commit 0baf025

File tree

3 files changed

+243
-189
lines changed

3 files changed

+243
-189
lines changed

spec/Graph.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -264,25 +264,17 @@ describe('FBP Graph', () => {
264264
const json = JSON.parse(jsonString);
265265
let g;
266266

267-
it('should produce a Graph when input is string', (done) => lib.graph.loadJSON(jsonString, (err, instance) => {
268-
if (err) {
269-
done(err);
270-
return;
271-
}
272-
g = instance;
273-
chai.expect(g).to.be.an('object');
274-
done();
275-
}));
267+
it('should produce a Graph when input is string', () => lib.graph.loadJSON(jsonString)
268+
.then((instance) => {
269+
g = instance;
270+
chai.expect(g).to.be.an('object');
271+
}));
276272

277-
it('should produce a Graph when input is json', (done) => lib.graph.loadJSON(json, (err, instance) => {
278-
if (err) {
279-
done(err);
280-
return;
281-
}
282-
g = instance;
283-
chai.expect(g).to.be.an('object');
284-
done();
285-
}));
273+
it('should produce a Graph when input is JSON', () => lib.graph.loadJSON(json)
274+
.then((instance) => {
275+
g = instance;
276+
chai.expect(g).to.be.an('object');
277+
}));
286278

287279
it('should not mutate the inputted json object', (done) => {
288280
chai.expect(Object.keys(json.processes).length).to.equal(4);
@@ -693,24 +685,37 @@ describe('FBP Graph', () => {
693685
const fs = require('fs');
694686
fs.unlink(graphPath, done);
695687
});
696-
it('should be possible to save a graph to a file', (done) => {
688+
it('should be possible to save a graph to a file', () => {
689+
const g = new lib.graph.Graph();
690+
g.addNode('Foo', 'Bar');
691+
originalGraph = g.toJSON();
692+
return g.save(graphPath);
693+
});
694+
it('should be possible to save a graph to a file with a callback', (done) => {
697695
const g = new lib.graph.Graph();
698696
g.addNode('Foo', 'Bar');
699697
originalGraph = g.toJSON();
700698
g.save(graphPath, done);
701699
});
702-
it('should be possible to load a graph from a file', (done) => lib.graph.loadFile(graphPath, (err, g) => {
703-
if (err) {
704-
done(err);
705-
return;
706-
}
707-
if (!g) {
708-
done(new Error('No graph'));
709-
return;
710-
}
711-
chai.expect(g.toJSON()).to.eql(originalGraph);
712-
done();
713-
}));
700+
it('should be possible to load a graph from a file', () => lib.graph.loadFile(graphPath)
701+
.then((g) => {
702+
chai.expect(g).to.be.an('object');
703+
chai.expect(g.toJSON()).to.eql(originalGraph);
704+
}));
705+
it('should be possible to load a graph from a file with a callback', (done) => {
706+
lib.graph.loadFile(graphPath, (err, g) => {
707+
if (err) {
708+
done(err);
709+
return;
710+
}
711+
if (!g) {
712+
done(new Error('No graph'));
713+
return;
714+
}
715+
chai.expect(g.toJSON()).to.eql(originalGraph);
716+
done();
717+
});
718+
});
714719
});
715720
describe('without .json suffix', () => {
716721
let graphPathLegacy;

0 commit comments

Comments
 (0)