Skip to content

Commit c2cc883

Browse files
test: improve test suite
1 parent 22fa72d commit c2cc883

File tree

7 files changed

+93
-4
lines changed

7 files changed

+93
-4
lines changed
File renamed without changes.

e2e/index.js.md renamed to e2e/cli.test.js.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Snapshot report for `e2e/index.js`
1+
# Snapshot report for `e2e/cli.test.js`
22

3-
The actual snapshot is saved in `index.js.snap`.
3+
The actual snapshot is saved in `cli.test.js.snap`.
44

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

File renamed without changes.

e2e/commands/init.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const test = require('ava')
2+
const fs = require('fs')
3+
4+
const {run, runPromptWithAnswers, ENTER} = require('../helpers/test-utils.js')
5+
6+
const genPath = `${__dirname}/init-cmd`
7+
const docsPath = `${__dirname}/init-cmd/docs`
8+
9+
test.before('create temp directory', () => {
10+
fs.mkdirSync(genPath)
11+
})
12+
13+
test.after('cleanup', () => {
14+
fs.rmdirSync(genPath, {recursive: true})
15+
})
16+
17+
test('generates docs directory', t => {
18+
run(['init', 'docs'], {cwd: genPath})
19+
// Check for existence
20+
t.true(fs.existsSync(`${docsPath}/README.md`))
21+
t.true(fs.existsSync(`${docsPath}/index.html`))
22+
})
23+
24+
test('force generates docs directory with --local flag', async t => {
25+
await runPromptWithAnswers(['init', 'docs', '--local'], ['y', ENTER], genPath)
26+
t.true(fs.existsSync(`${docsPath}/vendor`))
27+
})

e2e/helpers/test-utils.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
const execa = require('execa')
22
const path = require('path')
3+
const runTest = require('cli-prompts-test')
4+
5+
const ENTER = '\x0D'
36

47
const CLI_PATH = path.join(__dirname, '..', '..', 'bin', 'docsify')
58

69
const run = (args, options = {}) => execa.sync(CLI_PATH, args, options)
710

11+
const runPromptWithAnswers = (args, answers, testPath) => {
12+
return runTest([CLI_PATH].concat(args), answers, {
13+
testPath
14+
})
15+
}
16+
817
module.exports = {
9-
run
18+
run,
19+
runPromptWithAnswers,
20+
ENTER
1021
}

package-lock.json

+50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"lint": "eslint .",
2626
"lint:fix": "eslint . --fix",
2727
"pretest": "npm run lint",
28-
"test": "ava e2e/index.js",
28+
"test": "ava e2e/*.test.js e2e/commands/*.test.js",
2929
"prebuild": "rimraf bin",
3030
"build": "rollup -c",
3131
"prerelease": "npm run build",
@@ -67,6 +67,7 @@
6767
},
6868
"devDependencies": {
6969
"ava": "^2.4.0",
70+
"cli-prompts-test": "^0.1.1",
7071
"cors": "^2.8.1",
7172
"eslint": "^6.8.0",
7273
"eslint-config-xo-space": "^0.22.0",

0 commit comments

Comments
 (0)