|
| 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 | +} |
0 commit comments