forked from eddyerburgh/jest-serializer-vue
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
38 lines (34 loc) · 1.28 KB
/
index.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
const beautify = require('js-beautify').html;
const fs = require('fs');
const _cloneDeep = require('lodash.clonedeep');
const helpers = require('./src/helpers.js');
const loadOptions = require('./src/loadOptions.js');
const stringManipulation = require('./src/stringManipulation.js');
const vnodeManipulation = require('./src/vnodeManipulation.js');
module.exports = {
/**
* Test function for Jest's serializer API.
* Determines whether to pass the markup through the print function.
*
* @param {string|object} received The markup or Vue wrapper to be formatted
* @return {boolean} true = Tells Jest to run the print function
*/
test: function (received) {
return helpers.isHtmlString(received) || helpers.isVueWrapper(received);
},
/**
* Print function for Jest's serializer API.
* Formats markup according to options.
*
* @param {string|object} received The markup or Vue wrapper to be formatted
* @return {string} The formatted markup
*/
print: function (received) {
const options = loadOptions(fs);
let html = received || '';
html = vnodeManipulation(html, options, _cloneDeep);
html = stringManipulation(html, options);
// Format markup
return beautify(html, options.formatting);
}
};