Skip to content

Commit 6448a4e

Browse files
committed
add tests
1 parent afb83f4 commit 6448a4e

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
node_modules/
55
yarn.lock
66
bin/
7+
test_docs/

e2e/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ test('rejects promise due to error on passing in an unknown command', async t =>
2525
const {stderr} = await execa(rootCommand, ['junkcmd'], {reject: false})
2626
t.snapshot(stderr)
2727
})
28+
29+
test('init the docs directory', async t => {
30+
const {stdout} = await execa(rootCommand, ['init', './test_docs'], {reject: false})
31+
t.snapshot(stdout)
32+
})
33+
34+
test('init the docs directory twice', async t => {
35+
const {stdout} = await execa(rootCommand, ['init', './test_docs'], {reject: false, input: 'n'})
36+
t.snapshot(stdout)
37+
})

e2e/index.js.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ 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+
`./test_docs already exists.␊
20+
? Are you sure you want to rewrite it? (Y/n) ? Are you sure you want to rewrite it? (Y/n) n? Are you sure you want to rewrite it? No`
21+
722
## rejects promise due to error on passing in an unknown command
823

924
> Snapshot 1

e2e/index.js.snap

169 Bytes
Binary file not shown.

lib/commands/init.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ module.exports = function (path = '', local, theme) {
1919
chalk.inverse(`docsify serve ${path}`) +
2020
'\n'
2121

22-
path = cwd(path || '.')
22+
const cwdPath = cwd(path || '.')
2323

24-
if (exists(path)) {
25-
console.log(chalk.red(`${path}`) + ' already exists.')
24+
if (exists(cwdPath)) {
25+
console.log(chalk.red(`${path || '.'}`) + ' already exists.')
2626

2727
inquirer
2828
.prompt([
@@ -38,14 +38,14 @@ module.exports = function (path = '', local, theme) {
3838
return process.exit(0)
3939
}
4040

41-
createFile(path, local, theme)
41+
createFile(cwdPath, local, theme)
4242
console.log(msg)
4343
})
4444

4545
return false
4646
}
4747

48-
createFile(path, local, theme)
48+
createFile(cwdPath, local, theme)
4949
console.log(msg)
5050
}
5151

0 commit comments

Comments
 (0)