|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const fs = require('fs'); |
| 6 | + |
| 7 | +const html = require('../../tools/doc/html.js'); |
| 8 | + |
| 9 | +// Test data is a list of objects with two properties. |
| 10 | +// The file property is the file path. |
| 11 | +// The html property is some html which will be generated by the doctool. |
| 12 | +// This html will be stripped of all whitespace because we don't currently |
| 13 | +// have an html parser. |
| 14 | +const testData = [ |
| 15 | + { |
| 16 | + 'file': common.fixturesDir + '/sample_document.md', |
| 17 | + 'html': '<ol><li>fish</li><li><p>fish</p></li><li><p>Redfish</p></li>' + |
| 18 | + '<li>Bluefish</li></ol>' |
| 19 | + }, |
| 20 | + { |
| 21 | + 'file': common.fixturesDir + '/order_of_end_tags_5873.md', |
| 22 | + 'html': '<h3>ClassMethod: Buffer.from(array) <span> ' + |
| 23 | + '<a class="mark" href="#foo_class_method_buffer_from_array" ' + |
| 24 | + 'id="foo_class_method_buffer_from_array">#</a> </span> </h3><div' + |
| 25 | + 'class="signature"><ul><li><code>array</code><a ' + |
| 26 | + 'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' + |
| 27 | + 'Reference/Global_Objects/Array" class="type"><Array></a></li>' + |
| 28 | + '</ul></div>' |
| 29 | + }, |
| 30 | +]; |
| 31 | + |
| 32 | +testData.forEach(function(item) { |
| 33 | + // Normalize expected data by stripping whitespace |
| 34 | + const expected = item.html.replace(/\s/g, ''); |
| 35 | + |
| 36 | + fs.readFile(item.file, 'utf8', common.mustCall(function(err, input) { |
| 37 | + assert.ifError(err); |
| 38 | + html(input, 'foo', 'doc/template.html', |
| 39 | + common.mustCall(function(err, output) { |
| 40 | + assert.ifError(err); |
| 41 | + |
| 42 | + const actual = output.replace(/\s/g, ''); |
| 43 | + // Assert that the input stripped of all whitespace contains the |
| 44 | + // expected list |
| 45 | + assert.notEqual(actual.indexOf(expected), -1); |
| 46 | + })); |
| 47 | + })); |
| 48 | +}); |
0 commit comments