Replace tape with jest

This commit is contained in:
Tyler Long
2017-09-10 11:42:39 +08:00
parent a5b7145527
commit 2d91daf858
5 changed files with 927 additions and 262 deletions

View File

@@ -22,8 +22,8 @@
"upgrade": "yarn upgrade --latest && yarn remove d3 && yarn add d3@3.5.17",
"lint": "standard",
"karma": "node -r babel-register node_modules/.bin/karma start karma.conf.js --single-run",
"tape": "node -r babel-register node_modules/.bin/tape test/cli_test-*.js",
"test": "yarn lint && yarn tape && yarn karma",
"jest": "jest --coverage",
"test": "yarn lint && yarn jest && yarn karma",
"jison": "gulp jison",
"prepublishOnly": "yarn build && yarn release && yarn test"
},
@@ -69,6 +69,7 @@
"inject-loader": "^3.0.1",
"jasmine": "^2.8.0",
"jasmine-es6": "^0.4.1",
"jest": "^21.0.2",
"jison": "^0.4.18",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
@@ -80,7 +81,6 @@
"rimraf": "^2.6.1",
"standard": "^10.0.3",
"style-loader": "^0.18.2",
"tape": "^4.8.0",
"webpack": "^3.5.6",
"webpack-node-externals": "^1.6.0"
},
@@ -89,5 +89,8 @@
"dist",
"lib",
"src"
]
],
"jest": {
"testRegex": "test/cli_test-.+?\\.js"
}
}

View File

