2014-12-20 17:40:58 -08:00
|
|
|
var fs = require('fs')
|
|
|
|
, path = require('path')
|
|
|
|
|
|
|
|
var test = require('tape')
|
|
|
|
, async = require('async')
|
|
|
|
, clone = require('clone')
|
|
|
|
, rimraf = require('rimraf')
|
|
|
|
|
|
|
|
var mermaid = require('../lib')
|
|
|
|
|
2015-12-26 10:59:44 +01:00
|
|
|
var fileTestMermaid = path.join('test','fixtures','test.mermaid');
|
|
|
|
var isWin = /^win/.test(process.platform);
|
|
|
|
var phantomCmd;
|
|
|
|
if(isWin){
|
|
|
|
phantomCmd = 'node_modules/.bin/phantomjs.cmd'
|
2016-12-13 21:05:16 -05:00
|
|
|
console.log('is win')
|
2015-12-26 10:59:44 +01:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
phantomCmd = 'node_modules/.bin/phantomjs'
|
|
|
|
}
|
2014-12-20 17:40:58 -08:00
|
|
|
var singleFile = {
|
2015-12-26 10:59:44 +01:00
|
|
|
files: [fileTestMermaid]
|
2016-12-13 21:05:16 -05:00
|
|
|
, outputDir: path.join(process.cwd(),'test/tmp_single')
|
2015-12-26 10:59:44 +01:00
|
|
|
, phantomPath: path.join(process.cwd(),phantomCmd)
|
|
|
|
, width : 1200
|
2016-09-28 13:56:23 -05:00
|
|
|
, css: path.join(__dirname, '..', 'dist', 'mermaid.css')
|
|
|
|
, sequenceConfig: null
|
|
|
|
, ganttConfig: null
|
2014-12-20 17:40:58 -08:00
|
|
|
}
|
|
|
|
, multiFile = {
|
2016-12-13 21:05:16 -05:00
|
|
|
files: [path.join('test','fixtures','test.mermaid'),
|
|
|
|
path.join('test','fixtures','test2.mermaid'),
|
|
|
|
path.join('test','fixtures','gantt.mermaid'),
|
|
|
|
path.join('test','fixtures','sequence.mermaid'),
|
|
|
|
]
|
|
|
|
, outputDir: 'test/tmp_multi'
|
2015-12-26 10:59:44 +01:00
|
|
|
, phantomPath: path.join(process.cwd(),phantomCmd)
|
|
|
|
, width : 1200
|
2016-09-28 13:56:23 -05:00
|
|
|
, css: path.join(__dirname, '..', 'dist', 'mermaid.css')
|
|
|
|
, sequenceConfig: null
|
|
|
|
, ganttConfig: null
|
2014-12-20 17:40:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test('output of single png', function(t) {
|
|
|
|
t.plan(3)
|
|
|
|
|
|
|
|
var expected = ['test.mermaid.png']
|
|
|
|
|
2016-12-17 18:03:11 -05:00
|
|
|
var opt = clone(singleFile)
|
2016-12-13 21:05:16 -05:00
|
|
|
opt.outputDir += '_png'
|
2014-12-20 17:40:58 -08:00
|
|
|
opt.png = true
|
2016-09-28 13:56:23 -05:00
|
|
|
|
2014-12-20 17:40:58 -08:00
|
|
|
mermaid.process(opt.files, opt, function(code) {
|
|
|
|
t.equal(code, 0, 'has clean exit code')
|
|
|
|
|
|
|
|
verifyFiles(expected, opt.outputDir, t)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('output of multiple png', function(t) {
|
|
|
|
t.plan(3)
|
|
|
|
|
2016-12-13 21:05:16 -05:00
|
|
|
var expected = ['test.mermaid.png', 'test2.mermaid.png',
|
|
|
|
'gantt.mermaid.png', 'sequence.mermaid.png']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2016-12-17 18:03:11 -05:00
|
|
|
var opt = clone(multiFile)
|
2016-12-13 21:05:16 -05:00
|
|
|
opt.outputDir += '_png'
|
2014-12-20 17:40:58 -08:00
|
|
|
opt.png = true
|
|
|
|
|
|
|
|
mermaid.process(opt.files, opt, function(code) {
|
|
|
|
t.equal(code, 0, 'has clean exit code')
|
|
|
|
|
|
|
|
verifyFiles(expected, opt.outputDir, t)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('output of single svg', function(t) {
|
|
|
|
t.plan(3)
|
|
|
|
|
|
|
|
var expected = ['test.mermaid.svg']
|
|
|
|
|
2016-12-17 18:03:11 -05:00
|
|
|
var opt = clone(singleFile)
|
2016-12-13 21:05:16 -05:00
|
|
|
opt.outputDir += '_svg'
|
2014-12-20 17:40:58 -08:00
|
|
|
opt.svg = true
|
|
|
|
|
|
|
|
mermaid.process(opt.files, opt, function(code) {
|
|
|
|
t.equal(code, 0, 'has clean exit code')
|
|
|
|
|
|
|
|
verifyFiles(expected, opt.outputDir, t)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('output of multiple svg', function(t) {
|
|
|
|
t.plan(3)
|
|
|
|
|
2016-12-13 21:05:16 -05:00
|
|
|
var expected = ['test.mermaid.svg', 'test2.mermaid.svg',
|
|
|
|
'gantt.mermaid.svg', 'sequence.mermaid.svg']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2016-12-17 18:03:11 -05:00
|
|
|
var opt = clone(multiFile)
|
2016-12-13 21:05:16 -05:00
|
|
|
opt.outputDir += '_svg'
|
2014-12-20 17:40:58 -08:00
|
|
|
opt.svg = true
|
|
|
|
|
|
|
|
mermaid.process(opt.files, opt, function(code) {
|
|
|
|
t.equal(code, 0, 'has clean exit code')
|
|
|
|
|
|
|
|
verifyFiles(expected, opt.outputDir, t)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-02-02 19:02:45 -08:00
|
|
|
test('output including CSS', function(t) {
|
|
|
|
t.plan(5)
|
|
|
|
|
|
|
|
var expected = ['test.mermaid.png']
|
|
|
|
, opt = clone(singleFile)
|
2015-12-26 10:59:44 +01:00
|
|
|
, opt2 = clone(singleFile)
|
2015-02-02 19:02:45 -08:00
|
|
|
, filename
|
|
|
|
, one
|
|
|
|
, two
|
|
|
|
|
|
|
|
opt.png = true
|
2016-12-13 21:05:16 -05:00
|
|
|
opt.outputDir += '_css_png'
|
2015-12-26 10:59:44 +01:00
|
|
|
opt2.png = true
|
2016-12-13 21:05:16 -05:00
|
|
|
opt2.outputDir += '_css_png'
|
2015-12-26 10:59:44 +01:00
|
|
|
|
2015-02-02 19:02:45 -08:00
|
|
|
|
|
|
|
mermaid.process(opt.files, opt, function(code) {
|
|
|
|
t.equal(code, 0, 'has clean exit code')
|
|
|
|
filename = path.join(opt.outputDir, path.basename(expected[0]))
|
|
|
|
one = fs.statSync(filename)
|
|
|
|
|
2016-09-28 13:56:23 -05:00
|
|
|
opt2.css = path.join('test','fixtures','test.css')
|
2015-02-02 19:02:45 -08:00
|
|
|
|
2016-12-13 21:05:16 -05:00
|
|
|
console.log('Generating #2');
|
2015-12-26 10:59:44 +01:00
|
|
|
mermaid.process(opt2.files, opt2, function(code) {
|
2015-02-02 19:02:45 -08:00
|
|
|
t.equal(code, 0, 'has clean exit code')
|
|
|
|
two = fs.statSync(filename)
|
|
|
|
t.notEqual(one.size, two.size)
|
|
|
|
|
|
|
|
verifyFiles(expected, opt.outputDir, t)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2014-12-20 17:40:58 -08:00
|
|
|
function verifyFiles(expected, dir, t) {
|
|
|
|
async.each(
|
|
|
|
expected
|
|
|
|
, function(file, cb) {
|
|
|
|
filename = path.join(dir, path.basename(file))
|
2015-12-26 10:59:44 +01:00
|
|
|
//console.log('Expected filename:'+filename);
|
2014-12-20 17:40:58 -08:00
|
|
|
fs.stat(filename, function(err, stat) {
|
|
|
|
cb(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
, function(err) {
|
|
|
|
t.notOk(err, 'all files passed')
|
2016-12-17 18:03:11 -05:00
|
|
|
var delete_tmps = false
|
2016-12-13 21:05:16 -05:00
|
|
|
var _rimraf=delete_tmps ? rimraf : function(dir, f) { f(0); }
|
|
|
|
_rimraf(dir, function(rmerr) {
|
2014-12-20 17:40:58 -08:00
|
|
|
t.notOk(rmerr, 'cleaned up')
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|