Change cli_test-parser.js to ES6

This commit is contained in:
Tyler Long 2017-04-10 21:59:40 +08:00
parent 69ceab9f44
commit c1e5fe3281
1 changed files with 78 additions and 70 deletions

View File

@ -1,14 +1,16 @@
var test = require('tape')
, cliPath = '../lib/cli'
const test = require('tape')
test('parses multiple files', function(t) {
t.plan(2)
const cliPath = '../lib/cli'
var cli = require(cliPath)
, argv = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
, expect = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
test('parses multiple files', function (t) {
t.plan(3)
cli.parse(argv, function(err, msg, opt) {
const cli = require(cliPath)
const argv = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
const expect = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
cli.parse(argv, function (err, msg, opt) {
t.ok(!err, 'no err')
t.equal(opt.files.length, 3, 'should have 3 parameters')
t.deepEqual(opt.files, expect, 'should match expected values')
@ -16,13 +18,14 @@ test('parses multiple files', function(t) {
})
})
test('defaults to png', function(t) {
t.plan(2)
test('defaults to png', function (t) {
t.plan(3)
var cli = require(cliPath)
, argv = ['example/file1.mermaid']
const cli = require(cliPath)
const argv = ['example/file1.mermaid']
cli.parse(argv, function(err, msg, opt) {
cli.parse(argv, function (err, msg, opt) {
t.ok(!err, 'no err')
t.ok(opt.png, 'png is set by default')
t.notOk(opt.svg, 'svg is not set by default')
@ -30,14 +33,14 @@ test('defaults to png', function(t) {
})
})
test('setting svg unsets png', function(t) {
t.plan(2)
test('setting svg unsets png', function (t) {
t.plan(3)
var cli = require(cliPath)
, argv = ['example/file1.mermaid', '-s']
cli.parse(argv, function(err, msg, opt) {
const cli = require(cliPath)
const argv = ['example/file1.mermaid', '-s']
cli.parse(argv, function (err, msg, opt) {
t.ok(!err, 'no err')
t.ok(opt.svg, 'svg is set when requested')
t.notOk(opt.png, 'png is unset when svg is set')
@ -45,13 +48,14 @@ test('setting svg unsets png', function(t) {
})
})
test('setting png and svg is allowed', function(t) {
t.plan(2)
test('setting png and svg is allowed', function (t) {
t.plan(3)
var cli = require(cliPath)
, argv = ['example/file1.mermaid', '-s', '-p']
const cli = require(cliPath)
const argv = ['example/file1.mermaid', '-s', '-p']
cli.parse(argv, function(err, msg, opt) {
cli.parse(argv, function (err, msg, opt) {
t.ok(!err, 'no err')
t.ok(opt.png, 'png is set when requested')
t.ok(opt.svg, 'svg is set when requested')
@ -59,65 +63,69 @@ test('setting png and svg is allowed', function(t) {
})
})
test('setting an output directory succeeds', function(t) {
t.plan(1)
test('setting an output directory succeeds', function (t) {
t.plan(2)
var cli = require(cliPath)
, argv = ['-o', 'example/']
const cli = require(cliPath)
const argv = ['example/file1.mermaid', '-o', 'example/']
cli.parse(argv, function(err, msg, opt) {
cli.parse(argv, function (err, msg, opt) {
t.ok(!err, 'no err')
t.equal(opt.outputDir, 'example/', 'output directory is set')
t.end()
})
})
test('not setting a css source file uses a default style', function(t) {
t.plan(1)
var cli = require(cliPath)
cli.parse([], function(err, msg, opt) {
t.ok(opt.css, 'css file is populated')
t.end()
})
})
test('setting a css source file succeeds', function(t) {
t.plan(1)
var cli = require(cliPath)
, argv = ['-t', 'test/fixtures/test.css']
cli.parse(argv, function(err, msg, opt) {
t.ok(opt.css, 'css file is populated')
t.end()
})
})
test('setting an output directory incorrectly causes an error', function(t) {
t.plan(1)
var cli = require(cliPath)
, argv = ['-o']
cli.parse(argv, function(err) {
t.ok(err, 'an error is raised')
t.end()
})
})
test('a callback function is called after parsing', function(t) {
test('not setting a css source file uses a default style', function (t) {
t.plan(2)
var cli = require(cliPath)
, argv = ['example/test.mermaid']
, expects = ['example/test.mermaid']
const cli = require(cliPath)
const argv = ['example/file1.mermaid']
cli.parse(argv, function(err, msg, opts) {
cli.parse(argv, function (err, msg, opt) {
t.ok(!err, 'no err')
t.ok(opt.css, 'css file is populated')
t.end()
})
})
test('setting a css source file succeeds', function (t) {
t.plan(2)
const cli = require(cliPath)
const argv = ['example/file1.mermaid', '-t', 'test/fixtures/test.css']
cli.parse(argv, function (err, msg, opt) {
t.ok(!err, 'no err')
t.ok(opt.css, 'css file is populated')
t.end()
})
})
test('a callback function is called after parsing', function (t) {
t.plan(3)
const cli = require(cliPath)
const argv = ['example/file1.mermaid']
cli.parse(argv, function (err, msg, opts) {
t.ok(!err, 'no err')
t.ok(true, 'callback was called')
t.deepEqual(argv, opts.files, 'options are as expected')
t.end()
})
})
test('setting an output directory incorrectly causes an error', function (t) {
t.plan(1)
const cli = require(cliPath)
const argv = ['-o']
cli.parse(argv, function (err) {
t.ok(err, 'an error is raised')
t.end()
})
})