forked from metabase/docs.metabase.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink-fixing.js
More file actions
56 lines (45 loc) · 1.68 KB
/
link-fixing.js
File metadata and controls
56 lines (45 loc) · 1.68 KB
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
#!/usr/bin/env node
var fs = require('fs')
var test = require('tape')
var fixInternalLinks = require('../lib/doc-links.js')
var urlRegex = /\[.+\]\(.+\)/g
var dir = 'spec/fixtures/test-set-docs/tutorial'
var emptyDir = 'spec/fixtures/test-set-docs/empty-dir'
var originalFile = 'spec/fixtures/doc-with-internal-links.md'
var originalContent = fs.readFileSync(originalFile).toString()
var finalFile = 'spec/fixtures/test-set-docs/tutorial/quick-start.md'
var expectedLinks = [
'[ipc](http://electron.atom.io/docs/v0.27.0/api/ipc-renderer)',
'[remote](http://electron.atom.io/docs/v0.27.0/api/remote)',
'[Application distribution](http://electron.atom.io/docs/v0.27.0/tutorial/application-distribution)',
'[here](https://github.com/atom/electron/releases)'
]
test('Fetch and write documentation with latest flag', function (t) {
t.plan(4)
fixInternalLinks(dir, 'v0.27.0', function callback (error) {
if (error) return t.fail(error)
compareLinks()
})
function compareLinks () {
var finalContent = fs.readFileSync(finalFile).toString()
var finalLinks = finalContent.match(urlRegex)
if (finalLinks) {
finalLinks.forEach(function (finalLink, i) {
t.equal(finalLink, expectedLinks[i], 'Link ' + finalLink + ' matches ' + expectedLinks[i])
})
}
cleanup()
}
function cleanup () {
fs.writeFile(finalFile, originalContent, function (error) {
if (error) return t.fail(error)
})
}
})
test('Parse empty directory', function (t) {
fixInternalLinks(emptyDir, 'v0.27.0', function callback (error) {
t.ok(error, 'got error')
t.equal(error.message, 'Found no relative links in files.', 'Got correct error message.')
t.end()
})
})