-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #774 from pattern-lab/react-engine-unit-tests
First couple of unit tests for the React engine
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
} |
9 changes: 9 additions & 0 deletions
9
test/files/_react-test-patterns/00-atoms/00-general/HelloWorld.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |