Skip to content

Commit

Permalink
Merge pull request #774 from pattern-lab/react-engine-unit-tests
Browse files Browse the repository at this point in the history
First couple of unit tests for the React engine
  • Loading branch information
bmuenzenmeyer authored Jan 16, 2018
2 parents 0b6bd5f + 19cc5c8 commit 1ed75af
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/engine_react_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require('path');
const fs = require('fs');
const tap = require('tap');
const loadPattern = require('../core/lib/loadPattern');
const testUtils = require('./util/test_utils.js');
const config = require('./util/patternlab-config.json');
const engineLoader = require('../core/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, '00-atoms/00-general/HelloWorld.jsx');
const patternContent = fs.readFileSync(patternPath, { encoding: 'utf8' });
const pattern = loadPattern(patternPath, fpl);

test.equals(pattern.template, patternContent);
test.end();
});

tap.test('Load the hello world pattern and verify output', test => {
const patternPath = path.join(testPatternsPath, '00-atoms/00-general/HelloWorld.jsx');
const pattern = loadPattern(patternPath, fpl);

return pattern.render().then(output => {
test.equals(output, '<div>Hello world!</div>\n');
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

const HelloWorld = () => (
<div>
Hello world!
</div>
);

export default HelloWorld;

0 comments on commit 1ed75af

Please sign in to comment.