mermaid/test/cli_test-samples.js

142 lines
3.8 KiB
JavaScript
Raw Normal View History

2017-04-10 22:24:20 +08:00
const exec = require('child_process').exec
const path = require('path')
2017-04-10 22:24:20 +08:00
const test = require('tape')
const rimraf = require('rimraf')
2017-04-10 22:24:20 +08:00
const testDir = 'test/fixtures/samples/'.replace('/', path.sep)
const phantomjs = 'node_modules/.bin/phantomjs '.replace('/', path.sep)
const loadHtmlSaveScreenshotPngScripts = testDir + path.sep + 'load_html_save_screenshot_png.phantomjs'
2017-04-10 22:24:20 +08:00
rimraf.sync(testDir + '*.actual.*')
2017-01-01 23:36:42 -05:00
2017-04-10 22:24:20 +08:00
function prependOutputArgs (args) {
return '--outputDir=' + testDir + ' --outputSuffix=.actual' + args
2017-01-01 23:36:42 -05:00
}
2017-04-10 22:24:20 +08:00
function execMermaid (args, verify) {
const cmd = 'bin/mermaid.js ' + args
execCmd(cmd, verify)
}
2017-04-10 22:24:20 +08:00
function execPhantomjsToLoadHtmlSaveScreenshotPng (html, verify) {
const cmd = (phantomjs + ' ' + loadHtmlSaveScreenshotPngScripts +
' ' + html + ' ' + html + '.actual.png')
execCmd(cmd, verify)
2017-01-01 23:41:38 -05:00
}
2017-04-10 22:24:20 +08:00
function execCmd (cmd, verify) {
2017-01-01 23:36:42 -05:00
console.log('cmd: ', cmd)
exec(cmd,
2017-04-10 22:24:20 +08:00
{ 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)
})
}
2017-04-10 22:24:20 +08:00
function verifyNoError (t) {
return function (error, stdout, stderr) {
2017-04-11 21:52:19 +08:00
t.ok(!error, 'no error')
2017-04-10 22:24:20 +08:00
t.notOk(stderr, 'no stderr')
t.end()
}
}
2017-04-10 22:24:20 +08:00
function verifyError (t) {
return function (error, stdout, stderr) {
2017-04-11 21:52:19 +08:00
t.ok(!error, 'no error')
t.ok(stderr, 'should get stderr')
t.end()
}
}
2017-04-10 22:24:20 +08:00
test('mermaid cli help', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['--help']
execMermaid(args.join(' '), verifyNoError(t))
})
test('mermaid cli help', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['--badopt']
execMermaid(args.join(' '), verifyError(t))
})
test.skip('sequence syntax error', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['--svg',
testDir + 'sequence_err.mmd'
2016-12-18 22:52:41 -05:00
]
2017-04-10 22:24:20 +08:00
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
2016-12-18 22:52:41 -05:00
});
2017-04-10 22:24:20 +08:00
['', 'fo', 'tspan', 'old'].forEach(function (textPlacement) {
test('sequence svg text placelment: ' + textPlacement, function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['--svg',
'--outputDir=' + testDir,
'--outputSuffix=' + (textPlacement ? '_' + textPlacement : '') + '.actual',
textPlacement ? '--sequenceConfig=' + testDir + 'sequence_text_' + textPlacement + '.cfg' : '',
testDir + 'sequence_text.mmd'
]
2017-04-10 22:24:20 +08:00
execMermaid(args.join(' '), verifyNoError(t))
})
2017-04-10 22:24:20 +08:00
})
2017-04-10 22:24:20 +08:00
test('sequence png', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['--png',
testDir + 'sequence_text.mmd'
2016-12-18 22:52:41 -05:00
]
2017-04-10 22:24:20 +08:00
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
})
2017-04-10 22:24:20 +08:00
test('flowchart svg text', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['--svg',
'--css=dist/mermaid.css',
'--width=500',
2017-04-10 22:24:20 +08:00
testDir + 'flowchart_text.mmd'
]
2017-04-10 22:24:20 +08:00
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
});
2017-04-10 22:24:20 +08:00
['svg', 'png'].forEach(function (format) {
test('flowchart ' + format + 'text2', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['--' + format,
'--css=dist/mermaid.forest.css',
'--width=500',
testDir + 'flowchart_text2.mmd'
]
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
})
})
2017-04-10 22:24:20 +08:00
test('gantt axis formatter svg', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['--svg',
'--css=dist/mermaid.css',
'--width=500',
2017-04-10 22:24:20 +08:00
'--ganttConfig=' + testDir + 'gantt_axis_formatter.cfg',
testDir + 'gantt_axis_formatter.mmd'
]
2017-04-10 22:24:20 +08:00
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
})
2017-04-10 22:24:20 +08:00
test('gitgraph sample svg', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
const args = ['-s', '-v',
'--width=500',
2017-04-10 22:24:20 +08:00
testDir + 'gitgraph.mmd'
]
2017-04-10 22:24:20 +08:00
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
})
test('load sample.html in phantomjs and save screenshot png', function (t) {
2017-04-11 21:52:19 +08:00
t.plan(2)
2017-04-10 22:24:20 +08:00
execPhantomjsToLoadHtmlSaveScreenshotPng(testDir + 'samples.html',
verifyNoError(t))
})