Skip to content

Commit bab5cef

Browse files
committed
Run tests in the browser via testling
Refactored test code to make it play nice with brfs
1 parent 07808db commit bab5cef

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "A through stream which converts markup in text form to JSONML",
55
"main": "index.js",
66
"scripts": {
7-
"test": "covert test/test.js && test/cli.sh"
7+
"testling": "browserify -t brfs test/test.js | testling",
8+
"test": "cd test; covert test.js && ./cli.sh"
89
},
910
"bin": {
1011
"jsonmlify": "bin/cli.js"
@@ -32,7 +33,10 @@
3233
"nomnom": "^1.8.0"
3334
},
3435
"devDependencies": {
36+
"brfs": "^1.2.0",
37+
"browserify": "^5.9.1",
3538
"covert": "^0.4.0",
36-
"tape": "^2.13.4"
39+
"tape": "^2.13.4",
40+
"testling": "^1.7.0"
3741
}
3842
}

test/test.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,43 @@ var fs = require('fs');
22
var test = require('tape');
33
var jsonmlify = require('../');
44

5-
function verify(testDir, t) {
6-
fs.createReadStream(__dirname + '/' + testDir + '/markup.html')
7-
.pipe(jsonmlify())
5+
function verify(markup, expected, t) {
6+
jsonmlify()
87
.on('data', function(data) {
9-
t.deepEqual(data, require(__dirname + '/' + testDir + '/expected.json'));
8+
t.deepEqual(data, expected);
109
t.end();
11-
});
10+
})
11+
.end(markup);
1212
}
1313

1414
test('should return an empty array for empty input markup', function(t) {
15-
verify('01-empty', t);
15+
var markup = fs.readFileSync(__dirname + '/01-empty/markup.html', 'utf8');
16+
var expected = require('./01-empty/expected.json');
17+
verify(markup, expected, t);
1618
});
1719

1820
test('should not set a node-list array on the node if it has no children', function(t) {
19-
verify('02-single-shallow-tag', t);
21+
var markup = fs.readFileSync(__dirname + '/02-single-shallow-tag/markup.html', 'utf8');
22+
var expected = require('./02-single-shallow-tag/expected.json');
23+
verify(markup, expected, t);
2024
});
2125

2226
test('should not set a attribute hash on the node if it has none', function(t) {
23-
verify('03-no-attributes', t);
27+
var markup = fs.readFileSync(__dirname + '/03-no-attributes/markup.html', 'utf8');
28+
var expected = require('./03-no-attributes/expected.json');
29+
verify(markup, expected, t);
2430
});
2531

2632
test('should parse nested tags and text nodes', function(t) {
27-
verify('04-nested-tags', t);
33+
var markup = fs.readFileSync(__dirname + '/04-nested-tags/markup.html', 'utf8');
34+
var expected = require('./04-nested-tags/expected.json');
35+
verify(markup, expected, t);
2836
});
2937

3038
test('should parse comments', function(t) {
31-
verify('05-comments', t);
39+
var markup = fs.readFileSync(__dirname + '/05-comments/markup.html', 'utf8');
40+
var expected = require('./05-comments/expected.json');
41+
verify(markup, expected, t);
3242
});
3343

3444
test('should report errors', function(t) {

0 commit comments

Comments
 (0)