@@ -264,25 +264,17 @@ describe('FBP Graph', () => {
264
264
const json = JSON . parse ( jsonString ) ;
265
265
let g ;
266
266
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
+ } ) ) ;
276
272
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
+ } ) ) ;
286
278
287
279
it ( 'should not mutate the inputted json object' , ( done ) => {
288
280
chai . expect ( Object . keys ( json . processes ) . length ) . to . equal ( 4 ) ;
@@ -693,24 +685,37 @@ describe('FBP Graph', () => {
693
685
const fs = require ( 'fs' ) ;
694
686
fs . unlink ( graphPath , done ) ;
695
687
} ) ;
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 ) => {
697
695
const g = new lib . graph . Graph ( ) ;
698
696
g . addNode ( 'Foo' , 'Bar' ) ;
699
697
originalGraph = g . toJSON ( ) ;
700
698
g . save ( graphPath , done ) ;
701
699
} ) ;
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
+ } ) ;
714
719
} ) ;
715
720
describe ( 'without .json suffix' , ( ) => {
716
721
let graphPathLegacy ;
0 commit comments