-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
107 lines (96 loc) · 3.34 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
require('mocha');
const assert = require('assert');
const reflinks = require('./');
const verb = require('templates');
let app;
describe('verb-reflinks', function() {
beforeEach(function() {
app = verb();
app.create('docs');
app.option('engine', '*');
app.engine('*', function(file, locals, cb) {
cb(null, file);
});
});
describe('lib', function() {
it('should export a function', function() {
assert.equal(typeof reflinks, 'function');
});
it('should expose a `.matches` method', function() {
assert.equal(typeof reflinks.matches, 'function');
});
it('should expose a `.diff` method', function() {
assert.equal(typeof reflinks.diff, 'function');
});
});
describe('middleware', function() {
it('should find reflinks in a file and add them to `file._reflinks`', function(cb) {
var count = 0;
app.postRender(/./, reflinks());
app.postRender(/./, function(file, next) {
assert(file._reflinks);
assert(Array.isArray(file._reflinks));
assert.equal(file._reflinks[0], 'generate');
assert.equal(file._reflinks[1], 'verb');
app.union('cache.reflinks', file._reflinks);
count = file._reflinks.length;
next();
});
var view = app.docs.addView('foo', {content: 'This is a reflink\n[verb][]\n[generate][]\n'});
app.render(view, function(err, view) {
if (err) return cb(err);
assert.equal(count, 2);
cb();
});
});
it('should add local reflinks to `file._reflinks`', function(cb) {
var count = 0;
app.postRender(/./, reflinks());
app.postRender(/./, function(file, next) {
assert(file._reflinks);
assert(Array.isArray(file._reflinks));
assert.equal(file._reflinks[0], 'docs');
assert.equal(file._reflinks[1], 'generate');
app.union('cache.reflinks', file._reflinks);
count = file._reflinks.length;
next();
});
var view = app.docs.addView('foo', {content: 'This is a reflink\n[documentation][docs]\n[generate][]\n'});
app.render(view, function(err, view) {
if (err) return cb(err);
assert.equal(count, 2);
cb();
});
});
it('should not add reflinks that are already defined locally', function(cb) {
var count = 0;
app.postRender(/./, reflinks());
app.postRender(/./, function(file, next) {
assert(file._reflinks);
assert(Array.isArray(file._reflinks));
assert.equal(file._reflinks[0], 'generate');
app.union('cache.reflinks', file._reflinks);
count = file._reflinks.length;
next();
});
var view = app.docs.addView('foo', {content: 'This is a reflink\n[verb][]\n[generate][]\n\n[verb]: https://github.com/verbose/verb'});
app.render(view, function(err, view) {
if (err) return cb(err);
assert.equal(count, 1);
cb();
});
});
});
describe('.matches', function() {
it('should expose a `.matches` method', function() {
assert.equal(typeof reflinks.matches, 'function');
});
it('should extract matches from a string', function() {
var matches = reflinks.matches('This is a reflink\n[verb][]\n[generate][]\n');
assert(matches);
assert(Array.isArray(matches));
assert.equal(matches.length, 2);
});
});
});