-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
117 lines (107 loc) · 3.25 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
108
109
110
111
112
113
114
115
116
117
'use strict';
require('mocha');
const assert = require('assert');
const vfs = require('vinyl-fs');
const reflinks = require('./');
describe('gulp-reflinks', function() {
it('should export a function', function() {
assert.equal(typeof reflinks, 'function');
});
it('should lint reflinks', function(cb) {
var files = [];
vfs.src('fixtures/missing.md')
.pipe(reflinks())
.on('data', function(file) {
files.push(file);
})
.on('end', function() {
assert.equal(files[0].contents.toString(), '[gulp][]\n\n[gulp]: http://gulpjs.com');
cb();
});
});
it('should not add reflinks that already exist', function(cb) {
var files = [];
vfs.src('fixtures/no-dupes.md')
.pipe(reflinks())
.on('data', function(file) {
files.push(file);
})
.on('end', function() {
assert.equal(files[0].contents.toString(), '[gulp][]\n\n[gulp]: http://gulpjs.com');
cb();
});
});
it('should lint compact reflinks', function(cb) {
var files = [];
vfs.src('fixtures/missing-compact.md')
.pipe(reflinks())
.on('data', function(file) {
files.push(file);
})
.on('end', function() {
assert.equal(files[0].contents.toString(), '[gulp]\n\n[gulp]: http://gulpjs.com');
cb();
});
});
it('should detect multiple missing reflinks', function(cb) {
var files = [];
vfs.src('fixtures/multiple.md')
.pipe(reflinks())
.on('data', function(file) {
files.push(file);
})
.on('end', function() {
assert.equal(files[0].contents.toString(), '[assemble][]\n[generate][]\n[verb][]\n\n[assemble]: https://github.com/assemble/assemble\n[generate]: https://github.com/generate/generate\n[verb]: https://github.com/verbose/verb');
cb();
});
});
it('should ignore reflinks in backticks', function(cb) {
var files = [];
vfs.src('fixtures/code.md')
.pipe(reflinks())
.on('data', function(file) {
files.push(file);
})
.on('end', function() {
assert(!/https/.test(files[0].contents.toString()));
cb();
});
});
it('should ignore reflinks with invalid characters', function(cb) {
var files = [];
vfs.src('fixtures/non-reflinks.md')
.pipe(reflinks())
.on('data', function(file) {
files.push(file);
})
.on('end', function() {
assert(!/https/.test(files[0].contents.toString()));
cb();
});
});
it('should set reflinks on `file._reflinks`', function(cb) {
var files = [];
vfs.src('fixtures/missing-compact.md')
.pipe(reflinks())
.on('data', function(file) {
files.push(file);
})
.on('end', function() {
assert.deepEqual(files[0]._reflinks, ['gulp']);
assert.equal(files[0].contents.toString(), '[gulp]\n\n[gulp]: http://gulpjs.com');
cb();
});
});
it('should set multiple reflinks on `file._reflinks`', function(cb) {
var files = [];
vfs.src('fixtures/multiple.md')
.pipe(reflinks())
.on('data', function(file) {
files.push(file);
})
.on('end', function() {
assert.deepEqual(files[0]._reflinks, ['assemble', 'generate', 'verb']);
cb();
});
});
});