Skip to content

Commit 22fa72d

Browse files
test: add helpers
1 parent f811906 commit 22fa72d

File tree

4 files changed

+17
-36
lines changed

4 files changed

+17
-36
lines changed

e2e/helpers/test-utils.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const execa = require('execa')
2+
const path = require('path')
3+
4+
const CLI_PATH = path.join(__dirname, '..', '..', 'bin', 'docsify')
5+
6+
const run = (args, options = {}) => execa.sync(CLI_PATH, args, options)
7+
8+
module.exports = {
9+
run
10+
}

e2e/index.js

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
'use strict'
22

3-
const path = require('path')
4-
const execa = require('execa')
53
const test = require('ava')
64

7-
const rootCommand = path.join(process.cwd(), 'bin/docsify')
5+
const {run} = require('./helpers/test-utils.js')
86

9-
test('shows up help message without any args', async t => {
10-
const {stderr} = await execa(rootCommand, {reject: false})
7+
test('shows up help message without any args', t => {
8+
const {stderr} = run([], {reject: false})
119
t.snapshot(stderr)
1210
})
1311

14-
const matchSnapshot = async (t, arg) => {
15-
const {stdout} = await execa(rootCommand, [arg])
12+
const matchSnapshot = (t, arg) => {
13+
const {stdout} = run([arg])
1614
t.snapshot(stdout)
1715
}
1816

@@ -21,18 +19,7 @@ test('shows help with --help flag', matchSnapshot, '--help')
2119
test('shows version information with -v flag', matchSnapshot, '-v')
2220
test('shows version information with --version flag', matchSnapshot, '--version')
2321

24-
test('rejects promise due to error on passing in an unknown command', async t => {
25-
const {stderr} = await execa(rootCommand, ['junkcmd'], {reject: false})
22+
test('rejects promise due to error on passing in an unknown command', t => {
23+
const {stderr} = run(['junkcmd'], {reject: false})
2624
t.snapshot(stderr)
2725
})
28-
29-
test('init the docs directory', async t => {
30-
// If you get `./test_docs already exists.`, delete the test_docs directory manually.
31-
const {stdout} = await execa(rootCommand, ['init', './test_docs'], {reject: false, timeout: 3000})
32-
t.snapshot(stdout)
33-
})
34-
35-
test('init the docs directory twice', async t => {
36-
const {stdout} = await execa(rootCommand, ['init', './'], {reject: false, input: 'n'})
37-
t.snapshot(stdout)
38-
})

e2e/index.js.md

-16
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@ The actual snapshot is saved in `index.js.snap`.
44

55
Generated by [AVA](https://ava.li).
66

7-
## init the docs directory
8-
9-
> Snapshot 1
10-
11-
`␊
12-
Initialization succeeded! Please run docsify serve ./test_docs␊
13-
`
14-
15-
## init the docs directory twice
16-
17-
> Snapshot 1
18-
19-
`./ already exists.␊
20-
[?25l? Are you sure you want to rewrite it? (y/N) false✔ Are you sure you want to rewrite it? (y/N) false␊
21-
[?25h`
22-
237
## rejects promise due to error on passing in an unknown command
248

259
> Snapshot 1

e2e/index.js.snap

-193 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)