1 | 'use strict'
|
2 | const describe = require('mocha').describe
|
3 | const it = require('mocha').it
|
4 | const expect = require('chai').expect
|
5 | const execa = require('execa')
|
6 | const pkg = require('../package.json')
|
7 | const path = require('path')
|
8 | const cli = path.resolve(__dirname, './cli.js')
|
9 | const testcwd = path.resolve(__dirname, 'test-cli')
|
10 |
|
11 | describe('cli', () => {
|
12 | it('show version', () => {
|
13 | return execa(cli, ['--version'])
|
14 | .then(result => expect(result.stdout).to.eq(pkg.version))
|
15 | })
|
16 |
|
17 | it('show version, shortcut', () => {
|
18 | return execa(cli, ['-v'])
|
19 | .then(result => expect(result.stdout).to.eq(pkg.version))
|
20 | })
|
21 |
|
22 | describe('test', () => {
|
23 | it('should pass markdown that is up to date', () => {
|
24 | return execa(cli, ['test', 'up-to-date.md', '--tap'], {
|
25 | cwd: testcwd,
|
26 | })
|
27 | .then(result => expect(result.stdout).to.eq([
|
28 | 'TAP version 13',
|
29 | '# markdown',
|
30 | 'ok 1 up-to-date.md',
|
31 | '',
|
32 | '1..1',
|
33 | '# tests 1',
|
34 | '# pass 1',
|
35 | '',
|
36 | '# ok',
|
37 | '',
|
38 | ].join('\n')))
|
39 | })
|
40 |
|
41 | it('should fail markdown that is not up to date', () => {
|
42 | return execa(cli, ['test', 'not-up-to-date.md', '--tap'], {
|
43 | cwd: testcwd,
|
44 | })
|
45 | .catch(result => {
|
46 | expect(result.stdout).to.have.string([
|
47 | 'TAP version 13',
|
48 | '# markdown',
|
49 | 'not ok 1 not-up-to-date.md',
|
50 | ' ---',
|
51 | ' operator: equal',
|
52 | ' expected: |-',
|
53 | " '<!--@\\'# \\' + pkg.name-->\\n# Bad title\\n<!--/@-->\\n\\nContent\\n'",
|
54 | ' actual: |-',
|
55 | " '<!--@\\'# \\' + pkg.name-->\\n# slipsum-lite\\n<!--/@-->\\n\\nContent\\n'",
|
56 | ].join('\n'))
|
57 |
|
58 | expect(result.stdout).to.have.string([
|
59 | ' ...',
|
60 | '',
|
61 | '1..1',
|
62 | '# tests 1',
|
63 | '# pass 0',
|
64 | '# fail 1\n\n',
|
65 | ].join('\n'))
|
66 | })
|
67 | })
|
68 | })
|
69 | })
|