mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-06 22:04:16 +01:00
add more tests in cli_test-samples: flowchart, sequence, gantt, gitgraph, load html in phantomjs and save screenshot png
This commit is contained in:
@@ -6,6 +6,8 @@ var path = require('path')
|
||||
, rimraf = require('rimraf')
|
||||
|
||||
var test_dir = 'test/fixtures/samples/'.replace('/',path.sep)
|
||||
var phantomjs = 'node_modules/.bin/phantomjs '.replace('/',path.sep)
|
||||
var load_html_save_screenshot_png_scripts = test_dir+path.sep+'load_html_save_screenshot_png.phantomjs'
|
||||
|
||||
rimraf.sync(test_dir+'*.actual.*');
|
||||
|
||||
@@ -18,22 +20,42 @@ function exec_mermaid(args, verify) {
|
||||
});
|
||||
}
|
||||
|
||||
function exec_phantomjs_to_load_html_save_screenshot_png(html, verify) {
|
||||
var cmd = (phantomjs + ' ' + load_html_save_screenshot_png_scripts +
|
||||
' ' + html + ' ' + html + '.actual.png');
|
||||
console.log(cmd)
|
||||
exec(cmd,
|
||||
{env: {PATH: './node_modules/.bin'+path.delimiter+process.env.PATH}},
|
||||
function(error, stdout, stderr) {
|
||||
console.log('error:',error,'\nstdout:\n',stdout,'\nstderr:\n',stderr);
|
||||
verify(error, stdout, stderr);
|
||||
});
|
||||
}
|
||||
|
||||
function verify_no_error(t) {
|
||||
return function(error, stdout, stderr) {
|
||||
t.notOk(stderr, 'no error')
|
||||
t.end()
|
||||
}
|
||||
}
|
||||
|
||||
function verify_error(t) {
|
||||
return function(error, stdout, stderr) {
|
||||
t.ok(stderr, 'should get error')
|
||||
t.end()
|
||||
}
|
||||
}
|
||||
|
||||
test('mermaid cli help', function(t) {
|
||||
t.plan(1);
|
||||
var args = [ '--help' ]
|
||||
exec_mermaid(args.join(' '), function(error, stdout, stderr) {
|
||||
t.notOk(stderr, 'no error')
|
||||
t.end()
|
||||
});
|
||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
||||
});
|
||||
|
||||
test('mermaid cli help', function(t) {
|
||||
t.plan(1);
|
||||
var args = [ '--badopt' ]
|
||||
exec_mermaid(args.join(' '), function(error, stdout, stderr) {
|
||||
t.ok(stderr, 'should get error')
|
||||
t.end()
|
||||
});
|
||||
exec_mermaid(args.join(' '), verify_error(t));
|
||||
});
|
||||
|
||||
//todo
|
||||
@@ -44,10 +66,7 @@ test.skip('sequence syntax error', function(t) {
|
||||
'--outputSuffix=.actual',
|
||||
test_dir+'sequence_err.mmd'
|
||||
]
|
||||
exec_mermaid(args.join(' '), function(error, stdout, stderr) {
|
||||
t.ok(stderr, 'should get error')
|
||||
t.end()
|
||||
});
|
||||
exec_mermaid(args.join(' '), verify_error(t));
|
||||
});
|
||||
|
||||
['', 'fo', 'tspan', 'old'].forEach(function(textPlacement) {
|
||||
@@ -59,10 +78,7 @@ test.skip('sequence syntax error', function(t) {
|
||||
textPlacement ? '--sequenceConfig='+test_dir+'sequence_text_'+textPlacement+'.cfg' : '',
|
||||
test_dir+'sequence_text.mmd'
|
||||
]
|
||||
exec_mermaid(args.join(' '), function(error, stdout, stderr) {
|
||||
t.notOk(stderr, 'no error')
|
||||
t.end()
|
||||
});
|
||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
||||
})
|
||||
});
|
||||
|
||||
@@ -73,21 +89,62 @@ test('sequence png', function(t) {
|
||||
'--outputSuffix=.actual',
|
||||
test_dir+'sequence_text.mmd'
|
||||
]
|
||||
exec_mermaid(args.join(' '), function(error, stdout, stderr) {
|
||||
t.notOk(stderr, 'no error')
|
||||
t.end()
|
||||
});
|
||||
})
|
||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
||||
});
|
||||
|
||||
test('flowchart svg text', function(t) {
|
||||
t.plan(1);
|
||||
var args = [ '--svg',
|
||||
'--outputDir=' + test_dir,
|
||||
'--outputSuffix=.actual',
|
||||
'--css=dist/mermaid.css',
|
||||
'--width=500',
|
||||
test_dir+'flowchart_text.mmd'
|
||||
]
|
||||
exec_mermaid(args.join(' '), function(error, stdout, stderr) {
|
||||
t.notOk(stderr, 'no error')
|
||||
t.end()
|
||||
});
|
||||
})
|
||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
||||
});
|
||||
|
||||
['svg', 'png'].forEach(function(format) {
|
||||
test('flowchart '+format+'text2', function(t) {
|
||||
t.plan(1);
|
||||
var args = [ '--'+format,
|
||||
'--outputDir=' + test_dir,
|
||||
'--outputSuffix=.actual',
|
||||
'--css=dist/mermaid.forest.css',
|
||||
'--width=500',
|
||||
test_dir+'flowchart_text2.mmd'
|
||||
]
|
||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
||||
}) });
|
||||
|
||||
|
||||
test('gantt axis formatter svg', function(t) {
|
||||
t.plan(1);
|
||||
var args = [ '--svg',
|
||||
'--outputDir=' + test_dir,
|
||||
'--outputSuffix=.actual',
|
||||
'--css=dist/mermaid.css',
|
||||
'--width=500',
|
||||
'--ganttConfig='+test_dir+'gantt_axis_formatter.cfg',
|
||||
test_dir+'gantt_axis_formatter.mmd'
|
||||
]
|
||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
||||
});
|
||||
|
||||
|
||||
test('gitgraph sample svg', function(t) {
|
||||
t.plan(1);
|
||||
var args = [ '-s', "-v",
|
||||
'--outputDir=' + test_dir,
|
||||
'--outputSuffix=.actual',
|
||||
'--width=500',
|
||||
test_dir+'gitgraph.mmd'
|
||||
]
|
||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
||||
});
|
||||
|
||||
test('load sample.html in phantomjs and save screenshot png', function(t) {
|
||||
t.plan(1);
|
||||
exec_phantomjs_to_load_html_save_screenshot_png(test_dir+'samples.html',
|
||||
verify_no_error(t));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user