Skip to content

Commit f6119d8

Browse files
committed
first step transclusion tests
1 parent 22ff3a5 commit f6119d8

File tree

5 files changed

+66
-18
lines changed

5 files changed

+66
-18
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "node ./test/index.js | tap-spec",
8+
"testify": "nodemon ./test/index.js | tap-spec",
89
"build": "browserify source/client.js -o build/client.js",
910
"watch": "watchify source/client.js -o build/client.js -v",
1011
"start": "npm run watch & nodemon server.js",
@@ -33,6 +34,7 @@
3334
"routes": "^2.0.0"
3435
},
3536
"devDependencies": {
37+
"nock": "^2.15.0",
3638
"tap-spec": "^4.1.0",
3739
"tape": "^4.2.1"
3840
}

test/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
process.env.NODE_ENV = 'testing'
2+
13
var youtubeAutoEmbed = require('./youtubeAutoEmbed_test')()
24
var treeBuild_test = require('./treeBuild_test')()
35

test/treeBuild_test.js

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,66 @@
11
var test = require('tape')
2+
var nock = require('nock')
23
var treeBuild = require('../treeBuild')
34

4-
var shallowMarkdown =
5-
'Test string, with [normal link](www.google.com), ' +
6-
'a +[hypermarkdown]("http://www.github.com/mixmix/hypermarkdown/master/blob/README.md") transclusion, ' +
7-
'and an transclusion with a [reference][] ' +
8-
'[ ]: http://www.github.com/mixmix/hypermarkdown/master/blob/README.md'
5+
var mockDomain = 'http://wwww.mock.com'
6+
var plain = {
7+
'path': '/plain.md',
8+
'content': 'Test string, with [normal link](www.google.com), nice '
9+
}
10+
var transclude = {
11+
'path': '/transclude.md',
12+
'content': 'a +[hypermarkdown](http://wwww.mock.com/_target.md) transclusion.'
13+
}
14+
var refTransclude = {
15+
'path': '/reference_transclude.md',
16+
'content': 'and an transclusion which uses [implicit reference][targetPartialUrl] break' +
17+
'[targetPartialUrl]: http://wwww.mock.com/_target.md'
18+
}
19+
var transcludeTarget = {
20+
'path': '/_target.md',
21+
'content': 'My sweet **transcluded** text!'
22+
}
923

1024
module.exports = function() {
11-
test('youtubeAutoEmbed', function(t) {
12-
t.equal(
13-
)
14-
t.equal(
15-
)
16-
t.equal(
17-
)
18-
25+
test('treeBuild', function(t) {
26+
27+
var scope = nock(mockDomain)
28+
.get(plain.path).reply(200, plain.content)
29+
.get(transclude.path).reply(200, transclude.content)
30+
.get(refTransclude.path).reply(200, refTransclude.content)
31+
.get(transcludeTarget.path).reply(200, transcludeTarget.content)
32+
33+
34+
treeBuild(mockDomain + plain.path, function(err, res) {
35+
if (err) throw err
36+
t.deepEqual( res['children'], [], 'it builds a tree one level deep when there are no transclusion links')
37+
})
1938

39+
treeBuild(mockDomain + transclude.path, function(err, res) {
40+
if (err) throw err
41+
t.notDeepEqual( res['children'], [], 'it is only 2 levels deep')
42+
t.deepEqual( res['children'][0]['content'], transcludeTarget.content, 'it loads transcluded branch text')
43+
t.deepEqual( res['children'][0]['url'], mockDomain + transcludeTarget.path, 'it loads transcluded branch url')
44+
})
45+
46+
treeBuild(mockDomain + refTransclude.path, function(err, res) {
47+
if (err) throw err
48+
t.notDeepEqual( res['children'], [], 'it is only 2 levels deep')
49+
t.deepEqual( res['children'][0]['content'], transcludeTarget.content, 'it loads transcluded branch text')
50+
t.deepEqual( res['children'][0]['url'], mockDomain + transcludeTarget.path, 'it loads transcluded branch url')
51+
})
52+
53+
//scope.done()
2054
t.end()
2155
})
2256
}
2357

58+
59+
function returnChildrenCallback( err, response ) {
60+
if (err) console.log( err )
61+
62+
console.log(response)
63+
//console.log(response['content'])
64+
console.log( response['children'] )
65+
return response['children']
66+
}

test/youtubeAutoEmbed_test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ module.exports = function() {
1515
)
1616
t.equal(
1717
youtubeAutoEmbed('link +<a href="https://www.youtube.com/watch?v=ZnuwB35GYMY">test</a>'),
18-
'link <iframe width="853" height="480" src="https://www.youtube.com/embed/ZnuwB35GYMY?rel=0" frameborder="0" allowfullscreen></iframe>',
18+
'link <div class="youtube-embed"><iframe width="853" height="480" src="https://www.youtube.com/embed/ZnuwB35GYMY?rel=0" frameborder="0" allowfullscreen></iframe></div>',
1919
'replaces youtube links with embedded videos'
2020
)
2121

22-
2322
t.end()
2423
})
2524
}

treeBuild.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ function expandTree( treeNode, callback ) {
3939
if (isInfiniteLoop(treeNode)) return callback(null, treeNode)
4040

4141
var getUrl = makeRaw(treeNode.url)
42-
console.log( Array(treeNode.depth*2).join(' ') + green('[Get] ') + getUrl)
42+
if (process.env.NODE_ENV != 'testing') {
43+
console.log( Array(treeNode.depth*2).join(' ') + green('[Get] ') + getUrl)
44+
}
4345

4446
request.get( getUrl, function(err, response, body) {
4547
if (err) {
@@ -103,8 +105,8 @@ function buildExplicitLink( treeNode, url ) {
103105
}
104106

105107
function findTransclusionLinks(text) {
106-
//var link_pattern_matches = text.match(/\+ \[ [^\[\]]* \] \( ^\)]+ \) /g)
107-
var link_pattern_matches = text.match(/\+\[[^\[\]]*\]\([^\)]+\)/g)
108+
//var link_pattern_matches = text.match(/\+ \[ [^\[\]]* \] \( [^\)]+ \) /g)
109+
var link_pattern_matches = text.match(/\+\[[^\[\]]*\]\([^\)]+\)/g)
108110

109111
if (link_pattern_matches) {
110112
return link_pattern_matches.map( seperateLabelAndLink )

0 commit comments

Comments
 (0)