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

View File

@@ -1,14 +1,16 @@
var test = require('tape')
, cliPath = '../lib/cli'
const test = require('tape')
const cliPath = '../lib/cli'
test('parses multiple files', function (t) {
t.plan(2)
t.plan(3)
var cli = require(cliPath)
, argv = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
, expect = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
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')
@@ -17,12 +19,13 @@ test('parses multiple files', function(t) {
})
test('defaults to png', function (t) {
t.plan(2)
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) {
t.ok(!err, 'no err')
t.ok(opt.png, 'png is set by default')
t.notOk(opt.svg, 'svg is not set by default')
@@ -31,13 +34,13 @@ test('defaults to png', function(t) {
})
test('setting svg unsets png', function (t) {
t.plan(2)
t.plan(3)
var cli = require(cliPath)
, argv = ['example/file1.mermaid', '-s']
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')
@@ -46,12 +49,13 @@ test('setting svg unsets png', function(t) {
})
test('setting png and svg is allowed', function (t) {
t.plan(2)
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) {
t.ok(!err, 'no err')
t.ok(opt.png, 'png is set when requested')
t.ok(opt.svg, 'svg is set when requested')
@@ -60,45 +64,64 @@ test('setting png and svg is allowed', function(t) {
})
test('setting an output directory succeeds', function (t) {
t.plan(1)
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) {
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)
t.plan(2)
var cli = require(cliPath)
const cli = require(cliPath)
const argv = ['example/file1.mermaid']
cli.parse([], function(err, msg, opt) {
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(1)
t.plan(2)
var cli = require(cliPath)
, argv = ['-t', 'test/fixtures/test.css']
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)
var cli = require(cliPath)
, argv = ['-o']
const cli = require(cliPath)
const argv = ['-o']
cli.parse(argv, function (err) {
t.ok(err, 'an error is raised')
@@ -106,18 +129,3 @@ test('setting an output directory incorrectly causes an error', function(t) {
t.end()
})
})
test('a callback function is called after parsing', function(t) {
t.plan(2)
var cli = require(cliPath)
, argv = ['example/test.mermaid']
, expects = ['example/test.mermaid']
cli.parse(argv, function(err, msg, opts) {
t.ok(true, 'callback was called')
t.deepEqual(argv, opts.files, 'options are as expected')
t.end()
})
})