Skip to content

Commit 2e474b3

Browse files
committed
Add test for log output
1 parent 6f05127 commit 2e474b3

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ node_modules
1515
npm-debug.log
1616
samples
1717
tmp_samples
18+
!test/fixtures/*.log

doctoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ for (var i = 0; i < argv._.length; i++) {
136136
, stat = fs.statSync(target);
137137

138138
if (stat.isDirectory() && stdOut){
139-
console.log('StdOut can not be used on a directory. Using dryrun instead.')
139+
console.log('StdOut can not be used on a directory. Using dryrun instead.');
140140
stdOut = false;
141141
dryRun = true;
142142
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Hello, world!
2+
3+
README to test doctoc with user-specified titles.
4+
5+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
6+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
7+
## Table of Contents
8+
9+
- [Installation](#installation)
10+
- [API](#api)
11+
- [License](#license)
12+
13+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
14+
15+
16+
## Installation
17+
## API
18+
## License
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
StdOut can not be used on a directory. Using dryrun instead.
2+
3+
DocToccing "test/fixtures/invalid_stdout" and its sub directories for github.com.
4+
5+
Found readme.md in "test/fixtures/invalid_stdout"
6+
7+
==================
8+
9+
"test/fixtures/invalid_stdout/readme.md" is up to date
10+
11+
Everything is OK.

test/transform-stdout.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('\nshould print to stdout with --stdout option', function (t) {
1313
return;
1414
}
1515
t.deepEqual(stdout
16-
, fs.readFileSync(__dirname + '/fixtures/stdout.md', 'utf8')
16+
, fs.readFileSync(__dirname + '/fixtures/stdout.log', 'utf8')
1717
, 'spits out the correct table of contents')
1818

1919
t.end()
@@ -28,9 +28,24 @@ test('\nshould print to stdout with -s option', function (t) {
2828
return;
2929
}
3030
t.deepEqual(stdout
31-
, fs.readFileSync(__dirname + '/fixtures/stdout.md', 'utf8')
31+
, fs.readFileSync(__dirname + '/fixtures/stdout.log', 'utf8')
3232
, 'spits out the correct table of contents')
3333

3434
t.end()
3535
})
3636
})
37+
38+
test('\nshould be a dry run even though the --stdout option provided due to being a directory', function (t) {
39+
40+
exec('node doctoc.js test/fixtures/invalid_stdout --stdout', function (error, stdout, stderr) {
41+
if (error) {
42+
console.error('exec error: ', error);
43+
return;
44+
}
45+
t.deepEqual(stdout
46+
, fs.readFileSync(__dirname + '/fixtures/stdout_run_on_directory.log', 'utf8')
47+
, 'spits out the correct logs for stdout on directory')
48+
49+
t.end()
50+
})
51+
})

0 commit comments

Comments
 (0)