mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-14 17:54:13 +01:00
Convert test/cli_test-sample.js to ES6
This commit is contained in:
@@ -1,141 +1,139 @@
|
|||||||
'use strict';
|
const exec = require('child_process').exec
|
||||||
var exec = require('child_process').exec;
|
const path = require('path')
|
||||||
var path = require('path')
|
|
||||||
|
|
||||||
var test = require('tape')
|
const test = require('tape')
|
||||||
, rimraf = require('rimraf')
|
const rimraf = require('rimraf')
|
||||||
|
|
||||||
var test_dir = 'test/fixtures/samples/'.replace('/',path.sep)
|
const testDir = 'test/fixtures/samples/'.replace('/', path.sep)
|
||||||
var phantomjs = 'node_modules/.bin/phantomjs '.replace('/',path.sep)
|
const 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'
|
const loadHtmlSaveScreenshotPngScripts = testDir + path.sep + 'load_html_save_screenshot_png.phantomjs'
|
||||||
|
|
||||||
rimraf.sync(test_dir+'*.actual.*');
|
rimraf.sync(testDir + '*.actual.*')
|
||||||
|
|
||||||
function prepend_output_args(args) {
|
function prependOutputArgs (args) {
|
||||||
return '--outputDir=' + test_dir + ' --outputSuffix=.actual' + args
|
return '--outputDir=' + testDir + ' --outputSuffix=.actual' + args
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec_mermaid(args, verify) {
|
function execMermaid (args, verify) {
|
||||||
var cmd = 'bin/mermaid.js ' + args
|
const cmd = 'bin/mermaid.js ' + args
|
||||||
exec_cmd(cmd, verify)
|
execCmd(cmd, verify)
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec_phantomjs_to_load_html_save_screenshot_png(html, verify) {
|
function execPhantomjsToLoadHtmlSaveScreenshotPng (html, verify) {
|
||||||
var cmd = (phantomjs + ' ' + load_html_save_screenshot_png_scripts +
|
const cmd = (phantomjs + ' ' + loadHtmlSaveScreenshotPngScripts +
|
||||||
' ' + html + ' ' + html + '.actual.png');
|
' ' + html + ' ' + html + '.actual.png')
|
||||||
exec_cmd(cmd, verify)
|
execCmd(cmd, verify)
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec_cmd(cmd, verify) {
|
function execCmd (cmd, verify) {
|
||||||
console.log('cmd: ', cmd)
|
console.log('cmd: ', cmd)
|
||||||
exec(cmd,
|
exec(cmd,
|
||||||
{env: {PATH: './node_modules/.bin'+path.delimiter+process.env.PATH}},
|
{ env: { PATH: './node_modules/.bin' + path.delimiter + process.env.PATH } },
|
||||||
function(error, stdout, stderr) {
|
function (error, stdout, stderr) {
|
||||||
console.log('error:',error,'\nstdout:\n',stdout,'\nstderr:\n',stderr);
|
console.log('error:', error, '\nstdout:\n', stdout, '\nstderr:\n', stderr)
|
||||||
verify(error, stdout, stderr);
|
verify(error, stdout, stderr)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function verify_no_error(t) {
|
function verifyNoError (t) {
|
||||||
return function(error, stdout, stderr) {
|
return function (error, stdout, stderr) {
|
||||||
t.notOk(stderr, 'no error')
|
t.notOk(stderr, 'no stderr')
|
||||||
t.end()
|
t.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function verify_error(t) {
|
function verifyError (t) {
|
||||||
return function(error, stdout, stderr) {
|
return function (error, stdout, stderr) {
|
||||||
t.ok(stderr, 'should get error')
|
t.ok(stderr, 'should get error')
|
||||||
t.end()
|
t.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test('mermaid cli help', function(t) {
|
test('mermaid cli help', function (t) {
|
||||||
t.plan(1);
|
t.plan(1)
|
||||||
var args = [ '--help' ]
|
const args = ['--help']
|
||||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
execMermaid(args.join(' '), verifyNoError(t))
|
||||||
});
|
})
|
||||||
|
|
||||||
test('mermaid cli help', function(t) {
|
test('mermaid cli help', function (t) {
|
||||||
t.plan(1);
|
t.plan(1)
|
||||||
var args = [ '--badopt' ]
|
const args = ['--badopt']
|
||||||
exec_mermaid(args.join(' '), verify_error(t));
|
execMermaid(args.join(' '), verifyError(t))
|
||||||
});
|
})
|
||||||
|
|
||||||
test.skip('sequence syntax error', function(t) {
|
test.skip('sequence syntax error', function (t) {
|
||||||
t.plan(1);
|
t.plan(1)
|
||||||
var args = [ '--svg',
|
const args = ['--svg',
|
||||||
test_dir+'sequence_err.mmd'
|
testDir + 'sequence_err.mmd'
|
||||||
]
|
]
|
||||||
exec_mermaid(prepend_output_args(args.join(' ')), verify_no_error(t));
|
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
|
||||||
});
|
});
|
||||||
|
|
||||||
['', 'fo', 'tspan', 'old'].forEach(function(textPlacement) {
|
['', 'fo', 'tspan', 'old'].forEach(function (textPlacement) {
|
||||||
test('sequence svg text placelment: '+textPlacement, function(t) {
|
test('sequence svg text placelment: ' + textPlacement, function (t) {
|
||||||
t.plan(1);
|
t.plan(1)
|
||||||
var args = [ '--svg',
|
const args = ['--svg',
|
||||||
'--outputDir=' + test_dir,
|
'--outputDir=' + testDir,
|
||||||
'--outputSuffix='+(textPlacement ? '_'+textPlacement : '')+'.actual',
|
'--outputSuffix=' + (textPlacement ? '_' + textPlacement : '') + '.actual',
|
||||||
textPlacement ? '--sequenceConfig='+test_dir+'sequence_text_'+textPlacement+'.cfg' : '',
|
textPlacement ? '--sequenceConfig=' + testDir + 'sequence_text_' + textPlacement + '.cfg' : '',
|
||||||
test_dir+'sequence_text.mmd'
|
testDir + 'sequence_text.mmd'
|
||||||
]
|
]
|
||||||
exec_mermaid(args.join(' '), verify_no_error(t));
|
execMermaid(args.join(' '), verifyNoError(t))
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
test('sequence png', function(t) {
|
test('sequence png', function (t) {
|
||||||
t.plan(1);
|
t.plan(1)
|
||||||
var args = [ '--png',
|
const args = ['--png',
|
||||||
test_dir+'sequence_text.mmd'
|
testDir + 'sequence_text.mmd'
|
||||||
]
|
]
|
||||||
exec_mermaid(prepend_output_args(args.join(' ')), verify_no_error(t));
|
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
|
||||||
});
|
})
|
||||||
|
|
||||||
test('flowchart svg text', function(t) {
|
test('flowchart svg text', function (t) {
|
||||||
t.plan(1);
|
t.plan(1)
|
||||||
var args = [ '--svg',
|
const args = ['--svg',
|
||||||
'--css=dist/mermaid.css',
|
'--css=dist/mermaid.css',
|
||||||
'--width=500',
|
'--width=500',
|
||||||
test_dir+'flowchart_text.mmd'
|
testDir + 'flowchart_text.mmd'
|
||||||
]
|
]
|
||||||
exec_mermaid(prepend_output_args(args.join(' ')), verify_no_error(t));
|
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
|
||||||
});
|
});
|
||||||
|
|
||||||
['svg', 'png'].forEach(function(format) {
|
['svg', 'png'].forEach(function (format) {
|
||||||
test('flowchart '+format+'text2', function(t) {
|
test('flowchart ' + format + 'text2', function (t) {
|
||||||
t.plan(1);
|
t.plan(1)
|
||||||
var args = [ '--'+format,
|
const args = ['--' + format,
|
||||||
'--css=dist/mermaid.forest.css',
|
'--css=dist/mermaid.forest.css',
|
||||||
'--width=500',
|
'--width=500',
|
||||||
test_dir+'flowchart_text2.mmd'
|
testDir + 'flowchart_text2.mmd'
|
||||||
]
|
]
|
||||||
exec_mermaid(prepend_output_args(args.join(' ')), verify_no_error(t));
|
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
|
||||||
}) });
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('gantt axis formatter svg', function (t) {
|
||||||
test('gantt axis formatter svg', function(t) {
|
t.plan(1)
|
||||||
t.plan(1);
|
const args = ['--svg',
|
||||||
var args = [ '--svg',
|
|
||||||
'--css=dist/mermaid.css',
|
'--css=dist/mermaid.css',
|
||||||
'--width=500',
|
'--width=500',
|
||||||
'--ganttConfig='+test_dir+'gantt_axis_formatter.cfg',
|
'--ganttConfig=' + testDir + 'gantt_axis_formatter.cfg',
|
||||||
test_dir+'gantt_axis_formatter.mmd'
|
testDir + 'gantt_axis_formatter.mmd'
|
||||||
]
|
]
|
||||||
exec_mermaid(prepend_output_args(args.join(' ')), verify_no_error(t));
|
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
|
||||||
});
|
})
|
||||||
|
|
||||||
|
test('gitgraph sample svg', function (t) {
|
||||||
test('gitgraph sample svg', function(t) {
|
t.plan(1)
|
||||||
t.plan(1);
|
const args = ['-s', '-v',
|
||||||
var args = [ '-s', '-v',
|
|
||||||
'--width=500',
|
'--width=500',
|
||||||
test_dir+'gitgraph.mmd'
|
testDir + 'gitgraph.mmd'
|
||||||
]
|
]
|
||||||
exec_mermaid(prepend_output_args(args.join(' ')), verify_no_error(t));
|
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
|
||||||
});
|
})
|
||||||
|
|
||||||
test('load sample.html in phantomjs and save screenshot png', function(t) {
|
test('load sample.html in phantomjs and save screenshot png', function (t) {
|
||||||
t.plan(1);
|
t.plan(1)
|
||||||
exec_phantomjs_to_load_html_save_screenshot_png(test_dir+'samples.html',
|
execPhantomjsToLoadHtmlSaveScreenshotPng(testDir + 'samples.html',
|
||||||
verify_no_error(t));
|
verifyNoError(t))
|
||||||
});
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user