-
Notifications
You must be signed in to change notification settings - Fork 7
/
automated-ui-testing.js
45 lines (38 loc) · 1.1 KB
/
automated-ui-testing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { morph } from 'views-morph'
import { shallow } from 'enzyme'
import fs from 'fs'
import globule from 'globule'
import toJson from 'enzyme-to-json'
import path from 'path'
import React from 'react'
const paths = globule.find('**/*.view', {
filter: f => !/node_modules/.test(f),
})
paths.forEach(fileRaw => {
const file = path.join(process.cwd(), fileRaw)
const viewName = path.basename(file, '.view')
try {
const View = require(`${file}.js`).default
const testsFile = `${file}.tests`
const code = morph(fs.readFileSync(testsFile, 'utf8'), {
as: 'tests',
name: `${viewName}.view.tests`,
file: {
raw: testsFile,
},
}).code.replace(/export const /g, 'out.')
const out = {}
// eslint-disable-next
new Function('out', code)(out)
const tests = out.make(() => {})
for (let test in tests) {
if (test === '_main') continue
it(`${viewName} (${test})`, () => {
const wrapper = shallow(<View {...tests[test]} />)
expect(toJson(wrapper)).toMatchSnapshot()
})
}
} catch (err) {
it.skip(viewName)
}
})