Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Split unit tests into a series of smaller files #123

Merged
merged 1 commit into from
Jan 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/badges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* globals before, describe, it */

var assert = require('assert')
var marky = require('..')
var fixtures = require('./fixtures')

describe('badges', function () {
var $

before(function () {
$ = marky(fixtures.badges)
})

it('adds a badge class to img tags containing badge images', function () {
assert($('img').length)
assert.equal($('img').length, $('img.badge').length)
})

it('adds a badge-only class to p tags containing nothing more than a badge', function () {
assert.equal($('p:not(.badge-only)').length, 2)
assert.equal($('p.badge-only').length, $('p').length - 2)
})
})
73 changes: 73 additions & 0 deletions test/cdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* globals before, describe, it */

var assert = require('assert')
var marky = require('..')
var fixtures = require('./fixtures')

describe('cdn', function () {
describe('when serveImagesWithCDN is true', function () {
var $
var options = {
package: {name: 'foo', version: '1.0.0'},
serveImagesWithCDN: true
}

before(function () {
$ = marky(fixtures.basic, options)
})

it('replaces relative img URLs with npm CDN URLs', function () {
assert(~fixtures.basic.indexOf('![](relative.png)'))
assert($("img[src='https://cdn.npm.im/foo@1.0.0/relative.png']").length)
})

it('replaces slashy relative img URLs with npm CDN URLs', function () {
assert(~fixtures.basic.indexOf('![](/slashy/deep.png)'))
assert($("img[src='https://cdn.npm.im/foo@1.0.0/slashy/deep.png']").length)
})

it('leaves protocol relative URLs alone', function () {
assert(~fixtures.basic.indexOf('![](//protocollie.com/woof.png)'))
assert($("img[src='//protocollie.com/woof.png']").length)
})

it('leaves HTTPS URLs alone', function () {
assert(~fixtures.basic.indexOf('![](https://secure.com/good.png)'))
assert($("img[src='https://secure.com/good.png']").length)
})
})

describe('when serveImagesWithCDN is false (default)', function () {
var $
var options = {
package: {
name: 'foo',
version: '1.0.0'
}
}

before(function () {
$ = marky(fixtures.basic, options)
})

it('leaves relative img alone', function () {
assert(~fixtures.basic.indexOf('![](relative.png)'))
assert($("img[src='relative.png']").length)
})

it('leaves slashy relative img URLs alone', function () {
assert(~fixtures.basic.indexOf('![](/slashy/deep.png)'))
assert($("img[src='/slashy/deep.png']").length)
})

it('leaves protocol relative URLs alone', function () {
assert(~fixtures.basic.indexOf('![](//protocollie.com/woof.png)'))
assert($("img[src='//protocollie.com/woof.png']").length)
})

it('leaves HTTPS URLs alone', function () {
assert(~fixtures.basic.indexOf('![](https://secure.com/good.png)'))
assert($("img[src='https://secure.com/good.png']").length)
})
})
})
5 changes: 3 additions & 2 deletions test/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var fs = require('fs')
var path = require('path')
var glob = require('glob')
var pkg = require('../package.json')

