Skip to content

Commit

Permalink
Add an inlined fixture test
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Oct 19, 2015
1 parent e035056 commit 833a5e7
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
27 changes: 24 additions & 3 deletions index.js
Expand Up @@ -24,6 +24,7 @@ module.exports = function base (options) {
var app = ware()
.use(reset.bind(ctx))
.use(sortCss.bind(ctx))
.use(sortJs.bind(ctx))
.use(addJs.bind(ctx))
.use(addCss.bind(ctx))
.use(relayout.bind(ctx))
Expand Down Expand Up @@ -54,16 +55,36 @@ function sortCss (files, ms, done) {
this.stylusImports.push(path)
} else if (item.match(/^https?:\/\//)) {
this.styles.push(item)
} else if (sources[item]) {
this.styles.push(sources[item])
} else if (files[item]) {
this.styles.push(item)
} else {
const local = sources[item]
if (!local) throw new Error(`css: can't find '#{item}'`)
this.styles.push(local)
throw new Error(`css: can't find '#{item}'`)
}
})

done()
}

function sortJs (files, ms, done) {
const list = toArray(ms.metadata().js)
const sources = files['_docpress.json'].sources

list.forEach((item) => {
if (item.match(/^https?:\/\//)) {
this.scripts.push(item)
} else if (sources[item]) {
this.scripts.push(sources[item])
} else if (files[item]) {
this.scripts.push(item)
} else {
throw new Error(`js: can't find '#{item}'`)
}
})
done()
}

/**
* Assets
*/
Expand Down
60 changes: 60 additions & 0 deletions test/index/basic_test.js
@@ -0,0 +1,60 @@
const compile = require('../../')()

describe('index/basic:', function () {
beforeEach(function (done) {
// Mock metalsmith object
var ms = {
directory () { return __dirname },
metadata () { return { docs: 'docs' } }
}

this.files = {
'docs/README.md': {
contents:
'* [My project](../README.md)\n' +
'* [Intro](intro.md)\n'
},
'README.md': {
contents:
'# My project\nHello.\n\n' +
'### Usage\n' +
'Use it wisely'
},
'docs/intro.md': {
contents: '# Introduction\n'
}
}

require('docpress-core')()(this.files, ms, (err) => {
if (err) throw err
compile(this.files, ms, (err) => {
if (err) throw err
done()
})
})
})

it('works', function () {
expect(this.files['index.html']).toExist()
})

describe('index.html', function () {
beforeEach(function () {
this.contents = this.files['index.html'].contents
})

it('renders markdown', function () {
expect(this.contents).toInclude('<h1 id="my-project">')
})

it('renders styles', function () {
expect(this.contents)
.toMatch(/assets\/style.css\?t=[a-f0-9]{8}/)
})

it('renders scripts', function () {
expect(this.contents)
.toMatch(/assets\/script.js\?t=[a-f0-9]{8}/)
})
})
})

0 comments on commit 833a5e7

Please sign in to comment.