Skip to content

Commit 1ed75af

Browse files
Merge pull request #774 from pattern-lab/react-engine-unit-tests
First couple of unit tests for the React engine
2 parents 0b6bd5f + 19cc5c8 commit 1ed75af

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

test/engine_react_tests.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const tap = require('tap');
4+
const loadPattern = require('../core/lib/loadPattern');
5+
const testUtils = require('./util/test_utils.js');
6+
const config = require('./util/patternlab-config.json');
7+
const engineLoader = require('../core/lib/pattern_engines');
8+
const testPatternsPath = path.resolve(__dirname, 'files', '_react-test-patterns');
9+
10+
engineLoader.loadAllEngines(config);
11+
12+
// don't run these tests unless the react engine is installed
13+
if (!engineLoader.react) {
14+
tap.test('React engine not installed, skipping tests.', test => {
15+
test.end();
16+
});
17+
} else {
18+
const fpl = testUtils.fakePatternLab(testPatternsPath);
19+
20+
tap.test('Load the hello world pattern and verify contents', test => {
21+
const patternPath = path.join(testPatternsPath, '00-atoms/00-general/HelloWorld.jsx');
22+
const patternContent = fs.readFileSync(patternPath, { encoding: 'utf8' });
23+
const pattern = loadPattern(patternPath, fpl);
24+
25+
test.equals(pattern.template, patternContent);
26+
test.end();
27+
});
28+
29+
tap.test('Load the hello world pattern and verify output', test => {
30+
const patternPath = path.join(testPatternsPath, '00-atoms/00-general/HelloWorld.jsx');
31+
const pattern = loadPattern(patternPath, fpl);
32+
33+
return pattern.render().then(output => {
34+
test.equals(output, '<div>Hello world!</div>\n');
35+
});
36+
});
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
const HelloWorld = () => (
4+
<div>
5+
Hello world!
6+
</div>
7+
);
8+
9+
export default HelloWorld;

0 commit comments

Comments
 (0)