forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine_react_tests.js
More file actions
47 lines (41 loc) · 1.38 KB
/
engine_react_tests.js
File metadata and controls
47 lines (41 loc) · 1.38 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
const path = require('path');
const fs = require('fs');
const tap = require('tap');
const loadPattern = require('../src/lib/loadPattern');
const testUtils = require('./util/test_utils.js');
const config = require('./util/patternlab-config.json');
const engineLoader = require('../src/lib/pattern_engines');
const testPatternsPath = path.resolve(
__dirname,
'files',
'_react-test-patterns'
);
engineLoader.loadAllEngines(config);
// don't run these tests unless the react engine is installed
if (!engineLoader.react) {
tap.test('React engine not installed, skipping tests.', (test) => {
test.end();
});
} else {
const fpl = testUtils.fakePatternLab(testPatternsPath);
tap.test('Load the hello world pattern and verify contents', (test) => {
const patternPath = path.join(
testPatternsPath,
'atoms/general/HelloWorld.jsx'
);
const patternContent = fs.readFileSync(patternPath, { encoding: 'utf8' });
const pattern = loadPattern(patternPath, fpl);
test.equal(pattern.template, patternContent);
test.end();
});
tap.test('Load the hello world pattern and verify output', (test) => {
const patternPath = path.join(
testPatternsPath,
'atoms/general/HelloWorld.jsx'
);
const pattern = loadPattern(patternPath, fpl);
return pattern.render().then((output) => {
test.equal(output, '<div>Hello world!</div>\n');
});
});
}