UNPKG

2.92 kBJavaScriptView Raw
1'use strict'
2const describe = require('mocha').describe
3const it = require('mocha').it
4const expect = require('chai').expect
5const execa = require('execa')
6const pkg = require('../package.json')
7const path = require('path')
8const cli = path.resolve(__dirname, '../bin/mos.js')
9const testcwd = path.resolve(__dirname, 'test-cli')
10
11describe('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 it('should use custom options for third-party plugins', () => {
70 return execa(cli, ['test', 'plugin-options.md', '--tap'], {
71 cwd: testcwd,
72 })
73 .then(result => expect(result.stdout).to.eq([
74 'TAP version 13',
75 '# markdown',
76 'ok 1 plugin-options.md',
77 '',
78 '1..1',
79 '# tests 1',
80 '# pass 1',
81 '',
82 '# ok',
83 '',
84 ].join('\n')))
85 })
86
87 it('should disable default plugin', () => {
88 return execa(cli, ['test', 'disable-default-plugin.md', '--tap'], {
89 cwd: testcwd,
90 })
91 .then(result => expect(result.stdout).to.eq([
92 'TAP version 13',
93 '# markdown',
94 'ok 1 disable-default-plugin.md',
95 '',
96 '1..1',
97 '# tests 1',
98 '# pass 1',
99 '',
100 '# ok',
101 '',
102 ].join('\n')))
103 })
104 })
105})