|
| 1 | +import markup from '../lib/markup' |
| 2 | +import { assert } from 'chai' |
| 3 | +import fs from 'fs' |
| 4 | +import { join } from 'path' |
| 5 | + |
| 6 | +function desc(path) { |
| 7 | + return { |
| 8 | + id: Date.now(), |
| 9 | + attributes: { |
| 10 | + description: fs.readFileSync(join(__dirname, `./mocks/description/${path}.md`), 'utf-8'), |
| 11 | + methods: [], |
| 12 | + properties: [], |
| 13 | + events: [] |
| 14 | + } |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +function mark(path) { |
| 19 | + let data = [ |
| 20 | + desc(path) |
| 21 | + ]; |
| 22 | + let result = markup({data}) |
| 23 | + let content = result.data[0].attributes.description |
| 24 | + maybeWrite(content, path) |
| 25 | + return content |
| 26 | +} |
| 27 | + |
| 28 | +function maybeWrite(content, path) { |
| 29 | + const fsPath = join(__dirname, `./mocks/description/${path}.html`) |
| 30 | + if (fs.existsSync(fsPath)) { |
| 31 | + return |
| 32 | + } |
| 33 | + fs.writeFileSync(fsPath, content, 'utf-8') |
| 34 | +} |
| 35 | + |
| 36 | +function snapshot(path) { |
| 37 | + const fsPath = join(__dirname, `./mocks/description/${path}.html`) |
| 38 | + return fs.readFileSync(fsPath, 'utf8') |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +describe('markup', () => { |
| 43 | + it('render correct syntax for handlebars with title', function() { |
| 44 | + const caseName = 'handlebars-title' |
| 45 | + assert.equal(mark(caseName), snapshot(caseName)) |
| 46 | + }) |
| 47 | + |
| 48 | + it('render correct syntax for handlebars without title', function() { |
| 49 | + const caseName = 'handlebars' |
| 50 | + assert.equal(mark(caseName), snapshot(caseName)) |
| 51 | + }) |
| 52 | + |
| 53 | + it('render correct syntax for javascript with title', function() { |
| 54 | + const caseName = 'javascript-title' |
| 55 | + assert.equal(mark(caseName), snapshot(caseName)) |
| 56 | + }) |
| 57 | + |
| 58 | + it('render correct syntax for javascript without title', function() { |
| 59 | + const caseName = 'javascript' |
| 60 | + assert.equal(mark(caseName), snapshot(caseName)) |
| 61 | + }) |
| 62 | +}) |
0 commit comments