|
1 | | -import fs from 'fs'; |
2 | | -import path from 'path'; |
3 | | -import glob from 'glob'; |
| 1 | +/* eslint-env jest, browser */ |
4 | 2 |
|
5 | | -import serializeNodeToHtmlString from './utils'; |
6 | | -import toDOM from './index'; |
| 3 | +import fs from 'fs' |
| 4 | +import path from 'path' |
| 5 | +import glob from 'glob' |
| 6 | +import serializeNodeToHtmlString from './utils.js' |
| 7 | +import toDOM from './index.js' |
7 | 8 |
|
8 | 9 | describe('fixtures', () => { |
9 | | - const root = path.join(__dirname, '__fixtures__'); |
10 | | - const fixturePaths = glob.sync(path.join(root, '**/*/')); |
| 10 | + const root = path.join(__dirname, '__fixtures__') |
| 11 | + const fixturePaths = glob.sync(path.join(root, '**/*/')) |
| 12 | + let index = -1 |
11 | 13 |
|
12 | | - fixturePaths.forEach((fixturePath) => { |
13 | | - const fixture = path.relative(root, fixturePath); |
14 | | - const fixtureInput = path.join(fixturePath, 'index.json'); |
15 | | - const fixtureOutput = path.join(fixturePath, 'index.html'); |
| 14 | + while (++index < fixturePaths.length) { |
| 15 | + each(fixturePaths[index]) |
| 16 | + } |
| 17 | + |
| 18 | + function each(fixturePath) { |
| 19 | + const fixture = path.relative(root, fixturePath) |
| 20 | + const fixtureInput = path.join(fixturePath, 'index.json') |
| 21 | + const fixtureOutput = path.join(fixturePath, 'index.html') |
16 | 22 |
|
17 | 23 | test(fixture, () => { |
18 | | - const fixtureData = JSON.parse(fs.readFileSync(fixtureInput)); |
19 | | - const parsedActual = serializeNodeToHtmlString(toDOM(fixtureData)); |
| 24 | + const fixtureData = JSON.parse(fs.readFileSync(fixtureInput)) |
| 25 | + const parsedActual = serializeNodeToHtmlString(toDOM(fixtureData)) |
20 | 26 |
|
21 | | - let parsedExpected; |
| 27 | + let parsedExpected |
22 | 28 |
|
23 | 29 | try { |
24 | | - parsedExpected = fs.readFileSync(fixtureOutput).toString().trim(); |
25 | | - } catch (e) { |
26 | | - fs.writeFileSync(fixtureOutput, parsedActual); |
27 | | - return; |
| 30 | + parsedExpected = fs.readFileSync(fixtureOutput).toString().trim() |
| 31 | + } catch { |
| 32 | + fs.writeFileSync(fixtureOutput, parsedActual) |
| 33 | + return |
28 | 34 | } |
29 | 35 |
|
30 | | - expect(parsedActual).toEqual(parsedExpected); |
31 | | - }); |
32 | | - }); |
33 | | -}); |
| 36 | + expect(parsedActual).toEqual(parsedExpected) |
| 37 | + }) |
| 38 | + } |
| 39 | +}) |
0 commit comments