@@ -1,7 +1,8 @@
/* eslint-env jest */
/* eslint-env jasmine */
const fs = require('fs')
const path = require('path')
const test = require('tape')
const async = require('async')
const clone = require('clone')
const rimraf = require('rimraf')
@@ -39,8 +40,12 @@ const multiFile = {
ganttConfig: null
}
test('output of single png', function (t) {
t.plan(3)
beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000
})
test('output of single png', function (done) {
expect.assertions(3)
const expected = ['test.mermaid.png']
@@ -49,14 +54,14 @@ test('output of single png', function (t) {
opt.png = true
mermaid.process(opt.files, opt, function (code) {
t.equal(code, 0, 'has clean exit code')
expect(code).toBe(0)
verifyFiles(expected, opt.outputDir, t)
verifyFiles(expected, opt.outputDir, done)
})
})
test('output of multiple png', function (t) {
t.plan(3)
test('output of multiple png', function (done) {
expect.assertions(3)
const expected = ['test.mermaid.png', 'test2.mermaid.png',
'gantt.mermaid.png', 'sequence.mermaid.png']
@@ -66,14 +71,14 @@ test('output of multiple png', function (t) {
opt.png = true
mermaid.process(opt.files, opt, function (code) {
t.equal(code, 0, 'has clean exit code')
expect(code).toBe(0)
verifyFiles(expected, opt.outputDir, t)
verifyFiles(expected, opt.outputDir, done)
})
})
test('output of single svg', function (t) {
t.plan(3)
test('output of single svg', function (done) {
expect.assertions(3)
const expected = ['test.mermaid.svg']
@@ -82,14 +87,14 @@ test('output of single svg', function (t) {
opt.svg = true
mermaid.process(opt.files, opt, function (code) {
t.equal(code, 0, 'has clean exit code')
expect(code).toBe(0)
verifyFiles(expected, opt.outputDir, t)
verifyFiles(expected, opt.outputDir, done)
})
})
test('output of multiple svg', function (t) {
t.plan(3)
test('output of multiple svg', function (done) {
expect.assertions(3)
const expected = ['test.mermaid.svg', 'test2.mermaid.svg',
'gantt.mermaid.svg', 'sequence.mermaid.svg']
@@ -99,14 +104,14 @@ test('output of multiple svg', function (t) {
opt.svg = true
mermaid.process(opt.files, opt, function (code) {
t.equal(code, 0, 'has clean exit code')
expect(code).toBe(0)
verifyFiles(expected, opt.outputDir, t)
verifyFiles(expected, opt.outputDir, done)
})
})
test('output including CSS', function (t) {
t.plan(5)
test('output including CSS', function (done) {
expect.assertions(5)
const expected = ['test.mermaid.png']
const opt = clone(singleFile)
@@ -118,23 +123,23 @@ test('output including CSS', function (t) {
opt2.outputDir += '_css_png'
mermaid.process(opt.files, opt, function (code) {
t.equal(code, 0, 'has clean exit code')
expect(code).toBe(0)
const filename = path.join(opt.outputDir, path.basename(expected[0]))
const one = fs.statSync(filename)
opt2.css = path.join('test', 'fixtures', 'test.css')
mermaid.process(opt2.files, opt2, function (code) {
t.equal(code, 0, 'has clean exit code')
expect(code).toBe(0)
const two = fs.statSync(filename)
t.notEqual(one.size, two.size)
expect(one.size).not.toBe(two.size)
verifyFiles(expected, opt.outputDir, t)
verifyFiles(expected, opt.outputDir, done)
})
})
})
function verifyFiles (expected, dir, t) {
function verifyFiles (expected, dir, done) {
async.each(
expected, function (file, cb) {
const filename = path.join(dir, path.basename(file))
@@ -142,12 +147,12 @@ function verifyFiles (expected, dir, t) {
cb(err)
})
}, function (err) {
t.notOk(err, 'all files passed')
expect(err).toBeFalsy()
const deleteTmps = true
const _rimraf = deleteTmps ? rimraf : function (dir, f) { f(0) }
_rimraf(dir, function (rmerr) {
t.notOk(rmerr, 'cleaned up')
t.end()
expect(rmerr).toBeFalsy()
done()
})
}
)

View File

@@ -1,131 +1,135 @@
const test = require('tape')
/* eslint-env jest */
/* eslint-env jasmine */
const cliPath = '../lib/cli'
test('parses multiple files', function (t) {
t.plan(3)
beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000
})
test('parses multiple files', function (done) {
expect.assertions(3)
const cli = require(cliPath)
const argv = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
const expect = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
const expected = ['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')
expect(!err).toBeTruthy()
expect(opt.files.length).toBe(3)
expect(opt.files).toEqual(expected)
t.end()
done()
})
})
test('defaults to png', function (t) {
t.plan(3)
test('defaults to png', function (done) {
expect.assertions(3)
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')
expect(!err).toBeTruthy()
expect(opt.png).toBeTruthy()
expect(opt.svg).toBeFalsy()
t.end()
done()
})
})
test('setting svg unsets png', function (t) {
t.plan(3)
test('setting svg unsets png', function (done) {
expect.assertions(3)
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')
expect(!err).toBeTruthy()
expect(opt.svg).toBeTruthy()
expect(opt.png).toBeFalsy()
t.end()
done()
})
})
test('setting png and svg is allowed', function (t) {
t.plan(3)
test('setting png and svg is allowed', function (done) {
expect.assertions(3)
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')
expect(!err).toBeTruthy()
expect(opt.png).toBeTruthy()
expect(opt.svg).toBeTruthy()
t.end()
done()
})
})
test('setting an output directory succeeds', function (t) {
t.plan(2)
test('setting an output directory succeeds', function (done) {
expect.assertions(2)
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()
expect(!err).toBeTruthy()
expect(opt.outputDir).toBe('example/')
done()
})
})
test('not setting a css source file uses a default style', function (t) {
t.plan(2)
test('not setting a css source file uses a default style', function (done) {
expect.assertions(2)
const cli = require(cliPath)
const argv = ['example/file1.mermaid']
cli.parse(argv, function (err, msg, opt) {
t.ok(!err, 'no err')
t.ok(opt.css, 'css file is populated')
t.end()
expect(!err).toBeTruthy()
expect(opt.css).toBeTruthy()
done()
})
})
test('setting a css source file succeeds', function (t) {
t.plan(2)
test('setting a css source file succeeds', function (done) {
expect.assertions(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()
expect(!err).toBeTruthy()
expect(opt.css).toBeTruthy()
done()
})
})
test('setting an output directory incorrectly causes an error', function (t) {
t.plan(1)
test('setting an output directory incorrectly causes an error', function (done) {
expect.assertions(1)
const cli = require(cliPath)
const argv = ['-o']
cli.parse(argv, function (err) {
t.ok(err, 'an error is raised')
expect(err).toBeTruthy()
t.end()
done()
})
})
test('a callback function is called after parsing', function (t) {
t.plan(3)
test('a callback function is called after parsing', function (done) {
expect.assertions(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')
expect(!err).toBeTruthy()
expect(true).toBeTruthy()
expect(argv).toEqual(opts.files)
t.end()
done()
})
})

View File

@@ -1,7 +1,8 @@
/* eslint-env jest */
/* eslint-env jasmine */
const exec = require('child_process').exec
const path = require('path')
const test = require('tape')
const rimraf = require('rimraf')
const localSearchPath = './node_modules/.bin' + path.delimiter + process.env.PATH
@@ -36,107 +37,103 @@ function execCmd (cmd, verify) {
})
}
function verifyNoError (t) {
function verifyNoError (done) {
return function (error, stdout, stderr) {
t.ok(!error, 'no error')
t.notOk(stderr, 'no stderr')
t.end()
expect(!error).toBeTruthy()
expect(stderr).toBeFalsy()
done()
}
}
function verifyError (t) {
function verifyError (done) {
return function (error, stdout, stderr) {
t.ok(!error, 'no error')
t.ok(stderr, 'should get stderr')
t.end()
expect(!error).toBeTruthy()
expect(stderr).toBeTruthy()
done()
}
}
test('mermaid cli help', function (t) {
t.plan(2)
beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000
})
test('mermaid cli help', function (done) {
expect.assertions(2)
const args = ['--help']
execMermaid(args.join(' '), verifyNoError(t))
execMermaid(args.join(' '), verifyNoError(done))
})
test('mermaid cli help', function (t) {
t.plan(2)
test('mermaid cli help', function (done) {
expect.assertions(2)
const args = ['--badopt']
execMermaid(args.join(' '), verifyError(t))
})
test.skip('sequence syntax error', function (t) {
t.plan(2)
const args = ['--svg',
testDir + 'sequence_err.mmd'
]
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
execMermaid(args.join(' '), verifyError(done))
});
['', 'fo', 'tspan', 'old'].forEach(function (textPlacement) {
test('sequence svg text placement: ' + textPlacement, function (t) {
t.plan(2)
test('sequence svg text placement: ' + textPlacement, function (done) {
expect.assertions(2)
const args = ['--svg',
'--outputDir=' + testDir,
'--outputSuffix=' + (textPlacement ? '_' + textPlacement : '') + '.actual',
textPlacement ? '--sequenceConfig=' + testDir + 'sequence_text_' + textPlacement + '.cfg' : '',
testDir + 'sequence_text.mmd'
]
execMermaid(args.join(' '), verifyNoError(t))
execMermaid(args.join(' '), verifyNoError(done))
})
})
test('sequence png', function (t) {
t.plan(2)
test('sequence png', function (done) {
expect.assertions(2)
const args = ['--png',
testDir + 'sequence_text.mmd'
]
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(done))
})
test('flowchart svg text', function (t) {
t.plan(2)
test('flowchart svg text', function (done) {
expect.assertions(2)
const args = ['--svg',
'--css=dist/mermaid.css',
'--width=500',
testDir + 'flowchart_text.mmd'
]
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(done))
});
['svg', 'png'].forEach(function (format) {
test('flowchart ' + format + 'text2', function (t) {
t.plan(2)
test('flowchart ' + format + 'text2', function (done) {
expect.assertions(2)
const args = ['--' + format,
'--css=dist/mermaid.forest.css',
'--width=500',
testDir + 'flowchart_text2.mmd'
]
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(done))
})
})
test('gantt axis formatter svg', function (t) {
t.plan(2)
test('gantt axis formatter svg', function (done) {
expect.assertions(2)
const args = ['--svg',
'--css=dist/mermaid.css',
'--width=500',
'--ganttConfig=' + testDir + 'gantt_axis_formatter.cfg',
testDir + 'gantt_axis_formatter.mmd'
]
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(done))
})
test('gitgraph sample svg', function (t) {
t.plan(2)
test('gitgraph sample svg', function (done) {
expect.assertions(2)
const args = ['-s', '-v',
'--width=500',
testDir + 'gitgraph.mmd'
]
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(t))
execMermaid(prependOutputArgs(args.join(' ')), verifyNoError(done))
})
test('load sample.html in phantomjs and save screenshot png', function (t) {
t.plan(2)
test('load sample.html in phantomjs and save screenshot png', function (done) {
expect.assertions(2)
execPhantomjsToLoadHtmlSaveScreenshotPng(testDir + 'samples.html',
verifyNoError(t))
verifyNoError(done))
})

926
yarn.lock

File diff suppressed because it is too large Load Diff