Skip to content

Commit 5b7dcf6

Browse files
Merge pull request #522 from alexbenic/underscore-tests
Convert engine_underscore_tests.js to use tape
2 parents c92aec4 + e3b52cb commit 5b7dcf6

File tree

1 file changed

+70
-64
lines changed

1 file changed

+70
-64
lines changed

test/engine_underscore_tests.js

Lines changed: 70 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
"use strict";
22

3+
var tap = require('tap');
34
var path = require('path');
45
var pa = require('../core/lib/pattern_assembler');
56
var testPatternsPath = path.resolve(__dirname, 'files', '_underscore-test-patterns');
67
var eol = require('os').EOL;
78

9+
// don't run tests unless underscore is installed
10+
var engineLoader = require('../core/lib/pattern_engines');
11+
if (!engineLoader.underscore) {
12+
tap.test('Underscore engine not installed, skipping tests', function (test) {
13+
test.end();
14+
});
15+
return;
16+
}
17+
818
// fake pattern lab constructor:
919
// sets up a fake patternlab object, which is needed by the pattern processing
1020
// apparatus.
@@ -30,67 +40,63 @@ function fakePatternLab() {
3040
return fpl;
3141
}
3242

33-
exports['engine_underscore'] = {
34-
'hello world underscore pattern renders': function (test) {
35-
test.expect(1);
36-
37-
var patternPath = path.resolve(
38-
testPatternsPath,
39-
'00-atoms',
40-
'00-global',
41-
'00-helloworld.html'
42-
);
43-
44-
// do all the normal processing of the pattern
45-
var patternlab = new fakePatternLab();
46-
var assembler = new pa();
47-
var helloWorldPattern = assembler.process_pattern_iterative(patternPath, patternlab);
48-
assembler.process_pattern_recursive(patternPath, patternlab);
49-
50-
test.equals(helloWorldPattern.render(), 'Hello world!' + eol);
51-
test.done();
52-
},
53-
'underscore partials can render JSON values': function (test) {
54-
test.expect(1);
55-
56-
// pattern paths
57-
var pattern1Path = path.resolve(
58-
testPatternsPath,
59-
'00-atoms',
60-
'00-global',
61-
'00-helloworld-withdata.html'
62-
);
63-
64-
// set up environment
65-
var patternlab = new fakePatternLab(); // environment
66-
var assembler = new pa();
67-
68-
// do all the normal processing of the pattern
69-
var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab);
70-
assembler.process_pattern_recursive(pattern1Path, patternlab);
71-
72-
// test
73-
test.equals(helloWorldWithData.render(), 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol);
74-
test.done();
75-
},
76-
'findPartial return the ID of the partial, given a whole partial call': function (test) {
77-
var engineLoader = require('../core/lib/pattern_engines');
78-
var underscoreEngine = engineLoader.underscore;
79-
80-
test.expect(1);
81-
82-
// do all the normal processing of the pattern
83-
// test
84-
test.equals(underscoreEngine.findPartial("<%= _.renderNamedPartial('molecules-details', obj) %>"), 'molecules-details');
85-
test.done();
86-
}
87-
};
88-
89-
90-
91-
// don't run these tests unless underscore is installed
92-
var engineLoader = require('../core/lib/pattern_engines');
93-
if (!engineLoader.underscore) {
94-
console.log("Underscore engine not installed, skipping tests.");
95-
delete exports.engine_underscore;
96-
}
43+
tap.test('hello world underscore pattern renders', function (test) {
44+
test.plan(1);
45+
46+
var patternPath = path.resolve(
47+
testPatternsPath,
48+
'00-atoms',
49+
'00-global',
50+
'00-helloworld.html'
51+
);
52+
53+
// do all the normal processing of the pattern
54+
var patternlab = new fakePatternLab();
55+
var assembler = new pa();
56+
var helloWorldPattern = assembler.process_pattern_iterative(patternPath, patternlab);
57+
assembler.process_pattern_recursive(patternPath, patternlab);
58+
59+
test.equals(helloWorldPattern.render(), 'Hello world!' + eol);
60+
test.end();
61+
62+
});
63+
64+
tap.test('underscore partials can render JSON values', function (test) {
65+
66+
test.plan(1);
67+
68+
// pattern paths
69+
var pattern1Path = path.resolve(
70+
testPatternsPath,
71+
'00-atoms',
72+
'00-global',
73+
'00-helloworld-withdata.html'
74+
);
75+
76+
// set up environment
77+
var patternlab = new fakePatternLab(); // environment
78+
var assembler = new pa();
79+
80+
// do all the normal processing of the pattern
81+
var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab);
82+
assembler.process_pattern_recursive(pattern1Path, patternlab);
83+
84+
// test
85+
test.equals(helloWorldWithData.render(), 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol);
86+
test.end();
87+
88+
});
89+
90+
tap.test('findPartial return the ID of the partial, given a whole partial call', function (test) {
91+
var engineLoader = require('../core/lib/pattern_engines');
92+
var underscoreEngine = engineLoader.underscore;
93+
94+
test.plan(1);
95+
96+
// do all the normal processing of the pattern
97+
// test
98+
test.equals(underscoreEngine.findPartial("<%= _.renderNamedPartial('molecules-details', obj) %>"), 'molecules-details');
99+
test.end();
100+
101+
});
102+

0 commit comments

Comments
 (0)