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