Skip to content

First couple of unit tests for the React engine #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;