Skip to content

Commit

Permalink
Test custom CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Oct 4, 2015
1 parent de465a0 commit 1422a04
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions fixture/onmount/docs/assets/script.js
@@ -0,0 +1 @@
/* custom */
4 changes: 4 additions & 0 deletions fixture/onmount/docs/assets/style.css
@@ -1,3 +1,7 @@
.custom-css {
font-family: 'fira sans';
}

.markdown-body h1 {
font-size: 3em;
font-weight: 300;
Expand Down
1 change: 0 additions & 1 deletion index.js
Expand Up @@ -34,7 +34,6 @@ function addCss (files, ms, done) {
if (!files['assets/style.css']) {
files['assets/style.css'] = { contents }
} else {
console.log('custom')
files['assets/style.css'].contents = contents + '\n' +
files['assets/style.css'].contents
}
Expand Down
18 changes: 13 additions & 5 deletions test/fixture_test.js
Expand Up @@ -4,9 +4,10 @@ const fixture = require('./support/fixture')

describe('fixture', function () {
let app, data
let fx = fixture('onmount')

before(function (done) {
app = require(fixture('onmount/metalsmith.js'))
app = require(fx.path('metalsmith.js'))
app.build((err) => {
if (err) return done(err)
done()
Expand All @@ -15,7 +16,7 @@ describe('fixture', function () {

describe('index.html', function () {
before(function () {
data = fixture.file('onmount/_bookdown/index.html')
data = fx.read('_bookdown/index.html')
})

it('renders as html', function () {
Expand All @@ -27,24 +28,31 @@ describe('fixture', function () {

describe('style.css', function () {
before(function () {
data = fixture.file('onmount/_bookdown/assets/style.css')
data = fx.read('_bookdown/assets/style.css')
})

it('works', function () {
expect(data).toInclude('.markdown-body')
expect(data).toInclude('.toc-menu')
})

it('renders custom css', function () {
expect(data).toInclude('fira sans')
})
})

describe('script.js', function () {
before(function () {
data = fixture.file('onmount/_bookdown/assets/script.js')
data = fx.read('_bookdown/assets/script.js')
})

it('works', function () {
expect(data).toInclude('Pjax')
expect(data).toInclude('pjax:complete')
expect(data).toInclude('Nprogress')
})
})

it('renders custom js', function () {
expect(data).toInclude('/* custom */')
}) })
})
29 changes: 24 additions & 5 deletions test/support/fixture.js
@@ -1,9 +1,28 @@
module.exports = fixture
'use strict'

function fixture (path) {
return require('path').join(__dirname, '../../fixture', path)
var join = require('path').join
var fs = require('fs')

function Fixture (path) {
if (!(this instanceof Fixture)) return new Fixture(path)
this.root = path
}

Fixture.root = join(__dirname, '../../fixture')

Fixture.prototype.path = function (file) {
return join(Fixture.root, this.root, file)
}

fixture.file = function fixtureFile (path) {
return require('fs').readFileSync(fixture(path), 'utf-8')
Fixture.prototype.exists = function (file) {
try {
fs.statSync(this.path(file))
return true
} catch (e) { return false }
}

Fixture.prototype.read = function (file) {
return fs.readFileSync(this.path(file), 'utf-8')
}

module.exports = Fixture

0 comments on commit 1422a04

Please sign in to comment.