1const assert = require('assert'); 2const fs = require('fs'); 3const path = require('path'); 4const parse5 = require('../../packages/parse5/lib'); 5const { generateTestsForEachTreeAdapter, getStringDiffMsg } = require('./common'); 6 7module.exports = function generateSeriliazerTests(moduleExports, prefix, serialize) { 8 const data = fs.readFileSync(path.join(__dirname, '../data/serialization/tests.json')); 9 const tests = JSON.parse(data); 10 11 generateTestsForEachTreeAdapter(moduleExports, (_test, treeAdapter) => { 12 tests.forEach((test, idx) => { 13 _test[`${prefix} - ${idx}.${test.name}`] = async () => { 14 const opts = { treeAdapter: treeAdapter }; 15 const document = parse5.parse(test.input, opts); 16 const serializedResult = await serialize(document, opts); 17 18 //NOTE: use ok assertion, so output will not be polluted by the whole content of the strings 19 assert.ok(serializedResult === test.expected, getStringDiffMsg(serializedResult, test.expected)); 20 }; 21 }); 22 }); 23}; 24