Skip to content

Commit 26ec4ea

Browse files
committed
Test toc-less cases
1 parent 5c5fbff commit 26ec4ea

File tree

6 files changed

+40
-15
lines changed

6 files changed

+40
-15
lines changed

fixture/onmount/metalsmith.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
var bookdown = require('../../ms')
1+
/* istanbul ignore next */
2+
(function() {
3+
var bookdown = require('../../ms')
24

3-
var app = bookdown(__dirname)
4-
.use(require('../../')())
5+
var app = bookdown(__dirname)
6+
.use(require('../../')())
57

6-
if (module.parent) {
7-
module.exports = app
8-
} else {
9-
app.build(function (err) { if (err) throw err })
10-
}
8+
if (module.parent) {
9+
module.exports = app
10+
} else {
11+
app.build(function (err) { if (err) throw err })
12+
}
13+
}())

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function buildIndex (files, ms, done) {
3636
var docs = ms.metadata().docs || 'docs'
3737

3838
if (!files[`${docs}/README.md`]) {
39-
var err = new Error(`Table of contents ('${docs}/README.md'}') found`)
39+
var err = new Error(`Table of contents not found ('${docs}/README.md')`)
4040
return done(err)
4141
}
4242

test/basic_test.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/index_test.js renamed to test/index/index_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const compile = require('../index')()
1+
const compile = require('../../index')()
22

33
describe('compile', function () {
44
beforeEach(function (done) {

test/index/tocless_test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const compile = require('../../index')()
2+
3+
describe('compile: toc-less', function () {
4+
beforeEach(function (done) {
5+
// Mock metalsmith object
6+
this.ms = {
7+
metadata () {
8+
return { docs: 'docs' }
9+
}
10+
}
11+
12+
this.files = {
13+
'README.md': { contents: '# hello\n' }
14+
}
15+
16+
compile(this.files, this.ms, (err) => {
17+
this.err = err
18+
done()
19+
})
20+
})
21+
22+
it('fails', function () {
23+
expect(this.err).toExist()
24+
expect(this.err.message).toMatch(/not found/)
25+
})
26+
})

test/mocha.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
--recursive
12
--require mocha-clean/brief
23
--require test/setup

0 commit comments

Comments
 (0)