var fixtures = {
dependencies: [], // our dependencies and devDependencies
Expand All @@ -16,8 +17,8 @@ fs.readdirSync(__dirname + '/fixtures').forEach(function (file) {
})

// Read in dependencies' and devDependencies' readmes
fixtures.dependencies = Object.keys(require('../package.json').devDependencies)
.concat(Object.keys(require('../package.json').dependencies))
fixtures.dependencies = Object.keys(pkg.devDependencies)
.concat(Object.keys(pkg.dependencies))
.sort()
fixtures.dependencies.forEach(function (name) {
var modulePath = path.resolve('node_modules', name)
Expand Down
6 changes: 6 additions & 0 deletions test/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* globals describe */

describe('github', function () {
require('./repo-github')
require('./repo-other')
})
29 changes: 29 additions & 0 deletions test/gravatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* globals before, describe, it */

var assert = require('assert')
var marky = require('..')
var fixtures = require('./fixtures')

describe('gravatar', function () {
var $

before(function () {
$ = marky(fixtures.gravatar)
})

it('replaces insecure gravatar img src URLs with secure HTTPS URLs', function () {
assert(~fixtures.gravatar.indexOf('http://gravatar.com/avatar/123?s=50&d=retro'))
assert.equal($('img').length, 3)
assert.equal($('img').eq(0).attr('src'), 'https://secure.gravatar.com/avatar/123?s=50&d=retro')
})

it('leaves secure gravatar URLs untouched', function () {
assert(~fixtures.gravatar.indexOf('https://secure.gravatar.com/avatar/456?s=50&d=retro'))
assert.equal($('img').eq(1).attr('src'), 'https://secure.gravatar.com/avatar/456?s=50&d=retro')
})

it('leaves non-gravtar URLs untouched', function () {
assert(~fixtures.gravatar.indexOf('http://not-gravatar.com/foo'))
assert.equal($('img').eq(2).attr('src'), 'http://not-gravatar.com/foo')
})
})
97 changes: 97 additions & 0 deletions test/headings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* globals before, describe, it */

var assert = require('assert')
var marky = require('..')
var fixtures = require('./fixtures')

describe('headings', function () {
var $

before(function () {
$ = marky(fixtures.dirty)
})

it('injects hashy anchor tags into headings that have DOM ids', function () {
assert(~fixtures.dirty.indexOf('# h1'))
assert($("h1 a[href='#h1']").length)
})

it('adds deep-link class to modified headings', function () {
assert(~fixtures.dirty.indexOf('# h1'))
assert($("h1.deep-link a[href='#h1']").length)
})

it("doesn't inject anchor tags into headings that already contain anchors", function () {
assert(~fixtures.dirty.indexOf('### [h3](/already/linky)'))
assert($("h3 a[href='/already/linky']").length)
})

it('applies a prefix to generated DOM ids by default', function () {
assert(~fixtures.dirty.indexOf('## h2'))
assert.equal($('h2#user-content-h2').length, 1)
})

it('allows id prefixes to be disabled with prefixHeadingIds', function () {
assert(~fixtures.dirty.indexOf('#### This is a TEST'))
$ = marky(fixtures.dirty, {prefixHeadingIds: false})
assert.equal($('h4#this-is-a-test').length, 1)
})

it('allows a dash in generated DOM ids just like GitHub', function () {
assert(~fixtures.github.indexOf('### heading with a - dash'))
$ = marky(fixtures.github)
assert.equal($('h3#heading-with-a---dash a').length, 1)
})

it('allows a trailing dash in generated DOM ids just like GitHub', function () {
assert(~fixtures.github.indexOf('### heading with a trailing dash -'))
$ = marky(fixtures.github)
assert.equal($('h3#heading-with-a-trailing-dash-- a').length, 1)
})

it('allows underscores in generated DOM ids like GitHub', function () {
assert(~fixtures.github.indexOf('### heading with an _ underscore'))
$ = marky(fixtures.github)
assert.equal($('h3#heading-with-an-_-underscore a').length, 1)
})

it('filters periods in generated DOM ids like GitHub', function () {
assert(~fixtures.github.indexOf('### heading with a period.txt'))
$ = marky(fixtures.github)
assert.equal($('h3#heading-with-a-periodtxt').length, 1)
})

it('allows two spaces even after filtering like GitHub', function () {
assert(~fixtures.github.indexOf('### exchange.bind_headers(exchange, routing [, bindCallback])'))
$ = marky(fixtures.github)
assert.equal($('h3#exchangebind_headersexchange-routing--bindcallback').length, 1)
})

it('add suffix to duplicate generated DOM ids like GitHub', function () {
assert(~fixtures.github.indexOf('### duplicate'))
assert(~fixtures.github.indexOf('### duplicate('))
assert(~fixtures.github.indexOf('### duplicate)'))
$ = marky(fixtures.github)
assert.equal($('h3#duplicate a').length, 1)
assert.equal($('h3#duplicate-1 a').length, 1)
assert.equal($('h3#duplicate-2 a').length, 1)
})

it('encodes innerHTML and removes angle brackets before generating ids', function () {
assert(~fixtures.payform.indexOf('## Browser `<input>` Helpers'))
$ = marky(fixtures.payform, {prefixHeadingIds: false})
assert.equal($('h2#browser-input-helpers a').length, 1)
assert.equal($('h2#browser-input-helpers a').html(), 'Browser <code>&lt;input&gt;</code> Helpers')
})

it('properly handles headings lacking a space between the leading #(s) and heading text', function () {
assert(~fixtures.lazyheading.indexOf('#lazy heading'))
$ = marky(fixtures.lazyheading, {prefixHeadingIds: false})
assert.equal($('h1#lazy-heading-1').length, 1)
assert.equal($('h2#lazy-heading-2').length, 1)
assert.equal($('h3#lazy-heading-3').length, 1)
assert.equal($('h4#lazy-heading-4').length, 1)
assert.equal($('h5#lazy-heading-5').length, 1)
assert.equal($('h6#lazy-heading-6').length, 1)
})
})
Loading