2017-09-10 11:42:39 +08:00
|
|
|
/* eslint-env jest */
|
|
|
|
/* eslint-env jasmine */
|
2017-09-10 21:23:04 +08:00
|
|
|
import cli from '../lib/cli'
|
2017-04-10 21:59:40 +08:00
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000
|
|
|
|
})
|
|
|
|
|
|
|
|
test('parses multiple files', function (done) {
|
|
|
|
expect.assertions(3)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
const argv = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
|
2017-09-10 11:42:39 +08:00
|
|
|
const expected = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
cli.parse(argv, function (err, msg, opt) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(!err).toBeTruthy()
|
|
|
|
expect(opt.files.length).toBe(3)
|
|
|
|
expect(opt.files).toEqual(expected)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
done()
|
2014-12-20 17:40:58 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
test('defaults to png', function (done) {
|
|
|
|
expect.assertions(3)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
const argv = ['example/file1.mermaid']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
cli.parse(argv, function (err, msg, opt) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(!err).toBeTruthy()
|
|
|
|
expect(opt.png).toBeTruthy()
|
|
|
|
expect(opt.svg).toBeFalsy()
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
done()
|
2014-12-20 17:40:58 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
test('setting svg unsets png', function (done) {
|
|
|
|
expect.assertions(3)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
const argv = ['example/file1.mermaid', '-s']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
cli.parse(argv, function (err, msg, opt) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(!err).toBeTruthy()
|
|
|
|
expect(opt.svg).toBeTruthy()
|
|
|
|
expect(opt.png).toBeFalsy()
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
done()
|
2014-12-20 17:40:58 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
test('setting png and svg is allowed', function (done) {
|
|
|
|
expect.assertions(3)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
const argv = ['example/file1.mermaid', '-s', '-p']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
cli.parse(argv, function (err, msg, opt) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(!err).toBeTruthy()
|
|
|
|
expect(opt.png).toBeTruthy()
|
|
|
|
expect(opt.svg).toBeTruthy()
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
done()
|
2014-12-20 17:40:58 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
test('setting an output directory succeeds', function (done) {
|
|
|
|
expect.assertions(2)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
const argv = ['example/file1.mermaid', '-o', 'example/']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
cli.parse(argv, function (err, msg, opt) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(!err).toBeTruthy()
|
|
|
|
expect(opt.outputDir).toBe('example/')
|
|
|
|
done()
|
2014-12-20 17:40:58 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
test('not setting a css source file uses a default style', function (done) {
|
|
|
|
expect.assertions(2)
|
2015-09-15 19:22:07 +02:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
const argv = ['example/file1.mermaid']
|
2015-09-15 19:22:07 +02:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
cli.parse(argv, function (err, msg, opt) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(!err).toBeTruthy()
|
|
|
|
expect(opt.css).toBeTruthy()
|
|
|
|
done()
|
2015-09-15 19:22:07 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
test('setting a css source file succeeds', function (done) {
|
|
|
|
expect.assertions(2)
|
2015-02-02 19:02:45 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
const argv = ['example/file1.mermaid', '-t', 'test/fixtures/test.css']
|
2015-02-02 19:02:45 -08:00
|
|
|
|
2017-04-10 21:59:40 +08:00
|
|
|
cli.parse(argv, function (err, msg, opt) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(!err).toBeTruthy()
|
|
|
|
expect(opt.css).toBeTruthy()
|
|
|
|
done()
|
2015-02-02 19:02:45 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
test('setting an output directory incorrectly causes an error', function (done) {
|
|
|
|
expect.assertions(1)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-11 21:52:19 +08:00
|
|
|
const argv = ['-o']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-11 21:52:19 +08:00
|
|
|
cli.parse(argv, function (err) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(err).toBeTruthy()
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
done()
|
2014-12-20 17:40:58 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
test('a callback function is called after parsing', function (done) {
|
|
|
|
expect.assertions(3)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-11 21:52:19 +08:00
|
|
|
const argv = ['example/file1.mermaid']
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-04-11 21:52:19 +08:00
|
|
|
cli.parse(argv, function (err, msg, opts) {
|
2017-09-10 11:42:39 +08:00
|
|
|
expect(!err).toBeTruthy()
|
|
|
|
expect(true).toBeTruthy()
|
|
|
|
expect(argv).toEqual(opts.files)
|
2014-12-20 17:40:58 -08:00
|
|
|
|
2017-09-10 11:42:39 +08:00
|
|
|
done()
|
2014-12-20 17:40:58 -08:00
|
|
|
})
|
|
|
|
})
|